Changeset 206 for trunk/python
- Timestamp:
- 08/25/10 11:20:32 (14 years ago)
- Location:
- trunk/python/pyregfi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/pyregfi/__init__.py
r205 r206 29 29 regfi.regfi_free_record.restype = None 30 30 31 regfi.regfi_fetch_classname.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)] 32 regfi.regfi_fetch_classname.restype = POINTER(REGFI_CLASSNAME) 33 34 regfi.regfi_fetch_sk.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)] 35 regfi.regfi_fetch_sk.restype = POINTER(REGFI_SK) 36 37 regfi.regfi_fetch_data.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_VK)] 38 regfi.regfi_fetch_data.restype = POINTER(REGFI_DATA) 39 31 40 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING] 32 41 regfi.regfi_iterator_new.restype = POINTER(REGFI_ITERATOR) … … 50 59 regfi.regfi_iterator_cur_key.restype = POINTER(REGFI_NK) 51 60 52 regfi.regfi_iterator_cur_sk.argtypes = [POINTER(REGFI_ITERATOR)]53 regfi.regfi_iterator_cur_sk.restype = POINTER(REGFI_SK)54 55 61 regfi.regfi_iterator_first_subkey.argtypes = [POINTER(REGFI_ITERATOR)] 56 62 regfi.regfi_iterator_first_subkey.restype = c_bool … … 76 82 regfi.regfi_iterator_find_value.argtypes = [POINTER(REGFI_ITERATOR), c_char_p] 77 83 regfi.regfi_iterator_find_value.restype = c_bool 78 79 # XXX: possibly move REGFI_ENCODING to file object and eliminate need for ITERATOR here.80 regfi.regfi_iterator_fetch_classname.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_NK)]81 regfi.regfi_iterator_fetch_classname.restype = POINTER(REGFI_CLASSNAME)82 83 regfi.regfi_iterator_fetch_data.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_VK)]84 regfi.regfi_iterator_fetch_data.restype = POINTER(REGFI_DATA)85 84 86 85 … … 91 90 92 91 def GetLogMessages(): 93 return regfi.regfi_log_get_str() 94 92 msgs = regfi.regfi_log_get_str() 93 if msgs == None: 94 return '' 95 return msgs 96 97 98 class _StructureWrapper(): 99 "Handles memory management and proxies attribute access to base structures" 100 base = None 101 102 def __init__(self, base): 103 # XXX: check for NULL here, throw an exception if so. 104 self.base = base 105 106 def __del__(self): 107 regfi.regfi_free_record(self.base) 108 109 def __getattr__(self, name): 110 return getattr(self.base.contents, name) 111 112 def __eq__(self, other): 113 return (type(self) == type(other)) and (self.offset == other.offset) 114 115 def __ne__(self, other): 116 return (not self.__eq__(other)) 117 118 119 class Key(_StructureWrapper): 120 pass 121 122 class Value(_StructureWrapper): 123 pass 124 125 class Data(_StructureWrapper): 126 pass 127 128 class Security(_StructureWrapper): 129 pass 95 130 96 131 class Hive(): … … 126 161 return HiveIterator(self) 127 162 163 def subtree(self, path): 164 hi = HiveIterator(self) 165 hi.descend(path) 166 return hi 167 128 168 129 169 class HiveIterator(): 130 170 hive = None 131 171 iter = None 132 root_traversed = False172 iteration_root = None 133 173 134 174 def __init__(self, hive): … … 147 187 148 188 def __iter__(self): 189 self.iteration_root = None 149 190 return self 150 191 151 192 def __next__(self): 152 if self.root_traversed: 153 self.root_traversed = True 154 193 if self.iteration_root == None: 194 self.iteration_root = self.current_key() 155 195 elif not regfi.regfi_iterator_down(self.iter): 156 196 up_ret = regfi.regfi_iterator_up(self.iter) 157 while up_ret and not regfi.regfi_iterator_next_subkey(self.iter): 197 while (up_ret and 198 not regfi.regfi_iterator_next_subkey(self.iter)): 199 if self.iteration_root == self.current_key(): 200 self.iteration_root = None 201 raise StopIteration('') 158 202 up_ret = regfi.regfi_iterator_up(self.iter) 159 203 … … 166 210 167 211 regfi.regfi_iterator_first_subkey(self.iter) 168 print(regfi.regfi_iterator_cur_key(self.iter).contents.keyname) 169 return regfi.regfi_iterator_cur_key(self.iter) 170 212 return self.current_key() 213 214 def down(self): 215 pass 216 217 def up(self): 218 pass 219 220 def descend(self, path): 221 #set up generator 222 cpath = (bytes(p,'ascii') for p in path) 223 224 # evaluate generator and create char* array 225 apath = (c_char_p*len(path))(*cpath) 226 227 if not regfi.regfi_iterator_walk_path(self.iter,apath): 228 raise Exception('Could not locate path.\n'+GetLogMessages()) 229 230 def current_key(self): 231 return Key(regfi.regfi_iterator_cur_key(self.iter)) -
trunk/python/pyregfi/structures.py
r205 r206 83 83 REGFI_VK._fields_ = [('offset', c_uint32), 84 84 ('cell_size', c_uint32), 85 (' valuename', c_char_p),86 (' valuename_raw', POINTER(c_char)),85 ('name', c_char_p), 86 ('name_raw', POINTER(c_char)), 87 87 ('name_length', c_uint16), 88 88 ('hbin_off', c_uint32), … … 119 119 ('name_length', c_uint16), 120 120 ('classname_length', c_uint16), 121 (' keyname', c_char_p),122 (' keyname_raw', POINTER(c_char)),121 ('name', c_char_p), 122 ('name_raw', POINTER(c_char)), 123 123 ('parent_off', c_uint32), 124 124 ('classname_off', c_uint32),
Note: See TracChangeset
for help on using the changeset viewer.