Changeset 215 for trunk/python


Ignore:
Timestamp:
03/27/11 21:46:11 (14 years ago)
Author:
tim
Message:

improvements to smoketest script, additional test case
added a function to get a key's parent in both regfi and pyregfi
bug fixes

Location:
trunk/python/pyregfi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/pyregfi/__init__.py

    r214 r215  
    3131regfi.regfi_log_set_mask.restype = c_bool
    3232
     33regfi.regfi_get_rootkey.argtypes = [POINTER(REGFI_FILE)]
     34regfi.regfi_get_rootkey.restype = POINTER(REGFI_NK)
     35
    3336regfi.regfi_free_record.argtypes = [c_void_p]
    3437regfi.regfi_free_record.restype = None
     
    6467                                   c_uint32]
    6568regfi.regfi_get_value.restype = POINTER(REGFI_VK)
     69
     70regfi.regfi_get_parentkey.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)]
     71regfi.regfi_get_parentkey.restype = POINTER(REGFI_NK)
    6672
    6773regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING]
     
    122128    if msgs == None:
    123129        return ''
    124     return msgs.decode('ascii')
     130    return msgs.decode('utf-8')
    125131
    126132
     
    132138    for i in range(0,length):
    133139        ret_val[i] = char_pointer[i][0]
     140
     141    return ret_val
     142
     143
     144def _strlist2charss(str_list):
     145    ret_val = []
     146    for s in str_list:
     147        ret_val.append(s.encode('utf-8', 'replace'))
     148
     149    ret_val = (c_char_p*(len(str_list)+1))(*ret_val)
     150    # Terminate the char** with a NULL pointer
     151    ret_val[-1] = 0
    134152
    135153    return ret_val
     
    155173
    156174    def __init__(self, hive, base):
     175        if not hive:
     176            raise Exception("Could not create _StructureWrapper,"
     177                            + " hive is NULL.  Current log:\n"
     178                            + GetLogMessages())
     179        if not base:
     180            raise Exception("Could not create _StructureWrapper,"
     181                            + " base is NULL.  Current log:\n"
     182                            + GetLogMessages())
    157183        self._hive = hive
    158         # XXX: check for NULL here, throw an exception if so.
    159184        self._base = base
    160185
    161186    def __del__(self):
    162187        regfi.regfi_free_record(self._base)
    163         hive = None
    164188
    165189    def __getattr__(self, name):
     
    172196        return (not self.__eq__(other))
    173197
    174 ## Registry key
    175198class Key(_StructureWrapper):
    176199    pass
     
    248271
    249272        elem = self._get_element(self._hive.file, self._key._base,
    250                                 c_uint32(self._current))
     273                                 c_uint32(self._current))
    251274        self._current += 1
    252275        return self._constructor(self._hive, elem)
     
    268291
    269292
     293## Registry key
    270294class Key(_StructureWrapper):
    271295    values = None
     
    295319    def fetch_security(self):
    296320        return Security(self._hive,
    297                         regfi.regfi_fetch_sk(self._hive.file, self.base))
     321                        regfi.regfi_fetch_sk(self._hive.file, self._base))
     322
     323    def get_parent(self):
     324        parent_base = regfi.regfi_get_parentkey(self._hive.file, self._base)
     325        if parent_base:
     326            return Key(self._hive, parent_base)
     327
     328        return None
     329
     330    def is_root(self):
     331        # This is quicker than retrieving the root key for comparison and
     332        # is more trustworthy than trusting the key's flags.
     333        return ((self._hive.root_cell+REGFI_REGF_SIZE) == self.offset)
    298334
    299335
     
    402438        return HiveIterator(self)
    403439
     440    def get_root(self):
     441        return Key(self, regfi.regfi_get_rootkey(self.file))
     442
     443
    404444    ## Creates a @ref HiveIterator initialized at the specified path in
    405445    #  the hive.
     
    479519
    480520    def descend(self, path):
    481         #set up generator
    482         cpath = (bytes(p,'ascii') for p in path)
    483 
    484         # evaluate generator and create char* array
    485         apath = (c_char_p*len(path))(*cpath)
     521        cpath = _strlist2charss(path)
    486522
    487523        # XXX: Use non-generic exception
    488         if not regfi.regfi_iterator_walk_path(self.iter,apath):
     524        if not regfi.regfi_iterator_walk_path(self.iter, cpath):
    489525            raise Exception('Could not locate path.\n'+GetLogMessages())
    490526
  • trunk/python/pyregfi/structures.py

    r213 r215  
    1313
    1414REGFI_DATA_TYPE = c_uint32
     15REGFI_REGF_SIZE = 0x1000
    1516
    1617# Registry value data types
Note: See TracChangeset for help on using the changeset viewer.