- Timestamp:
- 07/16/05 19:16:17 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfio.c
r31 r32 35 35 ******************************************************************/ 36 36 37 /* Registry types mapping */ 38 const VAL_STR reg_type_names[] = 39 { 40 { REG_SZ, "SZ" }, 41 { REG_EXPAND_SZ, "EXPAND_SZ" }, 42 { REG_BINARY, "BIN" }, 43 { REG_DWORD, "DWORD" }, 44 { REG_DWORD_BE, "DWORD_BE" }, 45 { REG_LINK, "LINK" }, 46 { REG_MULTI_SZ, "MULTI_SZ" }, 47 { REG_RESOURCE_LIST, "RSRC_LIST" }, 48 { REG_FULL_RESOURCE_DESCRIPTOR, "RSRC_DESC" }, 49 { REG_RESOURCE_REQUIREMENTS_LIST,"RSRC_REQ_LIST"}, 50 { REG_KEY, "KEY" }, 51 { 0, NULL }, 52 }; 53 54 55 /* Returns NULL on error */ 56 const char* type_val2str(unsigned int val) 57 { 58 int i; 59 60 for(i=0; reg_type_names[i].val && reg_type_names[i].str; i++) 61 if (reg_type_names[i].val == val) 62 return reg_type_names[i].str; 63 64 return NULL; 65 } 66 67 68 /* Returns 0 on error */ 69 int type_str2val(const char* str) 70 { 71 int i; 72 73 for(i=0; reg_type_names[i].val && reg_type_names[i].str; i++) 74 if (strcmp(reg_type_names[i].str, str) == 0) 75 return reg_type_names[i].val; 76 77 return 0; 78 } 79 37 80 38 81 /******************************************************************* … … 95 138 bytes_read = returned = 0; 96 139 97 while ( bytes_read < block_size ) { 98 if ( (returned = read( file->fd, buffer+bytes_read, block_size-bytes_read )) == -1 ) { 140 while ( bytes_read < block_size ) 141 { 142 if((returned = 143 read(file->fd, buffer+bytes_read, block_size-bytes_read)) == -1) 144 { 99 145 /*DEBUG(0,("read_block: read() failed (%s)\n", strerror(errno) ));*/ 100 146 return false; 101 147 } 102 if ( (returned == 0) && (bytes_read < block_size) ) { 148 if ((returned == 0) && (bytes_read < block_size)) 149 { 103 150 /*DEBUG(0,("read_block: not a vald registry file ?\n" ));*/ 104 151 return false; 105 152 } 106 153 107 154 bytes_read += returned; 108 155 } … … 701 748 /* get the data if necessary */ 702 749 703 if ( vk->data_size != 0 ) { 750 if ( vk->data_size != 0 ) 751 { 704 752 bool charmode = false; 705 753 … … 708 756 709 757 /* the data is stored in the offset if the size <= 4 */ 710 711 if ( !(vk->data_size & VK_DATA_IN_OFFSET) ){758 if ( !(vk->data_size & VK_DATA_IN_OFFSET) ) 759 { 712 760 REGF_HBIN *hblock = hbin; 713 761 uint32 data_rec_size; 714 762 715 if ( hbin->ps.io ) { 763 if ( hbin->ps.io ) 764 { 716 765 if ( !(vk->data = (uint8*)zcalloc(sizeof(uint8), vk->data_size) ) ) 717 766 return false; … … 719 768 720 769 /* this data can be in another hbin */ 721 if ( !hbin_contains_offset( hbin, vk->data_off ) ) { 770 if ( !hbin_contains_offset( hbin, vk->data_off ) ) 771 { 722 772 if ( !(hblock = lookup_hbin_block( file, vk->data_off )) ) 723 773 return false; 724 774 } 725 if ( !(prs_set_offset( &hblock->ps, (vk->data_off+HBIN_HDR_SIZE-hblock->first_hbin_off)-sizeof(uint32) )) ) 726 return false; 727 728 if ( !hblock->ps.io ) { 775 if (!(prs_set_offset(&hblock->ps, 776 (vk->data_off 777 + HBIN_HDR_SIZE 778 - hblock->first_hbin_off) 779 - sizeof(uint32)))) 780 { return false; } 781 782 if ( !hblock->ps.io ) 783 { 729 784 data_rec_size = ( (vk->data_size+sizeof(uint32)) & 0xfffffff8 ) + 8; 730 785 data_rec_size = ( data_rec_size - 1 ) ^ 0xFFFFFFFF; … … 732 787 if ( !prs_uint32( "data_rec_size", &hblock->ps, depth, &data_rec_size )) 733 788 return false; 734 if ( !prs_uint8s( charmode, "data", &hblock->ps, depth, vk->data, vk->data_size) ) 789 if(!prs_uint8s(charmode, "data", &hblock->ps, depth, 790 vk->data, vk->data_size)) 735 791 return false; 736 792 … … 738 794 hblock->dirty = true; 739 795 } 740 else { 741 if ( !(vk->data = zcalloc(sizeof(uint8), 4) ) ) 796 else 797 { 798 if(!(vk->data = zcalloc(sizeof(uint8), 4))) 742 799 return false; 743 800 SIVAL( vk->data, 0, vk->data_off ); … … 749 806 750 807 data_size = ((start_off - end_off ) & 0xfffffff8 ); 751 if ( data_size != vk->rec_size )752 /*DEBUG(10,("prs_vk_rec: data_size check failed (0x%x < 0x%x)\n", data_size, vk->rec_size));*/753 754 755 808 /*if ( data_size != vk->rec_size ) 809 DEBUG(10,("prs_vk_rec: data_size check failed (0x%x < 0x%x)\n", data_size, vk->rec_size));*/ 810 811 if ( !hbin->ps.io ) 812 hbin->dirty = true; 756 813 757 814 return true; … … 763 820 in the prs_struct *ps. 764 821 *******************************************************************/ 765 static bool hbin_prs_vk_records( 766 int depth, REGF_NK_REC *nk, REGF_FILE *file)822 static bool hbin_prs_vk_records(const char *desc, REGF_HBIN *hbin, 823 int depth, REGF_NK_REC *nk, REGF_FILE *file) 767 824 { 768 825 int i; … … 772 829 773 830 /* check if we have anything to do first */ 774 775 if ( nk->num_values == 0 ) 831 if(nk->num_values == 0) 776 832 return true; 777 833 778 if ( hbin->ps.io ) { 779 if ( !(nk->values = (REGF_VK_REC*)zcalloc(sizeof(REGF_VK_REC), nk->num_values ) ) ) 834 if(hbin->ps.io) 835 { 836 if (!(nk->values = (REGF_VK_REC*)zcalloc(sizeof(REGF_VK_REC), 837 nk->num_values ))) 780 838 return false; 781 839 } 782 840 783 841 /* convert the offset to something relative to this HBIN block */ 784 785 if ( !prs_set_offset( &hbin->ps, nk->values_off+HBIN_HDR_SIZE-hbin->first_hbin_off-sizeof(uint32)) ) 786 return false; 787 788 if ( !hbin->ps.io ) { 842 if (!prs_set_offset(&hbin->ps, 843 nk->values_off 844 + HBIN_HDR_SIZE 845 - hbin->first_hbin_off 846 - sizeof(uint32))) 847 { return false; } 848 849 if ( !hbin->ps.io ) 850 { 789 851 record_size = ( ( nk->num_values * sizeof(uint32) ) & 0xfffffff8 ) + 8; 790 852 record_size = (record_size - 1) ^ 0xFFFFFFFF; … … 794 856 return false; 795 857 796 for ( i=0; i<nk->num_values; i++ ) { 858 for ( i=0; i<nk->num_values; i++ ) 859 { 797 860 if ( !prs_uint32( "vk_off", &hbin->ps, depth, &nk->values[i].rec_off ) ) 798 861 return false; 799 862 } 800 863 801 for ( i=0; i<nk->num_values; i++ ) { 864 for ( i=0; i<nk->num_values; i++ ) 865 { 802 866 REGF_HBIN *sub_hbin = hbin; 803 867 uint32 new_offset; 804 868 805 if ( !hbin_contains_offset( hbin, nk->values[i].rec_off ) ) { 869 if ( !hbin_contains_offset( hbin, nk->values[i].rec_off ) ) 870 { 806 871 sub_hbin = lookup_hbin_block( file, nk->values[i].rec_off ); 807 if ( !sub_hbin ) { 872 if ( !sub_hbin ) 873 { 808 874 /*DEBUG(0,("hbin_prs_vk_records: Failed to find HBIN block containing offset [0x%x]\n", 809 875 nk->values[i].hbin_off));*/ … … 812 878 } 813 879 814 new_offset = nk->values[i].rec_off + HBIN_HDR_SIZE - sub_hbin->first_hbin_off; 815 if ( !prs_set_offset( &sub_hbin->ps, new_offset ) ) 816 return false; 817 if ( !hbin_prs_vk_rec( "vk_rec", sub_hbin, depth, &nk->values[i], file ) ) 880 new_offset = nk->values[i].rec_off 881 + HBIN_HDR_SIZE 882 - sub_hbin->first_hbin_off; 883 884 if (!prs_set_offset(&sub_hbin->ps, new_offset)) 885 return false; 886 if (!hbin_prs_vk_rec("vk_rec", sub_hbin, depth, &nk->values[i], file)) 818 887 return false; 819 888 } … … 822 891 hbin->dirty = true; 823 892 824 825 893 return true; 826 894 } … … 829 897 /******************************************************************* 830 898 *******************************************************************/ 831 832 899 static REGF_SK_REC* find_sk_record_by_offset( REGF_FILE *file, uint32 offset ) 833 900 { … … 842 909 } 843 910 844 /******************************************************************* 845 *******************************************************************/ 846 911 912 /******************************************************************* 913 *******************************************************************/ 847 914 static REGF_SK_REC* find_sk_record_by_sec_desc( REGF_FILE *file, SEC_DESC *sd ) 848 915 { … … 859 926 } 860 927 861 /******************************************************************* 862 *******************************************************************/ 863 928 929 /******************************************************************* 930 *******************************************************************/ 864 931 static bool hbin_prs_key( REGF_FILE *file, REGF_HBIN *hbin, REGF_NK_REC *nk ) 865 932 { … … 876 943 /* fill in values */ 877 944 878 if ( nk->num_values && (nk->values_off!=REGF_OFFSET_NONE) ) { 945 if ( nk->num_values && (nk->values_off!=REGF_OFFSET_NONE) ) 946 { 879 947 sub_hbin = hbin; 880 if ( !hbin_contains_offset( hbin, nk->values_off ) ) { 948 if ( !hbin_contains_offset( hbin, nk->values_off ) ) 949 { 881 950 sub_hbin = lookup_hbin_block( file, nk->values_off ); 882 if ( !sub_hbin ) { 951 if ( !sub_hbin ) 952 { 883 953 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing value_list_offset [0x%x]\n", 884 954 nk->values_off));*/ … … 887 957 } 888 958 889 if ( !hbin_prs_vk_records( "vk_rec", sub_hbin, depth, nk, file))959 if(!hbin_prs_vk_records("vk_rec", sub_hbin, depth, nk, file)) 890 960 return false; 891 961 } 892 962 893 963 /* now get subkeys */ 894 895 if ( nk->num_subkeys && (nk->subkeys_off!=REGF_OFFSET_NONE) ){964 if ( nk->num_subkeys && (nk->subkeys_off!=REGF_OFFSET_NONE) ) 965 { 896 966 sub_hbin = hbin; 897 if ( !hbin_contains_offset( hbin, nk->subkeys_off ) ) { 967 if ( !hbin_contains_offset( hbin, nk->subkeys_off ) ) 968 { 898 969 sub_hbin = lookup_hbin_block( file, nk->subkeys_off ); 899 if ( !sub_hbin ) { 970 if ( !sub_hbin ) 971 { 900 972 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing subkey_offset [0x%x]\n", 901 973 nk->subkeys_off));*/ … … 904 976 } 905 977 906 if ( !hbin_prs_lf_records( "lf_rec", sub_hbin, depth, nk))978 if (!hbin_prs_lf_records("lf_rec", sub_hbin, depth, nk)) 907 979 return false; 908 980 } … … 910 982 /* get the to the security descriptor. First look if we have already parsed it */ 911 983 912 if ( (nk->sk_off!=REGF_OFFSET_NONE) && !( nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off )) ) { 913 984 if ((nk->sk_off!=REGF_OFFSET_NONE) 985 && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off ))) 986 { 914 987 sub_hbin = hbin; 915 if ( !hbin_contains_offset( hbin, nk->sk_off ) ) { 988 if (!hbin_contains_offset(hbin, nk->sk_off)) 989 { 916 990 sub_hbin = lookup_hbin_block( file, nk->sk_off ); 917 991 if ( !sub_hbin ) { … … 937 1011 } 938 1012 939 /******************************************************************* 940 *******************************************************************/ 941 1013 1014 /******************************************************************* 1015 *******************************************************************/ 942 1016 static bool next_record( REGF_HBIN *hbin, const char *hdr, bool *eob ) 943 1017 { … … 954 1028 /* assume that the current offset is at the reacord header 955 1029 and we need to backup to read the record size */ 956 957 1030 curr_off -= sizeof(uint32); 958 1031 959 1032 block_size = ps->buffer_size; 960 1033 record_size = 0; 961 while ( !found ) {962 1034 while ( !found ) 1035 { 963 1036 curr_off = curr_off+record_size; 964 1037 if ( curr_off >= block_size ) … … 985 1058 986 1059 /* mark prs_struct as done ( at end ) if no more SK records */ 987 /* mark end-of-block as true */ 988 989 if ( !found ) 1060 /* mark end-of-block as true */ 1061 if ( !found ) 990 1062 { 991 1063 prs_set_offset( &hbin->ps, hbin->ps.buffer_size ); … … 993 1065 return false; 994 1066 } 995 996 if ( !prs_set_offset( ps, curr_off ))1067 1068 if (!prs_set_offset(ps, curr_off)) 997 1069 return false; 998 1070 … … 1003 1075 /******************************************************************* 1004 1076 *******************************************************************/ 1005 static bool next_nk_record( REGF_FILE *file, REGF_HBIN *hbin, REGF_NK_REC *nk, bool *eob ) 1006 { 1007 if ( next_record( hbin, "nk", eob ) && hbin_prs_key( file, hbin, nk ) ) 1077 static bool next_nk_record(REGF_FILE *file, REGF_HBIN *hbin, 1078 REGF_NK_REC *nk, bool *eob) 1079 { 1080 if (next_record(hbin, "nk", eob) 1081 && hbin_prs_key(file, hbin, nk)) 1008 1082 return true; 1009 1083 … … 1161 1235 1162 1236 /* see if there is anything left to report */ 1163 1164 if ( !nk || (nk->subkeys_off==REGF_OFFSET_NONE) || (nk->subkey_index >= nk->num_subkeys))1237 if (!nk || (nk->subkeys_off==REGF_OFFSET_NONE) 1238 || (nk->subkey_index >= nk->num_subkeys)) 1165 1239 return NULL; 1166 1240 1167 1241 /* find the HBIN block which should contain the nk record */ 1168 1169 1242 if(!(hbin 1170 1243 = lookup_hbin_block(file, nk->subkeys.hashes[nk->subkey_index].nk_off ))) … … 1176 1249 1177 1250 nk_offset = nk->subkeys.hashes[nk->subkey_index].nk_off; 1178 if ( !prs_set_offset( &hbin->ps, (HBIN_HDR_SIZE + nk_offset - hbin->first_hbin_off) ) ) 1251 if(!prs_set_offset(&hbin->ps, 1252 (HBIN_HDR_SIZE + nk_offset - hbin->first_hbin_off))) 1179 1253 return NULL; 1180 1254 1181 1255 nk->subkey_index++; 1182 if 1183 return NULL; 1184 1185 if ( !hbin_prs_key( file, hbin, subkey ))1186 return NULL; 1187 1256 if(!(subkey = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC)))) 1257 return NULL; 1258 1259 if(!hbin_prs_key(file, hbin, subkey)) 1260 return NULL; 1261 1188 1262 return subkey; 1189 1263 }
Note: See TracChangeset
for help on using the changeset viewer.