- Timestamp:
- 04/14/08 00:55:41 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r104 r105 450 450 block_off = REGF_BLOCKSIZE; 451 451 do { 452 /* cleanup before the next round */453 if ( hbin )454 {455 if(hbin->ps.is_dynamic)456 SAFE_FREE(hbin->ps.data_p);457 hbin->ps.is_dynamic = false;458 hbin->ps.buffer_size = 0;459 hbin->ps.data_offset = 0;460 }461 462 452 hbin = regfi_parse_hbin(file, block_off, true, false); 463 453 … … 478 468 479 469 /******************************************************************* 470 TODO: not currently validating against max_size 480 471 *******************************************************************/ 481 472 REGF_HASH_LIST* regfi_load_hashlist(REGF_FILE* file, uint32 offset, 482 uint32 num_keys, bool strict) 473 uint32 num_keys, uint32 max_size, 474 bool strict) 483 475 { 484 476 REGF_HASH_LIST* ret_val; … … 657 649 658 650 /****************************************************************************** 659 *651 TODO: not currently validating against max_size. 660 652 ******************************************************************************/ 661 653 REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset, 662 uint32 num_values) 654 uint32 num_values, uint32 max_size, 655 bool strict) 663 656 { 664 657 REGF_VK_REC** ret_val; … … 748 741 /******************************************************************* 749 742 *******************************************************************/ 750 static REGF_NK_REC* hbin_prs_key(REGF_FILE *file, REGF_HBIN *hbin) 751 { 743 REGF_NK_REC* regfi_load_key(REGF_FILE *file, uint32 offset, bool strict) 744 { 745 REGF_HBIN* hbin; 752 746 REGF_HBIN* sub_hbin; 753 747 REGF_NK_REC* nk; 754 uint32 nk_cell_offset; 755 uint32 nk_max_length; 756 uint32 sk_max_length; 757 int depth = 0; 758 759 depth++; 748 uint32 max_length, off; 749 750 hbin = lookup_hbin_block(file, offset-REGF_BLOCKSIZE); 751 if (hbin == NULL) 752 return NULL; 760 753 761 754 /* get the initial nk record */ 762 nk_cell_offset = hbin->file_off + hbin->ps.data_offset - sizeof(uint32); 763 nk_max_length = hbin->block_size - hbin->ps.data_offset + sizeof(uint32); 764 if ((nk = regfi_parse_nk(file, nk_cell_offset, nk_max_length, true)) == NULL) 765 { 766 fprintf(stderr, "DEBUG: regfi_parse_nk returned NULL!\n"); 767 return NULL; 768 } 755 max_length = hbin->block_size + hbin->file_off - offset; 756 if ((nk = regfi_parse_nk(file, offset, max_length, true)) == NULL) 757 return NULL; 769 758 770 759 /* fill in values */ 771 if ( nk->num_values && (nk->values_off!=REGF_OFFSET_NONE))760 if(nk->num_values && (nk->values_off!=REGF_OFFSET_NONE)) 772 761 { 773 762 sub_hbin = hbin; 774 if ( !hbin_contains_offset( hbin, nk->values_off ) ) 775 { 776 sub_hbin = lookup_hbin_block( file, nk->values_off ); 777 if ( !sub_hbin ) 763 if(!hbin_contains_offset(hbin, nk->values_off)) 764 sub_hbin = lookup_hbin_block(file, nk->values_off); 765 766 if(sub_hbin == NULL) 767 { 768 if(strict) 778 769 { 779 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing value_list_offset [0x%x]\n", 780 nk->values_off));*/ 770 free(nk); 781 771 return NULL; 782 772 } 783 } 784 785 nk->values = regfi_load_valuelist(file, nk->values_off+REGF_BLOCKSIZE, 786 nk->num_values); 787 if(nk->values == NULL) 788 { 789 printf("values borked!\n"); 790 return NULL; 791 } 792 } 793 794 /* now get subkeys */ 795 if ( nk->num_subkeys && (nk->subkeys_off!=REGF_OFFSET_NONE) ) 796 { 797 sub_hbin = hbin; 798 if ( !hbin_contains_offset( hbin, nk->subkeys_off ) ) 799 { 800 sub_hbin = lookup_hbin_block( file, nk->subkeys_off ); 801 if ( !sub_hbin ) 773 else 774 nk->values = NULL; 775 } 776 else 777 { 778 off = nk->values_off + REGF_BLOCKSIZE; 779 max_length = sub_hbin->block_size + sub_hbin->file_off - off; 780 nk->values = regfi_load_valuelist(file, off, nk->num_values, max_length, 781 true); 782 if(strict && nk->values == NULL) 802 783 { 803 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing subkey_offset [0x%x]\n", 804 nk->subkeys_off));*/ 784 free(nk); 805 785 return NULL; 806 786 } 807 787 } 808 809 nk->subkeys = regfi_load_hashlist(file, nk->subkeys_off + REGF_BLOCKSIZE, 810 nk->num_subkeys, true); 811 if (nk->subkeys == NULL) 812 { 813 /* TODO: temporary hack to get around 'ri' records */ 814 nk->num_subkeys = 0; 815 } 816 } 817 818 /* get the security descriptor. First look if we have already parsed it */ 819 if ((nk->sk_off!=REGF_OFFSET_NONE) 820 && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off ))) 788 } 789 790 /* now get subkeys */ 791 if(nk->num_subkeys && (nk->subkeys_off != REGF_OFFSET_NONE)) 821 792 { 822 793 sub_hbin = hbin; 823 if (!hbin_contains_offset(hbin, nk->sk_off)) 824 { 825 sub_hbin = lookup_hbin_block( file, nk->sk_off ); 826 if ( !sub_hbin ) 794 if(!hbin_contains_offset(hbin, nk->subkeys_off)) 795 sub_hbin = lookup_hbin_block(file, nk->subkeys_off); 796 797 if (sub_hbin == NULL) 798 { 799 if(strict) 827 800 { 828 801 free(nk); 829 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing sk_offset [0x%x]\n", 830 nk->subkeys_off));*/ 802 /* TODO: need convenient way to free nk->values deeply in all cases. */ 831 803 return NULL; 832 804 } 833 } 805 else 806 nk->subkeys = NULL; 807 } 808 else 809 { 810 off = nk->subkeys_off + REGF_BLOCKSIZE; 811 max_length = sub_hbin->block_size + sub_hbin->file_off - off; 812 nk->subkeys = regfi_load_hashlist(file, off, nk->num_subkeys, 813 max_length, true); 814 if(nk->subkeys == NULL) 815 { 816 /* TODO: temporary hack to get around 'ri' records */ 817 nk->num_subkeys = 0; 818 } 819 } 820 } 821 822 /* get the security descriptor. First look if we have already parsed it */ 823 if((nk->sk_off!=REGF_OFFSET_NONE) 824 && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off ))) 825 { 826 sub_hbin = hbin; 827 if(!hbin_contains_offset(hbin, nk->sk_off)) 828 sub_hbin = lookup_hbin_block(file, nk->sk_off); 829 830 if(sub_hbin == NULL) 831 { 832 free(nk); 833 /* TODO: need convenient way to free nk->values and nk->subkeys deeply 834 * in all cases. 835 */ 836 return NULL; 837 } 838 839 off = nk->sk_off + REGF_BLOCKSIZE; 840 max_length = sub_hbin->block_size + sub_hbin->file_off - off; 841 nk->sec_desc = regfi_parse_sk(file, off, max_length, true); 842 if(strict && nk->sec_desc == NULL) 843 { 844 free(nk); 845 /* TODO: need convenient way to free nk->values and nk->subkeys deeply 846 * in all cases. 847 */ 848 return NULL; 849 } 850 nk->sec_desc->sk_off = nk->sk_off; 834 851 835 sk_max_length = sub_hbin->block_size - (nk->sk_off - sub_hbin->first_hbin_off);836 nk->sec_desc = regfi_parse_sk(file, nk->sk_off + REGF_BLOCKSIZE,837 sk_max_length, true);838 if(nk->sec_desc == NULL)839 return NULL;840 nk->sec_desc->sk_off = nk->sk_off;841 842 852 /* add to the list of security descriptors (ref_count has been read from the files) */ 843 853 /* XXX: this kind of caching needs to be re-evaluated */ … … 976 986 hbin->block_size-HBIN_HEADER_REC_SIZE, &root_offset)) 977 987 { 978 if(!prs_set_offset(&hbin->ps, root_offset + 4 979 - hbin->first_hbin_off - REGF_BLOCKSIZE)) 980 return NULL; 981 982 nk = hbin_prs_key(file, hbin); 988 nk = regfi_load_key(file, root_offset, true); 983 989 break; 984 990 } … … 1223 1229 const REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i) 1224 1230 { 1225 REGF_NK_REC* subkey;1226 REGF_HBIN* hbin;1227 1231 uint32 nk_offset; 1228 1232 … … 1233 1237 1234 1238 nk_offset = i->cur_key->subkeys->hashes[i->cur_subkey].nk_off; 1235 1236 /* find the HBIN block which should contain the nk record */ 1237 hbin = lookup_hbin_block(i->f, nk_offset); 1238 if(!hbin) 1239 { 1240 /* XXX: should print out some kind of error message every time here */ 1241 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing offset [0x%x]\n", 1242 i->cur_key->subkeys->hashes[i->cur_subkey].nk_off));*/ 1243 return NULL; 1244 } 1245 1246 if(!prs_set_offset(&hbin->ps, 1247 HBIN_MAGIC_SIZE + nk_offset - hbin->first_hbin_off)) 1248 return NULL; 1249 1250 if((subkey = hbin_prs_key(i->f, hbin)) == NULL) 1251 return NULL; 1252 1253 return subkey; 1239 1240 return regfi_load_key(i->f, nk_offset+REGF_BLOCKSIZE, true); 1254 1241 } 1255 1242 … … 1459 1446 uint8 hbin_header[HBIN_HEADER_REC_SIZE]; 1460 1447 uint32 length, curr_off; 1461 int32 cell_len;1448 uint32 cell_len; 1462 1449 bool is_unalloc; 1463 1450 … … 1506 1493 } 1507 1494 1508 /* TODO: need to get rid of this, but currently lots depends on the1509 * ps structure.1510 */1511 if(!prs_init(&hbin->ps, hbin->block_size, file->mem_ctx, UNMARSHALL))1512 {1513 free(hbin);1514 return NULL;1515 }1516 length = hbin->block_size;1517 if((regfi_read(file->fd, (uint8*)hbin->ps.data_p, &length) != 0)1518 || length != hbin->block_size)1519 {1520 free(hbin);1521 return NULL;1522 }1523 1524 1525 1495 if(save_unalloc) 1526 1496 { 1527 cell_len = 0;1528 1497 curr_off = HBIN_HEADER_REC_SIZE; 1529 while ( curr_off < hbin->block_size ) 1530 { 1531 is_unalloc = false; 1532 cell_len = IVALS(hbin->ps.data_p, curr_off); 1533 if(cell_len > 0) 1534 is_unalloc = true; 1535 else 1536 cell_len = -1*cell_len; 1498 while(curr_off < hbin->block_size) 1499 { 1500 if(!regfi_parse_cell(file->fd, hbin->file_off+curr_off, NULL, 0, 1501 &cell_len, &is_unalloc)) 1502 break; 1537 1503 1538 1504 if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len)) … … 1554 1520 } 1555 1521 } 1556 1557 /* TODO: need to get rid of this, but currently lots depends on the1558 * ps structure.1559 */1560 if(!prs_set_offset(&hbin->ps, file->data_offset+HBIN_MAGIC_SIZE))1561 return NULL;1562 1522 1563 1523 return hbin;
Note: See TracChangeset
for help on using the changeset viewer.