Changeset 161
- Timestamp:
- 12/07/09 12:01:22 (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r160 r161 60 60 #define REGFI_MSG_WARN 0x0004 61 61 #define REGFI_MSG_ERROR 0x0010 62 63 typedef uint8 REGFI_ENCODING; 64 /* regfi library supported character encodings */ 65 #define REGFI_ENCODING_ASCII 0 66 #define REGFI_ENCODING_UTF8 1 67 #define REGFI_ENCODING_DEFAULT REGFI_ENCODING_ASCII 68 /* UTF16LE is not supported for output */ 69 #define REGFI_ENCODING_UTF16LE 2 70 71 #define REGFI_NUM_ENCODINGS 3 62 72 63 73 /* Windows is lame */ … … 360 370 361 371 /* header information */ 362 uint16 key_type;372 uint16 flags; 363 373 uint8 magic[REGFI_CELL_MAGIC_SIZE]; 364 374 NTTIME mtime; … … 479 489 void_stack* key_positions; 480 490 REGFI_NK_REC* cur_key; 481 const char*string_encoding;491 REGFI_ENCODING string_encoding; 482 492 uint32 cur_subkey; 483 493 uint32 cur_value; … … 529 539 * file -- The opened registry file the iterator should be 530 540 * created for. 531 * output_encoding -- An integer representing the output string encoding.532 * These integers currently map to a specific set of533 * iconv(3) encodings.541 * output_encoding -- Character encoding that strings should be returned in. 542 * Only supply the REGFI_ENCODING_* constants, as others 543 * will be rejected. 534 544 * The following values are currently accepted: 535 * 0 - default (currently US-ASCII//TRANSLIT)536 * 1 - US-ASCII//TRANSLIT537 * 2 - UTF-8//TRANSLIT545 * REGFI_ENCODING_DEFAULT (currently REGFI_ENCODING_ASCII) 546 * REGFI_ENCODING_ASCII 547 * REGFI_ENCODING_UTF8 538 548 * 539 549 * XXX: This encoding only applies to specific data … … 545 555 */ 546 556 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, 547 uint32output_encoding);557 REGFI_ENCODING output_encoding); 548 558 void regfi_iterator_free(REGFI_ITERATOR* i); 549 559 bool regfi_iterator_down(REGFI_ITERATOR* i); … … 578 588 /********************************************************/ 579 589 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, 590 REGFI_ENCODING output_encoding, 580 591 bool strict); 581 592 REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32 offset, … … 597 608 bool strict); 598 609 bool regfi_interpret_data(REGFI_FILE* file, 599 const char*string_encoding,610 REGFI_ENCODING string_encoding, 600 611 uint32 type, REGFI_DATA* data); 601 612 void regfi_free_classname(REGFI_CLASSNAME* classname); … … 666 677 /* Private Functions */ 667 678 /************************************/ 668 REGFI_NK_REC* regfi_rootkey(REGFI_FILE* file); 679 REGFI_NK_REC* regfi_rootkey(REGFI_FILE* file, 680 REGFI_ENCODING output_encoding); 669 681 void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list); 670 682 uint32 regfi_read(int fd, uint8* buf, uint32* length); … … 689 701 REGFI_VK_REC* regfi_copy_vk(const REGFI_VK_REC* vk); 690 702 int32 regfi_calc_maxsize(REGFI_FILE* file, uint32 offset); 691 int32 regfi_conv_charset(const char* output_charset, 703 int32 regfi_conv_charset(const char* input_charset, 704 const char* output_charset, 692 705 uint8* input, char* output, 693 706 uint32 input_len, uint32 output_max); -
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; -
trunk/src/reglookup-recover.c
r160 r161 127 127 /* XXX: Add command line option to choose output encoding */ 128 128 if(vk->data != NULL 129 && !regfi_interpret_data(f, "US-ASCII//TRANSLIT", vk->type, vk->data))129 && !regfi_interpret_data(f, REGFI_ENCODING_ASCII, vk->type, vk->data)) 130 130 { 131 131 fprintf(stderr, "WARN: Error occurred while interpreting data for VK record" … … 271 271 else 272 272 { 273 if(cur_ancestor-> key_type& REGFI_NK_FLAG_ROOT)273 if(cur_ancestor->flags & REGFI_NK_FLAG_ROOT) 274 274 virt_offset = REGFI_OFFSET_NONE; 275 275 else -
trunk/src/reglookup.c
r160 r161 191 191 { 192 192 const REGFI_ITER_POSITION* cur; 193 const REGFI_NK_REC* tmp_key; 193 194 uint32 buf_left = 127; 194 195 uint32 buf_len = buf_left+1; … … 198 199 char* new_buf; 199 200 char* name; 200 const char* cur_name;201 201 void_stack_iterator* iter; 202 202 … … 226 226 cur = void_stack_iterator_next(iter); 227 227 if (cur == NULL) 228 cur_name = i->cur_key->keyname; 229 else 230 cur_name = cur->nk->keyname; 228 tmp_key = i->cur_key; 229 else 230 tmp_key = cur->nk; 231 232 if(tmp_key->keyname == NULL) 233 name = quote_buffer(i->cur_key->keyname_raw, i->cur_key->name_length, 234 key_special_chars); 235 else 236 name = quote_string(tmp_key->keyname, key_special_chars); 231 237 232 238 buf[buf_len-buf_left-1] = '/'; 233 239 buf_left -= 1; 234 name = quote_string(cur_name, key_special_chars);235 240 name_len = strlen(name); 236 241 if(name_len+1 > buf_left) … … 617 622 618 623 /* XXX: add command line option to choose output encoding */ 619 iter = regfi_iterator_new(f, 0);624 iter = regfi_iterator_new(f, REGFI_ENCODING_ASCII); 620 625 if(iter == NULL) 621 626 {
Note: See TracChangeset
for help on using the changeset viewer.