Changeset 224
- Timestamp:
- 04/03/11 12:53:59 (14 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
test/pyregfi-smoketest.py
r220 r224 201 201 files = [] 202 202 for f in sys.argv[1:]: 203 files.append((f, open(f,"r +b")))203 files.append((f, open(f,"rb"))) 204 204 205 205 … … 216 216 print 217 217 sys.stdout.flush() 218 fh.close() 218 219 219 220 hive = None -
trunk/include/regfi.h
r221 r224 979 979 980 980 981 /** Increments reference count on record 982 * 983 * Adds an extra internal reference to specified record, making it necessary to 984 * call regfi_free_record on it an additional time before it is freed. This is 985 * useful in cases where multiple threads/structures need access to a record, 986 * without requiring them to be in sync with when it is freed. 987 * 988 * Can be used on REGFI_NK, REGFI_VK, REGFI_SK, REGFI_DATA, and 989 * REGFI_CLASSNAME records. 990 * 991 * @return true on success, false otherwise 992 * 993 * @ingroup regfiBase 994 */ 995 _EXPORT 996 bool regfi_reference_record(const void* record); 997 998 981 999 /** Retrieves number of subkeys referenced by this key. 982 1000 * -
trunk/lib/regfi.c
r223 r224 1720 1720 1721 1721 1722 /****************************************************************************** 1723 *****************************************************************************/ 1724 bool regfi_reference_record(const void* record) 1725 { 1726 if(talloc_reference(NULL, record) != NULL) 1727 return true; 1728 return false; 1729 } 1722 1730 1723 1731 -
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.