Changeset 224 for trunk/python
- Timestamp:
- 04/03/11 12:53:59 (14 years ago)
- Location:
- trunk/python/pyregfi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/pyregfi/__init__.py
r221 r224 200 200 self._base = base 201 201 202 202 203 # Memory management for most regfi structures is taken care of here 203 204 def __del__(self): 204 205 regfi.regfi_free_record(self._base) 206 205 207 206 208 # Any attribute requests not explicitly defined in subclasses gets passed … … 208 210 def __getattr__(self, name): 209 211 return getattr(self._base.contents, name) 212 210 213 211 214 ## Test for equality … … 224 227 return (type(self) == type(other)) and (self.offset == other.offset) 225 228 229 226 230 def __ne__(self, other): 227 231 return (not self.__eq__(other)) … … 244 248 class _GenericList(object): 245 249 _hive = None 246 _key = None250 _key_base = None 247 251 _length = None 248 252 _current = None … … 255 259 256 260 def __init__(self, key): 261 if not key: 262 raise Exception("Could not create _GenericList; key is NULL." 263 + "Current log:\n" + GetLogMessages()) 264 265 if not regfi.regfi_reference_record(key._base): 266 raise Exception("Could not create _GenericList; memory error." 267 + "Current log:\n" + GetLogMessages()) 268 self._key_base = key._base 269 self._length = self._fetch_num(self._key_base) 257 270 self._hive = key._hive 258 271 259 # Normally it's good to avoid cyclic references like this 260 # (key.list.key...) but in this case it makes ctypes memory 261 # management easier to reference the Key instead of the base 262 # structure. We use a weak reference in order to allow for garbage 263 # collection, since value/subkey lists should not be usable if their 264 # parent Key is freed anyway. 265 266 # XXX: check for NULL here, throw an exception if so. 267 self._key = weakref.proxy(key) 268 self._length = self._fetch_num(key._base) 269 270 272 273 def __del__(self): 274 regfi.regfi_free_record(self._key_base) 275 276 271 277 ## Length of list 272 278 def __len__(self): … … 286 292 name = create_string_buffer(bytes(name)) 287 293 288 if self._find_element(self._hive.file, self._key ._base,294 if self._find_element(self._hive.file, self._key_base, 289 295 name, byref(index)): 290 296 return self._constructor(self._hive, 291 297 self._get_element(self._hive.file, 292 self._key ._base,298 self._key_base, 293 299 index)) 294 300 raise KeyError('') … … 308 314 raise StopIteration('') 309 315 310 elem = self._get_element(self._hive.file, self._key ._base,316 elem = self._get_element(self._hive.file, self._key_base, 311 317 ctypes.c_uint32(self._current)) 312 318 self._current += 1 … … 638 644 def __getattr__(self, name): 639 645 if name == "root": 640 if self._root == None: 641 self._root = Key(self, regfi.regfi_get_rootkey(self.file)) 642 return self._root 646 # XXX: This creates reference loops. Need to cache better inside regfi 647 #if self._root == None: 648 # self._root = Key(self, regfi.regfi_get_rootkey(self.file)) 649 #return self._root 650 return Key(self, regfi.regfi_get_rootkey(self.file)) 643 651 644 652 elif name == "modified": -
trunk/python/pyregfi/structures.py
r221 r224 241 241 regfi.regfi_free_record.restype = None 242 242 243 regfi.regfi_reference_record.argtypes = [c_void_p] 244 regfi.regfi_reference_record.restype = c_bool 245 243 246 regfi.regfi_fetch_num_subkeys.argtypes = [POINTER(REGFI_NK)] 244 247 regfi.regfi_fetch_num_subkeys.restype = c_uint32
Note: See TracChangeset
for help on using the changeset viewer.