Index: trunk/include/regfi.h
===================================================================
--- trunk/include/regfi.h	(revision 109)
+++ trunk/include/regfi.h	(revision 110)
@@ -72,7 +72,4 @@
 #define REG_KEY                        0x7FFFFFFF
 
-#define REGFI_FLAG_NONE         0x0
-#define REGFI_FLAG_SAVE_UNALLOC 0x1
-
 #define REGF_BLOCKSIZE		0x1000
 #define REGF_ALLOC_BLOCK	0x1000  /* Minimum allocation unit for hbins */
@@ -260,5 +257,4 @@
   /* Experimental hbin lists */
   range_list* hbins;
-  range_list* unalloc_cells;
 
   /* file format information */  
@@ -319,5 +315,5 @@
 char*                 regfi_get_group(SEC_DESC* sec_desc);
 
-REGF_FILE*            regfi_open(const char* filename, uint32 flags);
+REGF_FILE*            regfi_open(const char* filename);
 int                   regfi_close(REGF_FILE* r);
 
@@ -349,5 +345,5 @@
 REGF_FILE*            regfi_parse_regf(int fd, bool strict);
 REGF_HBIN*            regfi_parse_hbin(REGF_FILE* file, uint32 offset, 
-				       bool strict, bool save_unalloc);
+				       bool strict);
 
 
@@ -393,4 +389,5 @@
 			uint32 length, bool strict);
 
+range_list* regfi_parse_unalloc_cells(REGF_FILE* file);
 
 #endif	/* _REGFI_H */
Index: trunk/lib/regfi.c
===================================================================
--- trunk/lib/regfi.c	(revision 109)
+++ trunk/lib/regfi.c	(revision 110)
@@ -817,5 +817,5 @@
  * first hbin offset.
  *******************************************************************/
-REGF_FILE* regfi_open(const char* filename, uint32 flags)
+REGF_FILE* regfi_open(const char* filename)
 {
   REGF_FILE* rb;
@@ -823,8 +823,5 @@
   uint32 hbin_off;
   int fd;
-  bool rla, save_unalloc = false;
-
-  if(flags & REGFI_FLAG_SAVE_UNALLOC)
-    save_unalloc = true;
+  bool rla;
 
   /* open an existing file */
@@ -844,9 +841,7 @@
   
   rb->hbins = range_list_new();
-  rb->unalloc_cells = range_list_new();
-  if((rb->hbins == NULL) || (rb->unalloc_cells == NULL))
+  if(rb->hbins == NULL)
   {
     range_list_free(rb->hbins);
-    range_list_free(rb->unalloc_cells);
     close(fd);
     free(rb);
@@ -856,10 +851,10 @@
   rla = true;
   hbin_off = REGF_BLOCKSIZE;
-  hbin = regfi_parse_hbin(rb, hbin_off, true, save_unalloc);
+  hbin = regfi_parse_hbin(rb, hbin_off, true);
   while(hbin && rla)
   {
     hbin_off = hbin->file_off + hbin->block_size;
     rla = range_list_add(rb->hbins, hbin->file_off, hbin->block_size, hbin);
-    hbin = regfi_parse_hbin(rb, hbin_off, true, save_unalloc);
+    hbin = regfi_parse_hbin(rb, hbin_off, true);
   }
 
@@ -886,8 +881,4 @@
   range_list_free(file->hbins);
 
-  for(i=0; i < range_list_size(file->unalloc_cells); i++)
-    free(range_list_get(file->unalloc_cells, i)->data);
-  range_list_free(file->unalloc_cells);
-
   free(file);
 
@@ -1392,18 +1383,14 @@
 /*******************************************************************
  * Given real file offset, read and parse the hbin at that location
- * along with it's associated cells.  If save_unalloc is true, a list
- * of unallocated cell offsets will be stored in TODO.
+ * along with it's associated cells.
  *******************************************************************/
 /* TODO: Need a way to return types of errors.  Also need to free 
  *       the hbin/ps when an error occurs.
  */
-REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, 
-			    bool strict, bool save_unalloc)
+REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, bool strict)
 {
   REGF_HBIN *hbin;
   uint8 hbin_header[HBIN_HEADER_REC_SIZE];
-  uint32 length, curr_off;
-  uint32 cell_len;
-  bool is_unalloc;
+  uint32 length;
   
   if(offset >= file->file_length)
@@ -1449,32 +1436,4 @@
     free(hbin);
     return NULL;
-  }
-
-  if(save_unalloc)
-  {
-    curr_off = HBIN_HEADER_REC_SIZE;
-    while(curr_off < hbin->block_size)
-    {
-      if(!regfi_parse_cell(file->fd, hbin->file_off+curr_off, NULL, 0,
-			   &cell_len, &is_unalloc))
-	break;
-
-      if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len))
-	/* TODO: should report an error here. */
-	break;
-
-      /* for some reason the record_size of the last record in
-	 an hbin block can extend past the end of the block
-	 even though the record fits within the remaining 
-	 space....aaarrrgggghhhhhh */  
-      if(curr_off + cell_len >= hbin->block_size)
-	cell_len = hbin->block_size - curr_off;
-
-      if(is_unalloc)
-	range_list_add(file->unalloc_cells, hbin->file_off+curr_off, 
-	  cell_len, NULL);
-
-      curr_off = curr_off+cell_len;
-    }
   }
 
