- Timestamp:
- 08/25/10 11:20:32 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r203 r206 1131 1131 goto fail_locked; 1132 1132 1133 ret_val->offset = offset; 1134 ret_val->cell_size = cell_length; 1133 1135 ret_val->num_values = num_values; 1134 1136 … … 1175 1177 } 1176 1178 1177 1179 /* XXX: should give this boolean return type to indicate errors */ 1178 1180 void regfi_interpret_valuename(REGFI_FILE* file, REGFI_VK* vk, 1179 1181 REGFI_ENCODING output_encoding, bool strict) … … 1193 1195 if(from_encoding == output_encoding) 1194 1196 { 1195 vk->valuename_raw = talloc_realloc(vk, vk->valuename_raw, 1196 uint8_t, vk->name_length+1); 1197 vk->valuename_raw[vk->name_length] = '\0'; 1198 vk->valuename = (char*)vk->valuename_raw; 1197 vk->name_raw[vk->name_length] = '\0'; 1198 vk->name = (char*)vk->name_raw; 1199 1199 } 1200 1200 else 1201 1201 { 1202 vk->valuename = talloc_array(vk, char, vk->name_length+1); 1203 if(vk->valuename == NULL) 1204 { 1205 talloc_free(vk); 1202 vk->name = talloc_array(vk, char, vk->name_length+1); 1203 if(vk->name == NULL) 1206 1204 return; 1207 }1208 1205 1209 1206 tmp_size = regfi_conv_charset(regfi_encoding_int2str(from_encoding), 1210 1207 regfi_encoding_int2str(output_encoding), 1211 vk-> valuename_raw, vk->valuename,1208 vk->name_raw, vk->name, 1212 1209 vk->name_length, vk->name_length+1); 1213 1210 if(tmp_size < 0) 1214 1211 { 1215 1212 regfi_log_add(REGFI_LOG_WARN, "Error occurred while converting" 1216 " value name to encoding %s. Error message: %s",1213 " value name to encoding %s. Error message: %s", 1217 1214 regfi_encoding_int2str(output_encoding), 1218 1215 strerror(-tmp_size)); 1219 talloc_free(vk-> valuename);1220 vk-> valuename = NULL;1216 talloc_free(vk->name); 1217 vk->name = NULL; 1221 1218 } 1222 1219 } … … 1227 1224 ******************************************************************************/ 1228 1225 REGFI_VK* regfi_load_value(REGFI_FILE* file, uint32_t offset, 1229 1226 REGFI_ENCODING output_encoding, bool strict) 1230 1227 { 1231 1228 REGFI_VK* ret_val = NULL; … … 1272 1269 1273 1270 1271 /* XXX: should give this boolean return type to indicate errors */ 1274 1272 void regfi_interpret_keyname(REGFI_FILE* file, REGFI_NK* nk, 1275 1273 REGFI_ENCODING output_encoding, bool strict) … … 1288 1286 if(from_encoding == output_encoding) 1289 1287 { 1290 nk->keyname_raw = talloc_realloc(nk, nk->keyname_raw, uint8_t, nk->name_length+1); 1291 nk->keyname_raw[nk->name_length] = '\0'; 1292 nk->keyname = (char*)nk->keyname_raw; 1288 nk->name_raw[nk->name_length] = '\0'; 1289 nk->name = (char*)nk->name_raw; 1293 1290 } 1294 1291 else 1295 1292 { 1296 nk->keyname = talloc_array(nk, char, nk->name_length+1); 1297 if(nk->keyname == NULL) 1298 { 1299 talloc_free(nk); 1293 nk->name = talloc_array(nk, char, nk->name_length+1); 1294 if(nk->name == NULL) 1300 1295 return; 1301 } 1296 1297 memset(nk->name,0,nk->name_length+1); 1302 1298 1303 1299 tmp_size = regfi_conv_charset(regfi_encoding_int2str(from_encoding), 1304 1300 regfi_encoding_int2str(output_encoding), 1305 nk-> keyname_raw, nk->keyname,1301 nk->name_raw, nk->name, 1306 1302 nk->name_length, nk->name_length+1); 1307 1303 if(tmp_size < 0) 1308 1304 { 1309 1305 regfi_log_add(REGFI_LOG_WARN, "Error occurred while converting" 1310 " key name to encoding %s. Error message: %s",1306 " key name to encoding %s. Error message: %s", 1311 1307 regfi_encoding_int2str(output_encoding), 1312 1308 strerror(-tmp_size)); 1313 talloc_free(nk-> keyname);1314 nk-> keyname = NULL;1309 talloc_free(nk->name); 1310 nk->name = NULL; 1315 1311 } 1316 1312 } … … 1322 1318 ******************************************************************************/ 1323 1319 REGFI_NK* regfi_load_key(REGFI_FILE* file, uint32_t offset, 1324 1320 REGFI_ENCODING output_encoding, bool strict) 1325 1321 { 1326 1322 REGFI_NK* nk; … … 1466 1462 ******************************************************************************/ 1467 1463 REGFI_NK* regfi_find_root_nk(REGFI_FILE* file, const REGFI_HBIN* hbin, 1468 1464 REGFI_ENCODING output_encoding) 1469 1465 { 1470 1466 REGFI_NK* nk = NULL; … … 1510 1506 /****************************************************************************** 1511 1507 ******************************************************************************/ 1512 REGFI_FILE* regfi_alloc(int fd )1508 REGFI_FILE* regfi_alloc(int fd, REGFI_ENCODING output_encoding) 1513 1509 { 1514 1510 REGFI_FILE* ret_val; … … 1527 1523 file_cb->seek = ®fi_raw_seek; 1528 1524 1529 ret_val = regfi_alloc_cb(file_cb );1525 ret_val = regfi_alloc_cb(file_cb, output_encoding); 1530 1526 if(ret_val == NULL) 1531 1527 goto fail; … … 1557 1553 /****************************************************************************** 1558 1554 ******************************************************************************/ 1559 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb) 1555 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb, 1556 REGFI_ENCODING output_encoding) 1560 1557 { 1561 1558 REGFI_FILE* rb; … … 1577 1574 file_cb->seek(file_cb, 0, SEEK_SET); 1578 1575 1576 if(output_encoding != REGFI_ENCODING_UTF8 1577 && output_encoding != REGFI_ENCODING_ASCII) 1578 { 1579 regfi_log_add(REGFI_LOG_ERROR, "Invalid output_encoding supplied" 1580 " in creation of regfi iterator."); 1581 return NULL; 1582 } 1583 1579 1584 /* Read file header */ 1580 1585 if ((rb = regfi_parse_regf(file_cb, false)) == NULL) … … 1585 1590 rb->file_length = file_length; 1586 1591 rb->cb = file_cb; 1592 rb->string_encoding = output_encoding; 1587 1593 1588 1594 if(pthread_mutex_init(&rb->cb_lock, NULL) != 0) … … 1664 1670 * rest of the file if that fails. 1665 1671 ******************************************************************************/ 1666 REGFI_NK* regfi_rootkey(REGFI_FILE* file , REGFI_ENCODING output_encoding)1672 REGFI_NK* regfi_rootkey(REGFI_FILE* file) 1667 1673 { 1668 1674 REGFI_NK* nk = NULL; … … 1674 1680 1675 1681 root_offset = file->root_cell+REGFI_REGF_SIZE; 1676 nk = regfi_load_key(file, root_offset, output_encoding, true);1682 nk = regfi_load_key(file, root_offset, file->string_encoding, true); 1677 1683 if(nk != NULL) 1678 1684 { … … 1696 1702 { 1697 1703 hbin = (REGFI_HBIN*)range_list_get(file->hbins, i)->data; 1698 nk = regfi_find_root_nk(file, hbin, output_encoding);1704 nk = regfi_find_root_nk(file, hbin, file->string_encoding); 1699 1705 } 1700 1706 … … 1717 1723 /****************************************************************************** 1718 1724 *****************************************************************************/ 1719 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, 1720 REGFI_ENCODING output_encoding) 1725 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file) 1721 1726 { 1722 1727 REGFI_NK* root; 1723 1728 REGFI_ITERATOR* ret_val; 1724 1729 1725 if(output_encoding != REGFI_ENCODING_UTF81726 && output_encoding != REGFI_ENCODING_ASCII)1727 {1728 regfi_log_add(REGFI_LOG_ERROR, "Invalid output_encoding supplied"1729 " in creation of regfi iterator.");1730 return NULL;1731 }1732 1733 1730 ret_val = talloc(NULL, REGFI_ITERATOR); 1734 1731 if(ret_val == NULL) 1735 1732 return NULL; 1736 1733 1737 root = regfi_rootkey(file , output_encoding);1734 root = regfi_rootkey(file); 1738 1735 if(root == NULL) 1739 1736 { … … 1755 1752 ret_val->cur_subkey = 0; 1756 1753 ret_val->cur_value = 0; 1757 ret_val->string_encoding = output_encoding;1758 1754 1759 1755 return ret_val; … … 1853 1849 while((subkey = regfi_iterator_cur_subkey(i)) != NULL && (found == false)) 1854 1850 { 1855 if(subkey-> keyname != NULL1856 && strcasecmp(subkey-> keyname, subkey_name) == 0)1851 if(subkey->name != NULL 1852 && strcasecmp(subkey->name, subkey_name) == 0) 1857 1853 found = true; 1858 1854 else … … 1903 1899 const REGFI_NK* regfi_iterator_cur_key(REGFI_ITERATOR* i) 1904 1900 { 1901 /* XXX: do we need to add a NULL talloc reference here? */ 1905 1902 return i->cur_key; 1906 1903 } … … 1909 1906 /****************************************************************************** 1910 1907 *****************************************************************************/ 1911 const REGFI_SK* regfi_ iterator_cur_sk(REGFI_ITERATOR* i)1912 { 1913 if( i->cur_key == NULL || i->cur_key->sk_off == REGFI_OFFSET_NONE)1914 return NULL; 1915 1916 return regfi_load_sk( i->f, i->cur_key->sk_off + REGFI_REGF_SIZE, true);1908 const REGFI_SK* regfi_fetch_sk(REGFI_FILE* file, const REGFI_NK* key) 1909 { 1910 if(key == NULL || key->sk_off == REGFI_OFFSET_NONE) 1911 return NULL; 1912 1913 return regfi_load_sk(file, key->sk_off + REGFI_REGF_SIZE, true); 1917 1914 } 1918 1915 … … 1941 1938 1942 1939 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, 1943 i-> string_encoding, true);1940 i->f->string_encoding, true); 1944 1941 } 1945 1942 … … 1967 1964 uint32_t old_value = i->cur_value; 1968 1965 1969 /* XXX: cur-> valuename can be NULL in the registry.1966 /* XXX: cur->name can be NULL in the registry. 1970 1967 * Should we allow for a way to search for that? 1971 1968 */ … … 1976 1973 while((cur = regfi_iterator_cur_value(i)) != NULL && (found == false)) 1977 1974 { 1978 if((cur-> valuename != NULL)1979 && (strcasecmp(cur-> valuename, value_name) == 0))1975 if((cur->name != NULL) 1976 && (strcasecmp(cur->name, value_name) == 0)) 1980 1977 found = true; 1981 1978 else … … 2019 2016 voffset = i->cur_key->values->elements[i->cur_value]; 2020 2017 ret_val = regfi_load_value(i->f, voffset+REGFI_REGF_SIZE, 2021 i-> string_encoding, true);2018 i->f->string_encoding, true); 2022 2019 } 2023 2020 … … 2038 2035 /****************************************************************************** 2039 2036 *****************************************************************************/ 2040 const REGFI_CLASSNAME* regfi_ iterator_fetch_classname(REGFI_ITERATOR* i,2041 2037 const REGFI_CLASSNAME* regfi_fetch_classname(REGFI_FILE* file, 2038 const REGFI_NK* key) 2042 2039 { 2043 2040 REGFI_CLASSNAME* ret_val; … … 2052 2049 2053 2050 offset = key->classname_off + REGFI_REGF_SIZE; 2054 max_size = regfi_calc_maxsize( i->f, offset);2051 max_size = regfi_calc_maxsize(file, offset); 2055 2052 if(max_size <= 0) 2056 2053 return NULL; 2057 2054 2058 2055 parse_length = key->classname_length; 2059 raw = regfi_parse_classname( i->f, offset, &parse_length, max_size, true);2056 raw = regfi_parse_classname(file, offset, &parse_length, max_size, true); 2060 2057 2061 2058 if(raw == NULL) … … 2071 2068 return NULL; 2072 2069 2070 ret_val->offset = offset; 2073 2071 ret_val->raw = raw; 2074 2072 ret_val->size = parse_length; … … 2078 2076 2079 2077 conv_size = regfi_conv_charset(regfi_encoding_int2str(REGFI_ENCODING_UTF16LE), 2080 regfi_encoding_int2str( i->string_encoding),2078 regfi_encoding_int2str(file->string_encoding), 2081 2079 raw, interpreted, 2082 2080 parse_length, parse_length); … … 2085 2083 regfi_log_add(REGFI_LOG_WARN, "Error occurred while" 2086 2084 " converting classname to charset %s. Error message: %s", 2087 i->string_encoding, strerror(-conv_size));2085 file->string_encoding, strerror(-conv_size)); 2088 2086 talloc_free(interpreted); 2089 2087 ret_val->interpreted = NULL; … … 2102 2100 /****************************************************************************** 2103 2101 *****************************************************************************/ 2104 const REGFI_DATA* regfi_ iterator_fetch_data(REGFI_ITERATOR* i,2105 2102 const REGFI_DATA* regfi_fetch_data(REGFI_FILE* file, 2103 const REGFI_VK* value) 2106 2104 { 2107 2105 REGFI_DATA* ret_val = NULL; … … 2110 2108 if(value->data_size != 0) 2111 2109 { 2112 raw_data = regfi_load_data( i->f, value->data_off, value->data_size,2110 raw_data = regfi_load_data(file, value->data_off, value->data_size, 2113 2111 value->data_in_offset, true); 2114 2112 if(raw_data.buf == NULL) … … 2132 2130 } 2133 2131 2134 if(!regfi_interpret_data(i->f, i->string_encoding, value->type, ret_val)) 2132 if(!regfi_interpret_data(file, file->string_encoding, 2133 value->type, ret_val)) 2135 2134 { 2136 2135 regfi_log_add(REGFI_LOG_INFO, "Error occurred while" … … 2344 2343 *****************************************************************************/ 2345 2344 int32_t regfi_conv_charset(const char* input_charset, const char* output_charset, 2346 uint8_t* input, char* output,2347 uint32_t input_len, uint32_t output_max)2345 uint8_t* input, char* output, 2346 uint32_t input_len, uint32_t output_max) 2348 2347 { 2349 2348 iconv_t conv_desc; … … 2657 2656 ret_val->name_length = SVAL(nk_header, 0x48); 2658 2657 ret_val->classname_length = SVAL(nk_header, 0x4A); 2659 ret_val-> keyname = NULL;2658 ret_val->name = NULL; 2660 2659 2661 2660 if(ret_val->name_length + REGFI_NK_MIN_LENGTH > ret_val->cell_size) … … 2682 2681 } 2683 2682 2684 ret_val->keyname_raw = talloc_array(ret_val, uint8_t, ret_val->name_length); 2685 if(ret_val->keyname_raw == NULL) 2683 /* +1 to length in case we decided to use this directly as a string later */ 2684 ret_val->name_raw = talloc_array(ret_val, uint8_t, ret_val->name_length+1); 2685 if(ret_val->name_raw == NULL) 2686 2686 goto fail_locked; 2687 2687 2688 2688 /* Don't need to seek, should be at the right offset */ 2689 2689 length = ret_val->name_length; 2690 if((regfi_read(file->cb, (uint8_t*)ret_val-> keyname_raw, &length) != 0)2690 if((regfi_read(file->cb, (uint8_t*)ret_val->name_raw, &length) != 0) 2691 2691 || length != ret_val->name_length) 2692 2692 { … … 2710 2710 2711 2711 uint8_t* regfi_parse_classname(REGFI_FILE* file, uint32_t offset, 2712 uint16_t* name_length, uint32_t max_size, bool strict)2712 uint16_t* name_length, uint32_t max_size, bool strict) 2713 2713 { 2714 2714 uint8_t* ret_val = NULL; … … 2811 2811 ret_val->offset = offset; 2812 2812 ret_val->cell_size = cell_length; 2813 ret_val-> valuename = NULL;2814 ret_val-> valuename_raw = NULL;2813 ret_val->name = NULL; 2814 ret_val->name_raw = NULL; 2815 2815 2816 2816 if(ret_val->cell_size > max_size) … … 2867 2867 cell_length+=8; 2868 2868 2869 ret_val->valuename_raw = talloc_array(ret_val, uint8_t, ret_val->name_length); 2870 if(ret_val->valuename_raw == NULL) 2869 /* +1 to length in case we decided to use this directly as a string later */ 2870 ret_val->name_raw = talloc_array(ret_val, uint8_t, ret_val->name_length+1); 2871 if(ret_val->name_raw == NULL) 2871 2872 goto fail_locked; 2872 2873 2873 2874 length = ret_val->name_length; 2874 if((regfi_read(file->cb, (uint8_t*)ret_val-> valuename_raw, &length) != 0)2875 if((regfi_read(file->cb, (uint8_t*)ret_val->name_raw, &length) != 0) 2875 2876 || length != ret_val->name_length) 2876 2877 {
Note: See TracChangeset
for help on using the changeset viewer.