Changeset 110 for trunk


Ignore:
Timestamp:
04/29/08 18:59:55 (17 years ago)
Author:
tim
Message:

moved unallocated cell parsing back out of the main line hbin parsing

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r109 r110  
    7272#define REG_KEY                        0x7FFFFFFF
    7373
    74 #define REGFI_FLAG_NONE         0x0
    75 #define REGFI_FLAG_SAVE_UNALLOC 0x1
    76 
    7774#define REGF_BLOCKSIZE          0x1000
    7875#define REGF_ALLOC_BLOCK        0x1000  /* Minimum allocation unit for hbins */
     
    260257  /* Experimental hbin lists */
    261258  range_list* hbins;
    262   range_list* unalloc_cells;
    263259
    264260  /* file format information */ 
     
    319315char*                 regfi_get_group(SEC_DESC* sec_desc);
    320316
    321 REGF_FILE*            regfi_open(const char* filename, uint32 flags);
     317REGF_FILE*            regfi_open(const char* filename);
    322318int                   regfi_close(REGF_FILE* r);
    323319
     
    349345REGF_FILE*            regfi_parse_regf(int fd, bool strict);
    350346REGF_HBIN*            regfi_parse_hbin(REGF_FILE* file, uint32 offset,
    351                                        bool strict, bool save_unalloc);
     347                                       bool strict);
    352348
    353349
     
    393389                        uint32 length, bool strict);
    394390
     391range_list* regfi_parse_unalloc_cells(REGF_FILE* file);
    395392
    396393#endif  /* _REGFI_H */
  • trunk/lib/regfi.c

    r109 r110  
    817817 * first hbin offset.
    818818 *******************************************************************/
    819 REGF_FILE* regfi_open(const char* filename, uint32 flags)
     819REGF_FILE* regfi_open(const char* filename)
    820820{
    821821  REGF_FILE* rb;
     
    823823  uint32 hbin_off;
    824824  int fd;
    825   bool rla, save_unalloc = false;
    826 
    827   if(flags & REGFI_FLAG_SAVE_UNALLOC)
    828     save_unalloc = true;
     825  bool rla;
    829826
    830827  /* open an existing file */
     
    844841 
    845842  rb->hbins = range_list_new();
    846   rb->unalloc_cells = range_list_new();
    847   if((rb->hbins == NULL) || (rb->unalloc_cells == NULL))
     843  if(rb->hbins == NULL)
    848844  {
    849845    range_list_free(rb->hbins);
    850     range_list_free(rb->unalloc_cells);
    851846    close(fd);
    852847    free(rb);
     
    856851  rla = true;
    857852  hbin_off = REGF_BLOCKSIZE;
    858   hbin = regfi_parse_hbin(rb, hbin_off, true, save_unalloc);
     853  hbin = regfi_parse_hbin(rb, hbin_off, true);
    859854  while(hbin && rla)
    860855  {
    861856    hbin_off = hbin->file_off + hbin->block_size;
    862857    rla = range_list_add(rb->hbins, hbin->file_off, hbin->block_size, hbin);
    863     hbin = regfi_parse_hbin(rb, hbin_off, true, save_unalloc);
     858    hbin = regfi_parse_hbin(rb, hbin_off, true);
    864859  }
    865860
     
    886881  range_list_free(file->hbins);
    887882
    888   for(i=0; i < range_list_size(file->unalloc_cells); i++)
    889     free(range_list_get(file->unalloc_cells, i)->data);
    890   range_list_free(file->unalloc_cells);
    891 
    892883  free(file);
    893884
     
    13921383/*******************************************************************
    13931384 * Given real file offset, read and parse the hbin at that location
    1394  * along with it's associated cells.  If save_unalloc is true, a list
    1395  * of unallocated cell offsets will be stored in TODO.
     1385 * along with it's associated cells.
    13961386 *******************************************************************/
    13971387/* TODO: Need a way to return types of errors.  Also need to free
    13981388 *       the hbin/ps when an error occurs.
    13991389 */
    1400 REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset,
    1401                             bool strict, bool save_unalloc)
     1390REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, bool strict)
    14021391{
    14031392  REGF_HBIN *hbin;
    14041393  uint8 hbin_header[HBIN_HEADER_REC_SIZE];
    1405   uint32 length, curr_off;
    1406   uint32 cell_len;
    1407   bool is_unalloc;
     1394  uint32 length;
    14081395 
    14091396  if(offset >= file->file_length)
     
    14491436    free(hbin);
    14501437    return NULL;
    1451   }
    1452 
    1453   if(save_unalloc)
    1454   {
    1455     curr_off = HBIN_HEADER_REC_SIZE;
    1456     while(curr_off < hbin->block_size)
    1457     {
    1458       if(!regfi_parse_cell(file->fd, hbin->file_off+curr_off, NULL, 0,
    1459                            &cell_len, &is_unalloc))
    1460         break;
    1461 
    1462       if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len))
    1463         /* TODO: should report an error here. */
    1464         break;
    1465 
    1466       /* for some reason the record_size of the last record in
    1467          an hbin block can extend past the end of the block
    1468          even though the record fits within the remaining
    1469          space....aaarrrgggghhhhhh */ 
    1470       if(curr_off + cell_len >= hbin->block_size)
    1471         cell_len = hbin->block_size - curr_off;
    1472 
    1473       if(is_unalloc)
    1474         range_list_add(file->unalloc_cells, hbin->file_off+curr_off,
    1475           cell_len, NULL);
    1476 
    1477       curr_off = curr_off+cell_len;
    1478     }
    14791438  }
    14801439
     
    17681727  return ret_val;
    17691728}
     1729
     1730
     1731range_list* regfi_parse_unalloc_cells(REGF_FILE* file)
     1732{
     1733  range_list* ret_val;
     1734  REGF_HBIN* hbin;
     1735  const range_list_element* hbins_elem;
     1736  uint32 i, num_hbins, curr_off, cell_len;
     1737  bool is_unalloc;
     1738
     1739  ret_val = range_list_new();
     1740  if(ret_val == NULL)
     1741    return NULL;
     1742
     1743  num_hbins = range_list_size(file->hbins);
     1744  for(i=0; i<num_hbins; i++)
     1745  {
     1746    hbins_elem = range_list_get(file->hbins, i);
     1747    if(hbins_elem == NULL)
     1748      break;
     1749    hbin = (REGF_HBIN*)hbins_elem->data;
     1750
     1751    curr_off = HBIN_HEADER_REC_SIZE;
     1752    while(curr_off < hbin->block_size)
     1753    {
     1754      if(!regfi_parse_cell(file->fd, hbin->file_off+curr_off, NULL, 0,
     1755                           &cell_len, &is_unalloc))
     1756        break;
     1757     
     1758      if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len))
     1759        /* TODO: should report an error here. */
     1760        break;
     1761     
     1762      /* for some reason the record_size of the last record in
     1763         an hbin block can extend past the end of the block
     1764         even though the record fits within the remaining
     1765         space....aaarrrgggghhhhhh */ 
     1766      if(curr_off + cell_len >= hbin->block_size)
     1767        cell_len = hbin->block_size - curr_off;
     1768     
     1769      if(is_unalloc)
     1770        range_list_add(ret_val, hbin->file_off+curr_off,
     1771                       cell_len, NULL);
     1772     
     1773      curr_off = curr_off+cell_len;
     1774    }
     1775  }
     1776
     1777  return ret_val;
     1778}
  • trunk/src/Makefile

    r90 r110  
    44
    55REGLOOKUP=$(BUILD_BIN)/reglookup
     6REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover
    67OBJ=$(wildcard ../lib/*.o)
    7 FILES=$(REGLOOKUP)
     8FILES=$(REGLOOKUP) $(REGLOOKUP_RECOVER)
    89
    910all: $(FILES)
     
    1213        $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ)
    1314
     15$(REGLOOKUP_RECOVER): reglookup-recover.o $(OBJ)
     16        $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ)
     17
    1418reglookup.o: reglookup.c
    1519        $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ reglookup.c
     20
     21reglookup-recover.o: reglookup-recover.c
     22        $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ reglookup-recover.c
    1623
    1724install:
  • trunk/src/reglookup.c

    r109 r110  
    901901    bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
    902902
    903   f = regfi_open(registry_file, 0);
     903  f = regfi_open(registry_file);
    904904  if(f == NULL)
    905905  {
Note: See TracChangeset for help on using the changeset viewer.