- Timestamp:
- 04/18/08 00:16:51 (17 years ago)
- Location:
- trunk/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/range_list.c
r100 r106 148 148 { 149 149 uint32_t i; 150 151 if(rl == NULL) 152 return; 153 150 154 for(i=0; i < rl->size; i++) 151 155 free(rl->elements[i]); -
trunk/lib/regfi.c
r105 r106 413 413 414 414 /******************************************************************* 415 Input a random offset and receive the correpsonding HBIN416 block for it417 *******************************************************************/418 static bool hbin_contains_offset( REGF_HBIN *hbin, uint32 offset)419 { 420 if ( !hbin)415 * Given an offset and an hbin, is the offset within that hbin? 416 * The offset is a virtual file offset. 417 *******************************************************************/ 418 static bool regfi_offset_in_hbin(REGF_HBIN* hbin, uint32 offset) 419 { 420 if(!hbin) 421 421 return false; 422 423 if ( (offset > hbin->first_hbin_off) && (offset < (hbin->first_hbin_off+hbin->block_size)) ) 422 423 if((offset > hbin->first_hbin_off) 424 && (offset < (hbin->first_hbin_off + hbin->block_size))) 424 425 return true; 425 426 … … 428 429 429 430 431 430 432 /******************************************************************* 431 Input a random offset and receive the correpsonding HBIN 432 block for it 433 *******************************************************************/ 434 static REGF_HBIN* lookup_hbin_block( REGF_FILE *file, uint32 offset ) 435 { 436 REGF_HBIN *hbin = NULL; 437 uint32 block_off; 438 439 /* start with the open list */ 440 441 for ( hbin=file->block_list; hbin; hbin=hbin->next ) { 442 /* DEBUG(10,("lookup_hbin_block: address = 0x%x [0x%x]\n", hbin->file_off, (uint32)hbin ));*/ 443 if ( hbin_contains_offset( hbin, offset ) ) 444 return hbin; 445 } 446 447 if ( !hbin ) { 448 /* start at the beginning */ 449 450 block_off = REGF_BLOCKSIZE; 451 do { 452 hbin = regfi_parse_hbin(file, block_off, true, false); 453 454 if ( hbin ) 455 block_off = hbin->file_off + hbin->block_size; 456 457 } while ( hbin && !hbin_contains_offset( hbin, offset ) ); 458 } 459 460 if ( hbin ) 461 /* XXX: this kind of caching needs to be re-evaluated */ 462 DLIST_ADD( file->block_list, hbin ); 463 464 return hbin; 433 * Given a virtual offset, and receive the correpsonding HBIN 434 * block for it. NULL if one doesn't exist. 435 *******************************************************************/ 436 static REGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset) 437 { 438 return (REGF_HBIN*)range_list_find_data(file->hbins, offset+REGF_BLOCKSIZE); 465 439 } 466 440 … … 683 657 vk_raw_offset = IVAL(buf, i*4); 684 658 685 sub_hbin = lookup_hbin_block(file, vk_raw_offset);659 sub_hbin = regfi_lookup_hbin(file, vk_raw_offset); 686 660 if (!sub_hbin) 687 661 { … … 740 714 741 715 /******************************************************************* 716 * TODO: Need to add full key and SK record caching using a 717 * custom cache structure. 742 718 *******************************************************************/ 743 719 REGF_NK_REC* regfi_load_key(REGF_FILE *file, uint32 offset, bool strict) … … 748 724 uint32 max_length, off; 749 725 750 hbin = lookup_hbin_block(file, offset-REGF_BLOCKSIZE);726 hbin = regfi_lookup_hbin(file, offset-REGF_BLOCKSIZE); 751 727 if (hbin == NULL) 752 728 return NULL; … … 761 737 { 762 738 sub_hbin = hbin; 763 if(! hbin_contains_offset(hbin, nk->values_off))764 sub_hbin = lookup_hbin_block(file, nk->values_off);739 if(!regfi_offset_in_hbin(hbin, nk->values_off)) 740 sub_hbin = regfi_lookup_hbin(file, nk->values_off); 765 741 766 742 if(sub_hbin == NULL) … … 792 768 { 793 769 sub_hbin = hbin; 794 if(! hbin_contains_offset(hbin, nk->subkeys_off))795 sub_hbin = lookup_hbin_block(file, nk->subkeys_off);770 if(!regfi_offset_in_hbin(hbin, nk->subkeys_off)) 771 sub_hbin = regfi_lookup_hbin(file, nk->subkeys_off); 796 772 797 773 if (sub_hbin == NULL) … … 825 801 { 826 802 sub_hbin = hbin; 827 if(! hbin_contains_offset(hbin, nk->sk_off))828 sub_hbin = lookup_hbin_block(file, nk->sk_off);803 if(!regfi_offset_in_hbin(hbin, nk->sk_off)) 804 sub_hbin = regfi_lookup_hbin(file, nk->sk_off); 829 805 830 806 if(sub_hbin == NULL) … … 910 886 { 911 887 REGF_FILE* rb; 888 REGF_HBIN* hbin = NULL; 889 uint32 hbin_off; 912 890 int fd; 913 891 int flags = O_RDONLY; 892 bool rla; 914 893 915 894 /* open an existing file */ … … 932 911 if((rb->hbins == NULL) || (rb->unalloc_cells == NULL)) 933 912 { 913 range_list_free(rb->hbins); 914 range_list_free(rb->unalloc_cells); 934 915 close(fd); 935 916 free(rb); 936 917 return NULL; 918 } 919 920 rla = true; 921 hbin_off = REGF_BLOCKSIZE; 922 hbin = regfi_parse_hbin(rb, hbin_off, true, false); 923 while(hbin && rla) 924 { 925 hbin_off = hbin->file_off + hbin->block_size; 926 rla = range_list_add(rb->hbins, hbin->file_off, hbin->block_size, hbin); 927 hbin = regfi_parse_hbin(rb, hbin_off, true, false); 937 928 } 938 929 … … 947 938 { 948 939 int fd; 940 uint32 i; 949 941 950 942 /* nothing to do if there is no open file */ … … 954 946 fd = file->fd; 955 947 file->fd = -1; 948 for(i=0; i < range_list_size(file->hbins); i++) 949 free(range_list_get(file->hbins, i)->data); 956 950 range_list_free(file->hbins); 951 952 for(i=0; i < range_list_size(file->unalloc_cells); i++) 953 free(range_list_get(file->unalloc_cells, i)->data); 957 954 range_list_free(file->unalloc_cells); 955 958 956 free(file); 959 957 960 return close( fd);958 return close(fd); 961 959 } 962 960 … … 1321 1319 } 1322 1320 1323 1324 1325 /****************/1326 /* Experimental */1327 /****************/1328 /*1329 typedef struct {1330 uint32 offset;1331 uint32 size;1332 } REGFI_CELL_INFO;1333 1334 typedef struct {1335 uint32 count1336 REGFI_CELL_INFO** cells;1337 } REGFI_CELL_LIST;1338 */1339 1321 1340 1322
Note: See TracChangeset
for help on using the changeset viewer.