- Timestamp:
- 03/25/11 11:48:27 (14 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.