Changeset 110
- Timestamp:
- 04/29/08 18:59:55 (17 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r109 r110 72 72 #define REG_KEY 0x7FFFFFFF 73 73 74 #define REGFI_FLAG_NONE 0x075 #define REGFI_FLAG_SAVE_UNALLOC 0x176 77 74 #define REGF_BLOCKSIZE 0x1000 78 75 #define REGF_ALLOC_BLOCK 0x1000 /* Minimum allocation unit for hbins */ … … 260 257 /* Experimental hbin lists */ 261 258 range_list* hbins; 262 range_list* unalloc_cells;263 259 264 260 /* file format information */ … … 319 315 char* regfi_get_group(SEC_DESC* sec_desc); 320 316 321 REGF_FILE* regfi_open(const char* filename , uint32 flags);317 REGF_FILE* regfi_open(const char* filename); 322 318 int regfi_close(REGF_FILE* r); 323 319 … … 349 345 REGF_FILE* regfi_parse_regf(int fd, bool strict); 350 346 REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, 351 bool strict , bool save_unalloc);347 bool strict); 352 348 353 349 … … 393 389 uint32 length, bool strict); 394 390 391 range_list* regfi_parse_unalloc_cells(REGF_FILE* file); 395 392 396 393 #endif /* _REGFI_H */ -
trunk/lib/regfi.c
r109 r110 817 817 * first hbin offset. 818 818 *******************************************************************/ 819 REGF_FILE* regfi_open(const char* filename , uint32 flags)819 REGF_FILE* regfi_open(const char* filename) 820 820 { 821 821 REGF_FILE* rb; … … 823 823 uint32 hbin_off; 824 824 int fd; 825 bool rla, save_unalloc = false; 826 827 if(flags & REGFI_FLAG_SAVE_UNALLOC) 828 save_unalloc = true; 825 bool rla; 829 826 830 827 /* open an existing file */ … … 844 841 845 842 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) 848 844 { 849 845 range_list_free(rb->hbins); 850 range_list_free(rb->unalloc_cells);851 846 close(fd); 852 847 free(rb); … … 856 851 rla = true; 857 852 hbin_off = REGF_BLOCKSIZE; 858 hbin = regfi_parse_hbin(rb, hbin_off, true , save_unalloc);853 hbin = regfi_parse_hbin(rb, hbin_off, true); 859 854 while(hbin && rla) 860 855 { 861 856 hbin_off = hbin->file_off + hbin->block_size; 862 857 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); 864 859 } 865 860 … … 886 881 range_list_free(file->hbins); 887 882 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 892 883 free(file); 893 884 … … 1392 1383 /******************************************************************* 1393 1384 * 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. 1396 1386 *******************************************************************/ 1397 1387 /* TODO: Need a way to return types of errors. Also need to free 1398 1388 * the hbin/ps when an error occurs. 1399 1389 */ 1400 REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, 1401 bool strict, bool save_unalloc) 1390 REGF_HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, bool strict) 1402 1391 { 1403 1392 REGF_HBIN *hbin; 1404 1393 uint8 hbin_header[HBIN_HEADER_REC_SIZE]; 1405 uint32 length, curr_off; 1406 uint32 cell_len; 1407 bool is_unalloc; 1394 uint32 length; 1408 1395 1409 1396 if(offset >= file->file_length) … … 1449 1436 free(hbin); 1450 1437 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 in1467 an hbin block can extend past the end of the block1468 even though the record fits within the remaining1469 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 }1479 1438 } 1480 1439 … … 1768 1727 return ret_val; 1769 1728 } 1729 1730 1731 range_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 4 4 5 5 REGLOOKUP=$(BUILD_BIN)/reglookup 6 REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover 6 7 OBJ=$(wildcard ../lib/*.o) 7 FILES=$(REGLOOKUP) 8 FILES=$(REGLOOKUP) $(REGLOOKUP_RECOVER) 8 9 9 10 all: $(FILES) … … 12 13 $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ) 13 14 15 $(REGLOOKUP_RECOVER): reglookup-recover.o $(OBJ) 16 $(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ) 17 14 18 reglookup.o: reglookup.c 15 19 $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ reglookup.c 20 21 reglookup-recover.o: reglookup-recover.c 22 $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ reglookup-recover.c 16 23 17 24 install: -
trunk/src/reglookup.c
r109 r110 901 901 bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n"); 902 902 903 f = regfi_open(registry_file , 0);903 f = regfi_open(registry_file); 904 904 if(f == NULL) 905 905 {
Note: See TracChangeset
for help on using the changeset viewer.