Changeset 215 for trunk/python
- Timestamp:
- 03/27/11 21:46:11 (14 years ago)
- Location:
- trunk/python/pyregfi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.