- Timestamp:
- 03/27/11 21:46:11 (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r209 r215 666 666 uint8_t* name_raw; 667 667 668 /** Vir utal offset of parent key */668 /** Virtual offset of parent key */ 669 669 uint32_t parent_off; 670 670 671 /** Vir utal offset of classname key */671 /** Virtual offset of classname key */ 672 672 uint32_t classname_off; 673 673 … … 952 952 953 953 954 /* Dispose of previously parsed records */ 954 /** Fetches a hive's root key. 955 * 956 * @return Returns the root key or NULL on failure. Key must be freed using 957 * @ref regfi_free_record. 958 * 959 * @ingroup regfiBase 960 */ 961 _EXPORT 962 const REGFI_NK* regfi_get_rootkey(REGFI_FILE* file); 963 955 964 956 965 /** Frees a record previously returned by one of the API functions. … … 962 971 * convenience. Since records returned previously must not be modified by users 963 972 * of the API due to internal caching, these are returned as const, so this 964 * function is const to make passing back ineasy.973 * function is const to make passing those records back easy. 965 974 * 966 975 * @ingroup regfiBase … … 1110 1119 uint32_t index); 1111 1120 1121 1122 1123 /** Uses a key's parent_off reference to retrieve it's parent. 1124 * 1125 * @param file the file from which key is derived 1126 * @param key the key whose parent is desired 1127 * 1128 * @return the requested subkey or NULL on error. 1129 * 1130 * @ingroup regfiBase 1131 */ 1132 _EXPORT 1133 const REGFI_NK* regfi_get_parentkey(REGFI_FILE* file, const REGFI_NK* key); 1112 1134 1113 1135 … … 1345 1367 /******************************************************************************/ 1346 1368 1347 /** Loads a key a t a given file offset along with associated data structures.1369 /** Loads a key and associated data structures given a file offset. 1348 1370 * 1349 1371 * XXX: finish documenting … … 1353 1375 _EXPORT 1354 1376 REGFI_NK* regfi_load_key(REGFI_FILE* file, uint32_t offset, 1355 1356 1377 REGFI_ENCODING output_encoding, 1378 bool strict); 1357 1379 1358 1380 … … 1584 1606 1585 1607 /******************************************************************************/ 1586 /* Private Functions */ 1587 /******************************************************************************/ 1588 REGFI_NK* regfi_rootkey(REGFI_FILE* file); 1589 1608 /* Private (and undocumented) Functions */ 1609 /******************************************************************************/ 1590 1610 off_t regfi_raw_seek(REGFI_RAW_FILE* self, 1591 1611 off_t offset, int whence); -
trunk/lib/regfi.c
r213 r215 1670 1670 * rest of the file if that fails. 1671 1671 ******************************************************************************/ 1672 REGFI_NK* regfi_rootkey(REGFI_FILE* file)1672 const REGFI_NK* regfi_get_rootkey(REGFI_FILE* file) 1673 1673 { 1674 1674 REGFI_NK* nk = NULL; … … 1695 1695 */ 1696 1696 1697 if(!regfi_read_lock(file, &file->hbins_lock, "regfi_ rootkey"))1697 if(!regfi_read_lock(file, &file->hbins_lock, "regfi_get_rootkey")) 1698 1698 return NULL; 1699 1699 … … 1705 1705 } 1706 1706 1707 if(!regfi_rw_unlock(file, &file->hbins_lock, "regfi_ rootkey"))1707 if(!regfi_rw_unlock(file, &file->hbins_lock, "regfi_get_rootkey")) 1708 1708 return NULL; 1709 1709 … … 1727 1727 { 1728 1728 uint32_t num_in_list = 0; 1729 if(key == NULL) 1730 return 0; 1731 1729 1732 if(key->subkeys != NULL) 1730 1733 num_in_list = key->subkeys->num_keys; … … 1747 1750 { 1748 1751 uint32_t num_in_list = 0; 1752 if(key == NULL) 1753 return 0; 1754 1749 1755 if(key->values != NULL) 1750 1756 num_in_list = key->values->num_values; … … 1773 1779 return NULL; 1774 1780 1775 root = regfi_rootkey(file);1781 root = (REGFI_NK*)regfi_get_rootkey(file); 1776 1782 if(root == NULL) 1777 1783 { … … 1906 1912 1907 1913 if(path[x] == NULL) 1914 { 1908 1915 return true; 1909 1916 } 1917 1910 1918 /* XXX: is this the right number of times? */ 1911 1919 for(; x > 0; x--) … … 2212 2220 2213 2221 2214 2215 2222 /****************************************************************************** 2216 2223 *****************************************************************************/ … … 2227 2234 return NULL; 2228 2235 } 2236 2237 2238 2239 /****************************************************************************** 2240 *****************************************************************************/ 2241 const REGFI_NK* regfi_get_parentkey(REGFI_FILE* file, const REGFI_NK* key) 2242 { 2243 if(key != NULL && key->parent_off != REGFI_OFFSET_NONE) 2244 { 2245 /* fprintf(stderr, "key->parent_off=%.8X\n", key->parent_off);*/ 2246 return regfi_load_key(file, 2247 key->parent_off+REGFI_REGF_SIZE, 2248 file->string_encoding, true); 2249 } 2250 2251 return NULL; 2252 } 2253 2229 2254 2230 2255 -
trunk/python/pyregfi/__init__.py
r214 r215 31 31 regfi.regfi_log_set_mask.restype = c_bool 32 32 33 regfi.regfi_get_rootkey.argtypes = [POINTER(REGFI_FILE)] 34 regfi.regfi_get_rootkey.restype = POINTER(REGFI_NK) 35 33 36 regfi.regfi_free_record.argtypes = [c_void_p] 34 37 regfi.regfi_free_record.restype = None … … 64 67 c_uint32] 65 68 regfi.regfi_get_value.restype = POINTER(REGFI_VK) 69 70 regfi.regfi_get_parentkey.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)] 71 regfi.regfi_get_parentkey.restype = POINTER(REGFI_NK) 66 72 67 73 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING] … … 122 128 if msgs == None: 123 129 return '' 124 return msgs.decode(' ascii')130 return msgs.decode('utf-8') 125 131 126 132 … … 132 138 for i in range(0,length): 133 139 ret_val[i] = char_pointer[i][0] 140 141 return ret_val 142 143 144 def _strlist2charss(str_list): 145 ret_val = [] 146 for s in str_list: 147 ret_val.append(s.encode('utf-8', 'replace')) 148 149 ret_val = (c_char_p*(len(str_list)+1))(*ret_val) 150 # Terminate the char** with a NULL pointer 151 ret_val[-1] = 0 134 152 135 153 return ret_val … … 155 173 156 174 def __init__(self, hive, base): 175 if not hive: 176 raise Exception("Could not create _StructureWrapper," 177 + " hive is NULL. Current log:\n" 178 + GetLogMessages()) 179 if not base: 180 raise Exception("Could not create _StructureWrapper," 181 + " base is NULL. Current log:\n" 182 + GetLogMessages()) 157 183 self._hive = hive 158 # XXX: check for NULL here, throw an exception if so.159 184 self._base = base 160 185 161 186 def __del__(self): 162 187 regfi.regfi_free_record(self._base) 163 hive = None164 188 165 189 def __getattr__(self, name): … … 172 196 return (not self.__eq__(other)) 173 197 174 ## Registry key175 198 class Key(_StructureWrapper): 176 199 pass … … 248 271 249 272 elem = self._get_element(self._hive.file, self._key._base, 250 c_uint32(self._current))273 c_uint32(self._current)) 251 274 self._current += 1 252 275 return self._constructor(self._hive, elem) … … 268 291 269 292 293 ## Registry key 270 294 class Key(_StructureWrapper): 271 295 values = None … … 295 319 def fetch_security(self): 296 320 return Security(self._hive, 297 regfi.regfi_fetch_sk(self._hive.file, self.base)) 321 regfi.regfi_fetch_sk(self._hive.file, self._base)) 322 323 def get_parent(self): 324 parent_base = regfi.regfi_get_parentkey(self._hive.file, self._base) 325 if parent_base: 326 return Key(self._hive, parent_base) 327 328 return None 329 330 def is_root(self): 331 # This is quicker than retrieving the root key for comparison and 332 # is more trustworthy than trusting the key's flags. 333 return ((self._hive.root_cell+REGFI_REGF_SIZE) == self.offset) 298 334 299 335 … … 402 438 return HiveIterator(self) 403 439 440 def get_root(self): 441 return Key(self, regfi.regfi_get_rootkey(self.file)) 442 443 404 444 ## Creates a @ref HiveIterator initialized at the specified path in 405 445 # the hive. … … 479 519 480 520 def descend(self, path): 481 #set up generator 482 cpath = (bytes(p,'ascii') for p in path) 483 484 # evaluate generator and create char* array 485 apath = (c_char_p*len(path))(*cpath) 521 cpath = _strlist2charss(path) 486 522 487 523 # XXX: Use non-generic exception 488 if not regfi.regfi_iterator_walk_path(self.iter, apath):524 if not regfi.regfi_iterator_walk_path(self.iter, cpath): 489 525 raise Exception('Could not locate path.\n'+GetLogMessages()) 490 526 -
trunk/python/pyregfi/structures.py
r213 r215 13 13 14 14 REGFI_DATA_TYPE = c_uint32 15 REGFI_REGF_SIZE = 0x1000 15 16 16 17 # Registry value data types
Note: See TracChangeset
for help on using the changeset viewer.