Changeset 213
- Timestamp:
- 03/25/11 11:48:27 (14 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
test/pyregfi-smoketest.py
r209 r213 1 #!/usr/bin/env python 1 #!/usr/bin/env python3 2 2 3 3 import sys 4 import gc 4 5 import pyregfi 5 6 6 files = sys.argv[1:] 7 def usage(): 8 sys.stderr.write("USAGE: pyregfi-smoketest.py hive1 [hive2 ...]\n") 7 9 8 10 9 def iter_values(key): 10 i = 0 11 for value in key.values(): 12 i += 1 13 14 return i 11 # Uses the HiveIterator to walk all keys 12 # Gathers various (meaningless) statistics to exercise simple attribute access 13 # and to hopefully smoke out any bugs that can be identified by changing stats 14 def iterTally(hive): 15 key_count = 0 16 key_lens = 0 17 key_rawlens = 0 18 value_count = 0 19 value_lens = 0 20 value_rawlens = 0 21 22 for k in hive: 23 key_count += 1 24 if k.name != None: 25 key_lens += len(k.name) 26 if k.name_raw != None: 27 key_rawlens += len(k.name_raw) 28 29 for v in k.values: 30 value_count += 1 31 if v.name != None: 32 value_lens += len(v.name) 33 if v.name_raw != None: 34 value_rawlens += len(v.name_raw) 35 36 print(" Counts: keys=%d, values=%d\n" % (key_count, value_count)) 37 print(" Total name length: keys=%d, values=%d\n" % (key_lens, value_lens)) 38 print(" Total raw name lengths: keys=%d, values=%d\n" % (key_rawlens, value_rawlens)) 15 39 16 40 17 for f in files:18 rf = pyregfi.RegistryFile(f)19 iter = rf.TreeIterator()20 41 21 num_keys = 0 22 num_values = 0 23 # The iterator now walks the entire registry hive, depth-first 24 for key in iter: 25 #print key.key.keyname 26 num_keys +=1 27 num_values += iter_values(key) 42 if len(sys.argv) < 2: 43 usage() 44 sys.exit(1) 28 45 29 print "keys: %d" % num_keys 30 print "values: %d" % num_values 46 files = [] 47 for f in sys.argv[1:]: 48 files.append((f, open(f,"r+b"))) 31 49 50 tests = [("iterTally",iterTally),] 32 51 33 iter = rf.TreeIterator() 34 root = iter.current() 35 for key in root.subkeys(): 36 for subkey in key.subkeys(): 37 for subsubkey in subkey.subkeys(): 38 print key.key.keyname 52 for hname,fh in files: 53 hive = pyregfi.Hive(fh) 54 for tname,t in tests: 55 tstr = "'%s' on '%s'" % (tname,hname) 56 print("##BEGIN %s:" % tstr) 57 t(hive) 58 print("##END %s; messages:" % tstr) 59 print(pyregfi.GetLogMessages()) 60 print 61 hive = None 62 gc.collect() 39 63 64 files = None 65 tests = None 66 gc.collect() 67 print gc.garbage -
trunk/lib/regfi.c
r209 r213 1780 1780 } 1781 1781 ret_val->cur_key = root; 1782 talloc_re ference(ret_val, root);1782 talloc_reparent(NULL, ret_val, root); 1783 1783 1784 1784 ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH); … … 1834 1834 return false; 1835 1835 } 1836 talloc_re ference(i, subkey);1836 talloc_reparent(NULL, i, subkey); 1837 1837 1838 1838 i->cur_key = subkey; … … 1920 1920 const REGFI_NK* regfi_iterator_cur_key(REGFI_ITERATOR* i) 1921 1921 { 1922 /* XXX: do we need to add a NULL talloc reference here? */1922 talloc_reference(NULL, i->cur_key); 1923 1923 return i->cur_key; 1924 1924 } -
trunk/python/pyregfi/__init__.py
r212 r213 15 15 16 16 17 regfi.regfi_alloc.argtypes = [c_int ]17 regfi.regfi_alloc.argtypes = [c_int, REGFI_ENCODING] 18 18 regfi.regfi_alloc.restype = POINTER(REGFI_FILE) 19 19 20 regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE) ]20 regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE), REGFI_ENCODING] 21 21 regfi.regfi_alloc_cb.restype = POINTER(REGFI_FILE) 22 22 … … 140 140 s = chars_pointer[i] 141 141 while s != None: 142 ret_val.append(s.decode('utf-8' ))142 ret_val.append(s.decode('utf-8', 'replace')) 143 143 i += 1 144 144 s = chars_pointer[i] … … 150 150 # access to base structures 151 151 class _StructureWrapper(object): 152 153 152 hive = None 154 153 base = None … … 161 160 def __del__(self): 162 161 regfi.regfi_free_record(self.base) 162 hive = None 163 163 164 164 def __getattr__(self, name): … … 205 205 self.length = self.fetch_num(key.base) 206 206 207 def __del__(self): 208 self.key = None 209 207 210 def __len__(self): 208 211 return self.length … … 274 277 ret_val = self.name_raw 275 278 else: 276 ret_val = ret_val.decode('utf-8' )279 ret_val = ret_val.decode('utf-8', 'replace') 277 280 278 281 elif name == "name_raw": … … 307 310 elif data_struct.type in (REG_SZ, REG_EXPAND_SZ, REG_LINK): 308 311 # Unicode strings 309 ret_val = data_struct.interpreted.string.decode('utf-8' )312 ret_val = data_struct.interpreted.string.decode('utf-8', 'replace') 310 313 elif data_struct.type in (REG_DWORD, REG_DWORD_BE): 311 314 # 32 bit integers … … 343 346 ret_val = self.name_raw 344 347 else: 345 ret_val = ret_val.decode('utf-8' )348 ret_val = ret_val.decode('utf-8', 'replace') 346 349 347 350 elif name == "name_raw": … … 370 373 try: 371 374 if hasattr(fh, 'fileno'): 372 self.file = regfi.regfi_alloc(fh.fileno() )375 self.file = regfi.regfi_alloc(fh.fileno(), REGFI_ENCODING_UTF8) 373 376 return 374 377 except: … … 379 382 self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek) 380 383 self.raw_file.read = read_cb_type(self.raw_file.cb_read) 381 self.file = regfi.regfi_alloc_cb(self.raw_file )384 self.file = regfi.regfi_alloc_cb(self.raw_file, REGFI_ENCODING_UTF8) 382 385 383 386 def __getattr__(self, name): … … 387 390 regfi.regfi_free(self.file) 388 391 if self.raw_file != None: 389 regfi.regfi_free(self.file) 390 392 self.raw_file = None 391 393 392 394 def __iter__(self): … … 421 423 422 424 def __init__(self, hive): 423 # REGFI_ENCODING_UTF8==1 424 self.iter = regfi.regfi_iterator_new(hive.file, 1) 425 self.iter = regfi.regfi_iterator_new(hive.file, REGFI_ENCODING_UTF8) 425 426 if self.iter == None: 426 427 raise Exception("Could not create iterator. Current log:\n" … … 432 433 433 434 def __del__(self): 434 regfi.regfi_iterator_free(self.iter) 435 regfi.regfi_iterator_free(self.iter) 435 436 436 437 def __iter__(self): … … 440 441 def __next__(self): 441 442 if self.iteration_root == None: 442 self.iteration_root = self.current_key() 443 self.iteration_root = self.current_key() 443 444 elif not regfi.regfi_iterator_down(self.iter): 444 445 up_ret = regfi.regfi_iterator_up(self.iter) -
trunk/python/pyregfi/structures.py
r209 r213 10 10 # XXX: can we always be sure enums are this size? 11 11 REGFI_ENCODING = c_uint32 12 REGFI_ENCODING_UTF8 = 1 13 12 14 REGFI_DATA_TYPE = c_uint32 13 15 -
trunk/src/reglookup.c
r206 r213 406 406 if(cur != root) 407 407 { 408 regfi_free_record(cur); 408 409 /* We're done with this sub-tree, going up and hitting other branches. */ 409 410 if(!regfi_iterator_up(iter)) … … 429 430 * Let's move down and print this first sub-tree out. 430 431 */ 432 regfi_free_record(cur); 431 433 if(!regfi_iterator_down(iter)) 432 434 { … … 443 445 printMsgs(iter->f); 444 446 } while(!((cur == root) && (sub == NULL))); 447 regfi_free_record(root); 445 448 446 449 if(print_verbose)
Note: See TracChangeset
for help on using the changeset viewer.