Changeset 207 for trunk/python
- Timestamp:
- 09/06/10 23:03:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/pyregfi/__init__.py
r206 r207 6 6 import ctypes 7 7 import ctypes.util 8 from ctypes import c_char,c_char_p,c_int,c_uint16,c_ bool,POINTER8 from ctypes import c_char,c_char_p,c_int,c_uint16,c_uint32,c_bool,POINTER 9 9 10 10 regfi = ctypes.CDLL(ctypes.util.find_library('regfi'), use_errno=True) … … 29 29 regfi.regfi_free_record.restype = None 30 30 31 regfi.regfi_fetch_num_subkeys.argtypes = [POINTER(REGFI_NK)] 32 regfi.regfi_fetch_num_subkeys.restype = c_uint32 33 34 regfi.regfi_fetch_num_values.argtypes = [POINTER(REGFI_NK)] 35 regfi.regfi_fetch_num_values.restype = c_uint32 36 31 37 regfi.regfi_fetch_classname.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)] 32 38 regfi.regfi_fetch_classname.restype = POINTER(REGFI_CLASSNAME) … … 38 44 regfi.regfi_fetch_data.restype = POINTER(REGFI_DATA) 39 45 46 regfi.regfi_find_subkey.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK), 47 c_char_p, POINTER(c_uint32)] 48 regfi.regfi_find_subkey.restype = c_bool 49 50 regfi.regfi_find_value.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK), 51 c_char_p, POINTER(c_uint32)] 52 regfi.regfi_find_value.restype = c_bool 53 54 regfi.regfi_get_subkey.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK), 55 c_uint32] 56 regfi.regfi_get_subkey.restype = POINTER(REGFI_NK) 57 58 regfi.regfi_get_value.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK), 59 c_uint32] 60 regfi.regfi_get_value.restype = POINTER(REGFI_VK) 61 40 62 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING] 41 63 regfi.regfi_iterator_new.restype = POINTER(REGFI_ITERATOR) … … 83 105 regfi.regfi_iterator_find_value.restype = c_bool 84 106 107 108 109 regfi.regfi_get_value 85 110 86 111 regfi.regfi_init.argtypes = [] … … 93 118 if msgs == None: 94 119 return '' 95 return msgs 120 return msgs.decode('ascii') 96 121 97 122 98 123 class _StructureWrapper(): 99 124 "Handles memory management and proxies attribute access to base structures" 125 hive = None 100 126 base = None 101 127 102 def __init__(self, base): 128 def __init__(self, hive, base): 129 self.hive = hive 103 130 # XXX: check for NULL here, throw an exception if so. 104 131 self.base = base … … 117 144 118 145 119 class Key(_StructureWrapper):120 pass121 122 146 class Value(_StructureWrapper): 123 147 pass 124 148 149 125 150 class Data(_StructureWrapper): 126 151 pass 127 152 153 128 154 class Security(_StructureWrapper): 129 155 pass 156 157 158 class _ValueList(): 159 hive = None 160 key = None 161 length = None 162 current = None 163 164 def __init__(self, key): 165 self.hive = key.hive 166 # XXX: check for NULL here, throw an exception if so. 167 self.key = key 168 self.length = regfi.regfi_fetch_num_values(key.base) 169 170 def __len__(self): 171 return self.length 172 173 def __getitem__(self, name): 174 index = c_uint32() 175 # XXX: need to do any funky unicode conversions on name? 176 if regfi.regfi_find_value(self.hive.file, self.key.base, 177 create_string_buffer(name), byref(index)): 178 return Value(hive, 179 regfi.regfi_get_value(hive.file, key.base, index)) 180 raise KeyError('') 181 182 def __iter__(self): 183 self.current = 0 184 return self 185 186 def __next__(self): 187 if self.current >= self.length: 188 raise StopIteration('') 189 190 vk = regfi.regfi_get_value(self.hive.file, self.key.base, 191 c_uint32(self.current)) 192 self.current += 1 193 return vk.contents 194 195 196 class Key(_StructureWrapper): 197 values = None 198 199 def __init__(self, hive, base): 200 super(Key, self).__init__(hive, base) 201 self.values = _ValueList(self) 202 203 def fetch_security(self): 204 return Security(self.hive, 205 regfi.regfi_fetch_sk(self.hive.file, self.base)) 206 130 207 131 208 class Hive(): … … 229 306 230 307 def current_key(self): 231 return Key( regfi.regfi_iterator_cur_key(self.iter))308 return Key(self.hive, regfi.regfi_iterator_cur_key(self.iter))
Note: See TracChangeset
for help on using the changeset viewer.