@@ -1768,2 +1727,52 @@
   return ret_val;
 }
+
+
+range_list* regfi_parse_unalloc_cells(REGF_FILE* file)
+{
+  range_list* ret_val;
+  REGF_HBIN* hbin;
+  const range_list_element* hbins_elem;
+  uint32 i, num_hbins, curr_off, cell_len;
+  bool is_unalloc;
+
+  ret_val = range_list_new();
+  if(ret_val == NULL)
+    return NULL;
+
+  num_hbins = range_list_size(file->hbins);
+  for(i=0; i<num_hbins; i++)
+  {
+    hbins_elem = range_list_get(file->hbins, i);
+    if(hbins_elem == NULL)
+      break;
+    hbin = (REGF_HBIN*)hbins_elem->data;
+
+    curr_off = HBIN_HEADER_REC_SIZE;
+    while(curr_off < hbin->block_size)
+    {
+      if(!regfi_parse_cell(file->fd, hbin->file_off+curr_off, NULL, 0,
+			   &cell_len, &is_unalloc))
+	break;
+      
+      if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len))
+	/* TODO: should report an error here. */
+	break;
+      
+      /* for some reason the record_size of the last record in
+	 an hbin block can extend past the end of the block
+	 even though the record fits within the remaining 
+	 space....aaarrrgggghhhhhh */  
+      if(curr_off + cell_len >= hbin->block_size)
+	cell_len = hbin->block_size - curr_off;
+      
+      if(is_unalloc)
+	range_list_add(ret_val, hbin->file_off+curr_off, 
+		       cell_len, NULL);
+      
+      curr_off = curr_off+cell_len;
+    }
+  }
+
+  return ret_val;
+}
Index: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	(revision 109)
+++ trunk/src/Makefile	(revision 110)
@@ -4,6 +4,7 @@
 
 REGLOOKUP=$(BUILD_BIN)/reglookup
+REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover
 OBJ=$(wildcard ../lib/*.o)
-FILES=$(REGLOOKUP)
+FILES=$(REGLOOKUP) $(REGLOOKUP_RECOVER)
 
 all: $(FILES)
@@ -12,6 +13,12 @@
 	$(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ)
 
+$(REGLOOKUP_RECOVER): reglookup-recover.o $(OBJ)
+	$(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ)
+
 reglookup.o: reglookup.c
 	$(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ reglookup.c
+
+reglookup-recover.o: reglookup-recover.c
+	$(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ reglookup-recover.c
 
 install:
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 109)
+++ trunk/src/reglookup.c	(revision 110)
@@ -901,5 +901,5 @@
     bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
 
-  f = regfi_open(registry_file, 0);
+  f = regfi_open(registry_file);
   if(f == NULL)
   {
