Changeset 206
- Timestamp:
- 08/25/10 11:20:32 (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r203 r206 359 359 typedef struct _regfi_value_list 360 360 { 361 /* Real offset of this record's cell in the file */ 362 uint32_t offset; 363 364 uint32_t cell_size; 365 361 366 /* Actual number of values referenced by this list. 362 367 * May differ from parent key's num_values if there were parsing errors. … … 373 378 typedef struct _regfi_classname 374 379 { 380 /** Real offset of this record's cell in the file */ 381 uint32_t offset; 382 375 383 /** As converted to requested REGFI_ENCODING */ 376 384 char* interpreted; … … 497 505 * @ingroup regfiBase 498 506 */ 499 typedef struct 507 typedef struct _regfi_vk 500 508 { 501 509 /** Real offset of this record's cell in the file */ … … 504 512 /** ((start_offset - end_offset) & 0xfffffff8) */ 505 513 uint32_t cell_size; 506 507 /* XXX: deprecated */508 REGFI_DATA* data;509 514 510 515 /** The name of this value converted to desired REGFI_ENCODING. … … 513 518 * settings. String is NUL terminated. 514 519 */ 515 char* valuename;520 char* name; 516 521 517 522 /** The raw value name … … 519 524 * Length of the buffer is stored in name_length. 520 525 */ 521 uint8_t* valuename_raw;522 523 /** Length of valuename_raw */526 uint8_t* name_raw; 527 528 /** Length of name_raw */ 524 529 uint16_t name_length; 525 530 … … 553 558 */ 554 559 bool data_in_offset; 560 561 /* XXX: deprecated */ 562 REGFI_DATA* data; 563 555 564 } REGFI_VK; 556 565 557 566 558 567 /* Key Security */ 559 struct _regfi_sk _rec;568 struct _regfi_sk; 560 569 561 570 /** Security structure 562 571 * @ingroup regfiBase 563 572 */ 564 typedef struct _regfi_sk _rec573 typedef struct _regfi_sk 565 574 { 566 575 /** Real file offset of this record */ … … 599 608 * @ingroup regfiBase 600 609 */ 601 typedef struct _regfi_nk _rec610 typedef struct _regfi_nk 602 611 { 603 612 /** Real offset of this record's cell in the file */ … … 642 651 * settings. String is NUL terminated. 643 652 */ 644 char* keyname;653 char* name; 645 654 646 655 /** The raw key name … … 648 657 * Length of the buffer is stored in name_length. 649 658 */ 650 uint8_t* keyname_raw;659 uint8_t* name_raw; 651 660 652 661 /** Virutal offset of parent key */ … … 662 671 uint32_t max_bytes_subkeyclassname; 663 672 664 /* XXX: max value name * 2 */673 /* XXX: max value name * 2 */ 665 674 uint32_t max_bytes_valuename; 666 675 … … 772 781 /* Run-time information */ 773 782 /************************/ 783 /* For sanity checking (not part of the registry header) */ 784 uint32_t file_length; 785 786 /** The encoding that all strings are converted to during interpretation. 787 */ 788 REGFI_ENCODING string_encoding; 789 774 790 /* Functions for accessing the file */ 775 791 REGFI_RAW_FILE* cb; … … 780 796 pthread_mutex_t cb_lock; 781 797 782 /* For sanity checking (not part of the registry header) */783 uint32_t file_length;784 785 798 /* Metadata about hbins */ 786 799 range_list* hbins; … … 811 824 /** The current key */ 812 825 REGFI_NK* cur_key; 813 814 /** The encoding that all strings are converted to as set during iterator815 * creation.816 */817 REGFI_ENCODING string_encoding;818 826 819 827 /** Index of the current subkey */ … … 866 874 */ 867 875 _EXPORT 868 REGFI_FILE* regfi_alloc(int fd );876 REGFI_FILE* regfi_alloc(int fd, REGFI_ENCODING output_encoding); 869 877 870 878 … … 882 890 */ 883 891 _EXPORT 884 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb); 892 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb, 893 REGFI_ENCODING output_encoding); 885 894 886 895 … … 952 961 _EXPORT 953 962 void regfi_free_record(const void* record); 963 964 965 /** Retrieves classname for a given key. 966 * 967 * @param file the file from which key is derived 968 * @param key the key whose classname is desired 969 * 970 * @return Returns a newly allocated classname structure, or NULL on failure. 971 * Classname structures must be freed with @ref regfi_free_record. 972 * 973 * @ingroup regfiBase 974 */ 975 _EXPORT 976 const REGFI_CLASSNAME* regfi_fetch_classname(REGFI_FILE* file, 977 const REGFI_NK* key); 978 979 980 /** Returns the SK (security) record referenced by the supplied key. 981 * 982 * @param file the file from which key is derived 983 * @param key the key whose SK record is desired 984 * 985 * @return A read-only SK structure, or NULL on failure. 986 * 987 * @ingroup regfiBase 988 */ 989 _EXPORT 990 const REGFI_SK* regfi_fetch_sk(REGFI_FILE* file, const REGFI_NK* key); 991 992 993 /** Retrieves data for a given value. 994 * 995 * @param file the file from which value is derived 996 * @param value the value whose data is desired 997 * 998 * @return Returns a newly allocated data structure, or NULL on failure. 999 * Data structures must be freed with @ref regfi_free_record. 1000 * 1001 * @ingroup regfiBase 1002 */ 1003 _EXPORT 1004 const REGFI_DATA* regfi_fetch_data(REGFI_FILE* file, 1005 const REGFI_VK* value); 954 1006 955 1007 … … 982 1034 */ 983 1035 _EXPORT 984 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, 985 REGFI_ENCODING output_encoding); 1036 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file); 986 1037 987 1038 … … 1074 1125 1075 1126 1076 /** Returns the SK (security) record referenced by the current key.1077 *1078 * @param i the iterator1079 *1080 * @return A read-only SK structure, or NULL on failure.1081 *1082 * @ingroup regfiIteratorLayer1083 */1084 _EXPORT1085 const REGFI_SK* regfi_iterator_cur_sk(REGFI_ITERATOR* i);1086 1087 1088 1127 /** Sets the internal subkey index to the first subkey referenced by the current 1089 1128 * key. … … 1193 1232 bool regfi_iterator_find_value(REGFI_ITERATOR* i, 1194 1233 const char* value_name); 1195 1196 /** Retrieves classname for a given key.1197 *1198 * @param i the iterator1199 * @param key the key whose classname is desired1200 *1201 * @return Returns a newly allocated classname structure, or NULL on failure.1202 * Classname structures must be freed with @ref regfi_free_record.1203 *1204 * @ingroup regfiIteratorLayer1205 */1206 _EXPORT1207 const REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i,1208 const REGFI_NK* key);1209 1210 1211 /** Retrieves data for a given value.1212 *1213 * @param i the iterator1214 * @param value the value whose data is desired1215 *1216 * @return Returns a newly allocated data structure, or NULL on failure.1217 * Data structures must be freed with @ref regfi_free_record.1218 *1219 * @ingroup regfiIteratorLayer1220 */1221 _EXPORT1222 const REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i,1223 const REGFI_VK* value);1224 1225 1234 1226 1235 … … 1330 1339 const REGFI_SK* regfi_load_sk(REGFI_FILE* file, uint32_t offset, 1331 1340 bool strict); 1341 1342 1332 1343 1333 1344 … … 1470 1481 /* Private Functions */ 1471 1482 /******************************************************************************/ 1472 REGFI_NK* regfi_rootkey(REGFI_FILE* file, 1473 REGFI_ENCODING output_encoding); 1483 REGFI_NK* regfi_rootkey(REGFI_FILE* file); 1474 1484 1475 1485 off_t regfi_raw_seek(REGFI_RAW_FILE* self, … … 1506 1516 void regfi_add_message(REGFI_FILE* file, uint16_t msg_type, 1507 1517 const char* fmt, ...); 1508 REGFI_NK* regfi_copy_nk(const REGFI_NK* nk);1509 REGFI_VK* regfi_copy_vk(const REGFI_VK* vk);1518 REGFI_NK* regfi_copy_nk(const REGFI_NK* nk); 1519 REGFI_VK* regfi_copy_vk(const REGFI_VK* vk); 1510 1520 _EXPORT 1511 1521 int32_t regfi_calc_maxsize(REGFI_FILE* file, uint32_t offset); -
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 { -
trunk/python/pyregfi/__init__.py
r205 r206 29 29 regfi.regfi_free_record.restype = None 30 30 31 regfi.regfi_fetch_classname.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)] 32 regfi.regfi_fetch_classname.restype = POINTER(REGFI_CLASSNAME) 33 34 regfi.regfi_fetch_sk.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)] 35 regfi.regfi_fetch_sk.restype = POINTER(REGFI_SK) 36 37 regfi.regfi_fetch_data.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_VK)] 38 regfi.regfi_fetch_data.restype = POINTER(REGFI_DATA) 39 31 40 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING] 32 41 regfi.regfi_iterator_new.restype = POINTER(REGFI_ITERATOR) … … 50 59 regfi.regfi_iterator_cur_key.restype = POINTER(REGFI_NK) 51 60 52 regfi.regfi_iterator_cur_sk.argtypes = [POINTER(REGFI_ITERATOR)]53 regfi.regfi_iterator_cur_sk.restype = POINTER(REGFI_SK)54 55 61 regfi.regfi_iterator_first_subkey.argtypes = [POINTER(REGFI_ITERATOR)] 56 62 regfi.regfi_iterator_first_subkey.restype = c_bool … … 76 82 regfi.regfi_iterator_find_value.argtypes = [POINTER(REGFI_ITERATOR), c_char_p] 77 83 regfi.regfi_iterator_find_value.restype = c_bool 78 79 # XXX: possibly move REGFI_ENCODING to file object and eliminate need for ITERATOR here.80 regfi.regfi_iterator_fetch_classname.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_NK)]81 regfi.regfi_iterator_fetch_classname.restype = POINTER(REGFI_CLASSNAME)82 83 regfi.regfi_iterator_fetch_data.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_VK)]84 regfi.regfi_iterator_fetch_data.restype = POINTER(REGFI_DATA)85 84 86 85 … … 91 90 92 91 def GetLogMessages(): 93 return regfi.regfi_log_get_str() 94 92 msgs = regfi.regfi_log_get_str() 93 if msgs == None: 94 return '' 95 return msgs 96 97 98 class _StructureWrapper(): 99 "Handles memory management and proxies attribute access to base structures" 100 base = None 101 102 def __init__(self, base): 103 # XXX: check for NULL here, throw an exception if so. 104 self.base = base 105 106 def __del__(self): 107 regfi.regfi_free_record(self.base) 108 109 def __getattr__(self, name): 110 return getattr(self.base.contents, name) 111 112 def __eq__(self, other): 113 return (type(self) == type(other)) and (self.offset == other.offset) 114 115 def __ne__(self, other): 116 return (not self.__eq__(other)) 117 118 119 class Key(_StructureWrapper): 120 pass 121 122 class Value(_StructureWrapper): 123 pass 124 125 class Data(_StructureWrapper): 126 pass 127 128 class Security(_StructureWrapper): 129 pass 95 130 96 131 class Hive(): … … 126 161 return HiveIterator(self) 127 162 163 def subtree(self, path): 164 hi = HiveIterator(self) 165 hi.descend(path) 166 return hi 167 128 168 129 169 class HiveIterator(): 130 170 hive = None 131 171 iter = None 132 root_traversed = False172 iteration_root = None 133 173 134 174 def __init__(self, hive): … … 147 187 148 188 def __iter__(self): 189 self.iteration_root = None 149 190 return self 150 191 151 192 def __next__(self): 152 if self.root_traversed: 153 self.root_traversed = True 154 193 if self.iteration_root == None: 194 self.iteration_root = self.current_key() 155 195 elif not regfi.regfi_iterator_down(self.iter): 156 196 up_ret = regfi.regfi_iterator_up(self.iter) 157 while up_ret and not regfi.regfi_iterator_next_subkey(self.iter): 197 while (up_ret and 198 not regfi.regfi_iterator_next_subkey(self.iter)): 199 if self.iteration_root == self.current_key(): 200 self.iteration_root = None 201 raise StopIteration('') 158 202 up_ret = regfi.regfi_iterator_up(self.iter) 159 203 … … 166 210 167 211 regfi.regfi_iterator_first_subkey(self.iter) 168 print(regfi.regfi_iterator_cur_key(self.iter).contents.keyname) 169 return regfi.regfi_iterator_cur_key(self.iter) 170 212 return self.current_key() 213 214 def down(self): 215 pass 216 217 def up(self): 218 pass 219 220 def descend(self, path): 221 #set up generator 222 cpath = (bytes(p,'ascii') for p in path) 223 224 # evaluate generator and create char* array 225 apath = (c_char_p*len(path))(*cpath) 226 227 if not regfi.regfi_iterator_walk_path(self.iter,apath): 228 raise Exception('Could not locate path.\n'+GetLogMessages()) 229 230 def current_key(self): 231 return Key(regfi.regfi_iterator_cur_key(self.iter)) -
trunk/python/pyregfi/structures.py
r205 r206 83 83 REGFI_VK._fields_ = [('offset', c_uint32), 84 84 ('cell_size', c_uint32), 85 (' valuename', c_char_p),86 (' valuename_raw', POINTER(c_char)),85 ('name', c_char_p), 86 ('name_raw', POINTER(c_char)), 87 87 ('name_length', c_uint16), 88 88 ('hbin_off', c_uint32), … … 119 119 ('name_length', c_uint16), 120 120 ('classname_length', c_uint16), 121 (' keyname', c_char_p),122 (' keyname_raw', POINTER(c_char)),121 ('name', c_char_p), 122 ('name_raw', POINTER(c_char)), 123 123 ('parent_off', c_uint32), 124 124 ('classname_off', c_uint32), -
trunk/src/common.c
r203 r206 324 324 char* ret_val; 325 325 326 if(nk-> keyname == NULL)327 ret_val = quote_buffer(nk-> keyname_raw, nk->name_length, key_special_chars);326 if(nk->name == NULL) 327 ret_val = quote_buffer(nk->name_raw, nk->name_length, key_special_chars); 328 328 else 329 ret_val = quote_string(nk-> keyname, key_special_chars);329 ret_val = quote_string(nk->name, key_special_chars); 330 330 331 331 return ret_val; … … 337 337 char* ret_val; 338 338 339 if(vk-> valuename == NULL)340 ret_val = quote_buffer(vk-> valuename_raw, vk->name_length,339 if(vk->name == NULL) 340 ret_val = quote_buffer(vk->name_raw, vk->name_length, 341 341 key_special_chars); 342 342 else 343 ret_val = quote_string(vk-> valuename, key_special_chars);343 ret_val = quote_string(vk->name, key_special_chars); 344 344 345 345 return ret_val; -
trunk/src/reglookup-recover.c
r203 r206 832 832 regfi_log_set_mask(REGFI_LOG_ERROR); 833 833 834 f = regfi_alloc(fd); 834 /* XXX: add command line option to choose output encoding */ 835 f = regfi_alloc(fd, REGFI_ENCODING_ASCII); 835 836 if(f == NULL) 836 837 { -
trunk/src/reglookup.c
r203 r206 77 77 } 78 78 79 data = regfi_ iterator_fetch_data(iter, vk);79 data = regfi_fetch_data(iter->f, vk); 80 80 81 81 printMsgs(iter->f); … … 304 304 formatTime(&key->mtime, mtime); 305 305 306 if(print_security && (sk=regfi_ iterator_cur_sk(iter)))306 if(print_security && (sk=regfi_fetch_sk(iter->f, key))) 307 307 { 308 308 owner = regfi_get_owner(sk->sec_desc); … … 321 321 dacl = empty_str; 322 322 323 classname = regfi_ iterator_fetch_classname(iter, key);323 classname = regfi_fetch_classname(iter->f, key); 324 324 printMsgs(iter->f); 325 325 if(classname != NULL) … … 636 636 } 637 637 638 f = regfi_alloc(fd); 638 /* XXX: add command line option to choose output encoding */ 639 f = regfi_alloc(fd, REGFI_ENCODING_ASCII); 639 640 if(f == NULL) 640 641 { … … 643 644 } 644 645 645 646 /* XXX: add command line option to choose output encoding */ 647 iter = regfi_iterator_new(f, REGFI_ENCODING_ASCII); 646 iter = regfi_iterator_new(f); 648 647 if(iter == NULL) 649 648 {
Note: See TracChangeset
for help on using the changeset viewer.