- Timestamp:
- 12/07/09 12:01:22 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r160 r161 19 19 * You should have received a copy of the GNU General Public License 20 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 22 * 23 23 * $Id$ … … 33 33 "MULTI_SZ", "RSRC_LIST", "RSRC_DESC", "RSRC_REQ_LIST", "QWORD"}; 34 34 35 const char* regfi_encoding_names[] = 36 {"US-ASCII//TRANSLIT", "UTF-8//TRANSLIT", "UTF-16LE//TRANSLIT"}; 35 37 36 38 … … 102 104 103 105 104 /* Returns NULL on error */ 106 /****************************************************************************** 107 * Returns NULL for an invalid e 108 *****************************************************************************/ 109 static const char* regfi_encoding_int2str(REGFI_ENCODING e) 110 { 111 if(e < REGFI_NUM_ENCODINGS) 112 return regfi_encoding_names[e]; 113 114 return NULL; 115 } 116 117 118 /****************************************************************************** 119 * Returns NULL for an invalid val 120 *****************************************************************************/ 105 121 const char* regfi_type_val2str(unsigned int val) 106 122 { … … 115 131 116 132 117 /* Returns -1 on error */ 133 /****************************************************************************** 134 * Returns -1 on error 135 *****************************************************************************/ 118 136 int regfi_type_str2val(const char* str) 119 137 { … … 1004 1022 * 1005 1023 ******************************************************************************/ 1006 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, bool strict) 1024 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, 1025 REGFI_ENCODING output_encoding, bool strict) 1007 1026 { 1008 1027 REGFI_NK_REC* nk; 1009 1028 uint32 off; 1010 int32 max_size; 1029 int32 max_size, tmp_size; 1030 REGFI_ENCODING from_encoding; 1011 1031 1012 1032 max_size = regfi_calc_maxsize(file, offset); … … 1021 1041 return NULL; 1022 1042 } 1043 1044 from_encoding = (nk->flags & REGFI_NK_FLAG_ASCIINAME) 1045 ? REGFI_ENCODING_ASCII : REGFI_ENCODING_UTF16LE; 1046 1047 if(from_encoding == output_encoding) 1048 { 1049 nk->keyname_raw = talloc_realloc(nk, nk->keyname_raw, uint8, nk->name_length+1); 1050 nk->keyname_raw[nk->name_length] = '\0'; 1051 nk->keyname = (char*)nk->keyname_raw; 1052 } 1053 else 1054 { 1055 nk->keyname = talloc_array(nk, char, nk->name_length+1); 1056 if(nk->keyname == NULL) 1057 { 1058 regfi_free_key(nk); 1059 return NULL; 1060 } 1061 1062 tmp_size = regfi_conv_charset(regfi_encoding_int2str(from_encoding), 1063 regfi_encoding_int2str(output_encoding), 1064 nk->keyname_raw, nk->keyname, 1065 nk->name_length, nk->name_length+1); 1066 if(tmp_size < 0) 1067 { 1068 regfi_add_message(file, REGFI_MSG_WARN, "Error occurred while converting" 1069 " keyname to encoding %s. Error message: %s", 1070 regfi_encoding_int2str(output_encoding), 1071 strerror(-tmp_size)); 1072 talloc_free(nk->keyname); 1073 nk->keyname = NULL; 1074 } 1075 } 1076 1023 1077 1024 1078 /* get value list */ … … 1132 1186 /****************************************************************************** 1133 1187 ******************************************************************************/ 1134 REGFI_NK_REC* regfi_find_root_nk(REGFI_FILE* file, const REGFI_HBIN* hbin) 1188 REGFI_NK_REC* regfi_find_root_nk(REGFI_FILE* file, const REGFI_HBIN* hbin, 1189 REGFI_ENCODING output_encoding) 1135 1190 { 1136 1191 REGFI_NK_REC* nk = NULL; … … 1151 1206 if(!unalloc) 1152 1207 { 1153 nk = regfi_load_key(file, cur_offset, true);1208 nk = regfi_load_key(file, cur_offset, output_encoding, true); 1154 1209 if(nk != NULL) 1155 1210 { 1156 if(nk-> key_type& REGFI_NK_FLAG_ROOT)1211 if(nk->flags & REGFI_NK_FLAG_ROOT) 1157 1212 return nk; 1158 1213 } … … 1270 1325 * rest of the file if that fails. 1271 1326 ******************************************************************************/ 1272 REGFI_NK_REC* regfi_rootkey(REGFI_FILE *file)1327 REGFI_NK_REC* regfi_rootkey(REGFI_FILE* file, REGFI_ENCODING output_encoding) 1273 1328 { 1274 1329 REGFI_NK_REC* nk = NULL; … … 1280 1335 1281 1336 root_offset = file->root_cell+REGFI_REGF_SIZE; 1282 nk = regfi_load_key(file, root_offset, true);1337 nk = regfi_load_key(file, root_offset, output_encoding, true); 1283 1338 if(nk != NULL) 1284 1339 { 1285 if(nk-> key_type& REGFI_NK_FLAG_ROOT)1340 if(nk->flags & REGFI_NK_FLAG_ROOT) 1286 1341 return nk; 1287 1342 } … … 1298 1353 { 1299 1354 hbin = (REGFI_HBIN*)range_list_get(file->hbins, i)->data; 1300 nk = regfi_find_root_nk(file, hbin );1355 nk = regfi_find_root_nk(file, hbin, output_encoding); 1301 1356 } 1302 1357 … … 1335 1390 /****************************************************************************** 1336 1391 *****************************************************************************/ 1337 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, uint32 output_encoding) 1392 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, 1393 REGFI_ENCODING output_encoding) 1338 1394 { 1339 1395 REGFI_NK_REC* root; 1340 REGFI_ITERATOR* ret_val = talloc(NULL, REGFI_ITERATOR); 1396 REGFI_ITERATOR* ret_val; 1397 1398 if(output_encoding != REGFI_ENCODING_UTF8 1399 && output_encoding != REGFI_ENCODING_ASCII) 1400 { 1401 regfi_add_message(file, REGFI_MSG_ERROR, "Invalid output_encoding supplied" 1402 " in creation of regfi iterator."); 1403 return NULL; 1404 } 1405 1406 ret_val = talloc(NULL, REGFI_ITERATOR); 1341 1407 if(ret_val == NULL) 1342 1408 return NULL; 1343 1409 1344 root = regfi_rootkey(file );1410 root = regfi_rootkey(file, output_encoding); 1345 1411 if(root == NULL) 1346 1412 { … … 1361 1427 ret_val->cur_subkey = 0; 1362 1428 ret_val->cur_value = 0; 1363 1364 switch (output_encoding) 1365 { 1366 case 0: 1367 case 1: 1368 ret_val->string_encoding = "US-ASCII//TRANSLIT"; 1369 break; 1370 case 2: 1371 ret_val->string_encoding = "UTF-8//TRANSLIT"; 1372 break; 1373 default: 1374 talloc_free(ret_val); 1375 return NULL; 1376 } 1377 1429 ret_val->string_encoding = output_encoding; 1430 1378 1431 return ret_val; 1379 1432 } … … 1559 1612 nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].offset; 1560 1613 1561 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, true); 1614 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, i->string_encoding, 1615 true); 1562 1616 } 1563 1617 … … 1695 1749 interpreted = talloc_array(NULL, char, parse_length); 1696 1750 1697 conv_size = regfi_conv_charset(i->string_encoding, 1751 conv_size = regfi_conv_charset(regfi_encoding_int2str(REGFI_ENCODING_UTF16LE), 1752 regfi_encoding_int2str(i->string_encoding), 1698 1753 raw, interpreted, 1699 1754 parse_length, parse_length); … … 1802 1857 /****************************************************************************** 1803 1858 *****************************************************************************/ 1804 bool regfi_interpret_data(REGFI_FILE* file, const char*string_encoding,1859 bool regfi_interpret_data(REGFI_FILE* file, REGFI_ENCODING string_encoding, 1805 1860 uint32 type, REGFI_DATA* data) 1806 1861 { … … 1827 1882 } 1828 1883 1829 tmp_size = regfi_conv_charset(string_encoding, 1884 tmp_size = regfi_conv_charset(regfi_encoding_int2str(REGFI_ENCODING_UTF16LE), 1885 regfi_encoding_int2str(string_encoding), 1830 1886 data->raw, (char*)tmp_str, 1831 1887 data->size, data->size); … … 1893 1949 * then parse and quote fields individually. 1894 1950 */ 1895 tmp_size = regfi_conv_charset(string_encoding, 1951 tmp_size = regfi_conv_charset(regfi_encoding_int2str(REGFI_ENCODING_UTF16LE), 1952 regfi_encoding_int2str(string_encoding), 1896 1953 data->raw, (char*)tmp_str, 1897 1954 data->size, data->size); … … 1969 2026 1970 2027 1971 1972 2028 /******************************************************************* 1973 2029 * Convert from UTF-16LE to specified character set. 1974 2030 * On error, returns a negative errno code. 1975 2031 *******************************************************************/ 1976 int32 regfi_conv_charset(const char* output_charset,2032 int32 regfi_conv_charset(const char* input_charset, const char* output_charset, 1977 2033 uint8* input, char* output, 1978 2034 uint32 input_len, uint32 output_max) … … 1985 2041 int ret; 1986 2042 2043 /* XXX: Consider creating a couple of conversion descriptors earlier, 2044 * storing them on an iterator so they don't have to be recreated 2045 * each time. 2046 */ 2047 1987 2048 /* Set up conversion descriptor. */ 1988 conv_desc = iconv_open(output_charset, "UTF-16LE");2049 conv_desc = iconv_open(output_charset, input_charset); 1989 2050 1990 2051 ret = iconv(conv_desc, &inbuf, &in_len, &outbuf, &out_len); … … 2227 2288 ret_val->magic[0] = nk_header[0x0]; 2228 2289 ret_val->magic[1] = nk_header[0x1]; 2229 ret_val-> key_type= SVAL(nk_header, 0x2);2230 2231 if((ret_val-> key_type& ~REGFI_NK_KNOWN_FLAGS) != 0)2290 ret_val->flags = SVAL(nk_header, 0x2); 2291 2292 if((ret_val->flags & ~REGFI_NK_KNOWN_FLAGS) != 0) 2232 2293 { 2233 2294 regfi_add_message(file, REGFI_MSG_WARN, "Unknown key flags (0x%.4X) while" 2234 2295 " parsing NK record at offset 0x%.8X.", 2235 (ret_val-> key_type& ~REGFI_NK_KNOWN_FLAGS), offset);2296 (ret_val->flags & ~REGFI_NK_KNOWN_FLAGS), offset); 2236 2297 } 2237 2298 … … 2268 2329 ret_val->name_length = SVAL(nk_header, 0x48); 2269 2330 ret_val->classname_length = SVAL(nk_header, 0x4A); 2331 ret_val->keyname = NULL; 2270 2332 2271 2333 if(ret_val->name_length + REGFI_NK_MIN_LENGTH > ret_val->cell_size) … … 2293 2355 } 2294 2356 2295 ret_val->keyname = talloc_array(ret_val, char, ret_val->name_length+1);2296 if(ret_val->keyname == NULL)2357 ret_val->keyname_raw = talloc_array(ret_val, uint8, ret_val->name_length); 2358 if(ret_val->keyname_raw == NULL) 2297 2359 { 2298 2360 talloc_free(ret_val); … … 2302 2364 /* Don't need to seek, should be at the right offset */ 2303 2365 length = ret_val->name_length; 2304 if((regfi_read(file->fd, (uint8*)ret_val->keyname , &length) != 0)2366 if((regfi_read(file->fd, (uint8*)ret_val->keyname_raw, &length) != 0) 2305 2367 || length != ret_val->name_length) 2306 2368 { … … 2310 2372 return NULL; 2311 2373 } 2312 ret_val->keyname[ret_val->name_length] = '\0';2313 2374 2314 2375 return ret_val;
Note: See TracChangeset
for help on using the changeset viewer.