Changeset 252


Ignore:
Timestamp:
05/08/11 13:33:49 (13 years ago)
Author:
tim
Message:

updated pyregfi to work with regfi changes
renamed some functions for more clarity
fixed some issues related to talloc_reference

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r232 r252  
    4242
    4343
    44 # helper function
     44# walks up parents to obtain path, rather than using downward links like iterator
    4545def getCurrentPath(key):
    4646    if key == None:
     
    7171                i += 1
    7272        except Exception as e:
    73             print("WARNING: Could not decend to path '%s'.\nError:\n %s\n%s" % (path,e.args,e))
     73            print("WARNING: Could not descend to path '%s'.\nError:\n %s\n%s" % (path,e.args,e))
    7474    print("   Successfully tested paths on %d keys." % i)
    7575
     
    162162    iter = pyregfi.HiveIterator(hive)
    163163    for k in iter:
    164         path = getCurrentPath(k)
     164        path = iter.current_path()
    165165        try:
    166             hive_iter = hive.subtree(path)
     166            hive_iter = hive.subtree(path[1:])
    167167            sk = hive_iter.first_subkey()
    168168            while sk != None:
    169169                ssk = hive_iter.find_subkey(sk.name)
    170                 sk_stat += len(ssk.name)
     170                if ssk != None:
     171                    sk_stat += len(ssk.name)
     172                else:
     173                    print("WARNING: ssk was None")
    171174                sk = hive_iter.next_subkey()
    172175
     
    174177            while v != None:
    175178                vv = hive_iter.find_value(v.name)
    176                 v_stat += len(vv.name)
     179                if vv != None:
     180                    v_stat += len(vv.name)
     181                else:
     182                    print("WARNING: vv was None")
    177183                v = hive_iter.next_value()
    178184
    179185        except Exception as e:
    180             print("WARNING: Could not decend to path '%s'.\nError:\n %s\n%s" % (path,e.args,e))
     186            print("WARNING: Could not descend to path '%s'.\nError:\n %s\n%s" % (path[1:],e.args,e))
    181187    print("   Subkey stat: %f" % sk_stat)
    182188    print("   Value stat: %f" % v_stat)
  • trunk/include/regfi.h

    r251 r252  
    10131013 * Adds an extra internal reference to specified record, making it necessary to
    10141014 * call regfi_free_record on it an additional time before it is freed.  This is
    1015  * useful in cases where multiple threads/structures need access to a record,
     1015 * useful in cases where multiple threads/structures need access to a shared record,
    10161016 * without requiring them to be in sync with when it is freed.
    10171017 *
     
    10221022 *        REGFI_SK, REGFI_DATA, and REGFI_CLASSNAME records.
    10231023 *
    1024  * @return true on success, false otherwise
    1025  *
    1026  * @ingroup regfiBase
    1027  */
    1028 _EXPORT()
    1029 bool regfi_reference_record(REGFI_FILE* file, const void* record);
     1024 * @return Updated record pointer on success, NULL otherwise
     1025 *
     1026 * @note Be sure to use the returned record for further access to the structure
     1027 *       instead of the previous version of the pointer.  E.g.:
     1028 *       @code
     1029 *       myKey = (const REGFI_NK*)regfi_reference_record(myFile, myKey);
     1030 *       @endcode
     1031 *
     1032 * @ingroup regfiBase
     1033 */
     1034_EXPORT()
     1035const void* regfi_reference_record(REGFI_FILE* file, const void* record);
    10301036
    10311037
     
    12891295 */
    12901296_EXPORT()
    1291 bool regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path);
     1297bool regfi_iterator_descend(REGFI_ITERATOR* i, const char** path);
    12921298
    12931299
     
    14131419
    14141420
    1415 /** Returns the full path where the iterator is currently located as a list
    1416  *  of NK records
     1421/** Returns the current key and all parent keys as a list of NK records
    14171422 *
    14181423 * @param i     the iterator
     
    14201425 * @return An array of NK record pointers terminated by a NULL pointer. 
    14211426 *         This array may be passed directly to regfi_free_record to free
    1422  *         the entire array. 
     1427 *         the entire array.
    14231428 *
    14241429 * @note In order to use an element of the array independently from the
     
    14301435 */
    14311436_EXPORT()
    1432 const REGFI_NK** regfi_iterator_cur_path(REGFI_ITERATOR* i);
     1437const REGFI_NK** regfi_iterator_ancestry(REGFI_ITERATOR* i);
    14331438
    14341439
  • trunk/lib/lru_cache.c

    r250 r252  
    260260    ht->table[hash] = e;
    261261  }
     262  if(ht->talloc_data)
     263    data = talloc_reference(e, data);
    262264  e->data = data;
    263   if(ht->talloc_data)
    264     talloc_reference(e, e->data);
    265265
    266266  /* Finally, let's insert the element to the newest position in the LRU list.*/
  • trunk/lib/regfi.c

    r251 r252  
    17991799/******************************************************************************
    18001800 *****************************************************************************/
    1801 bool regfi_reference_record(REGFI_FILE* file, const void* record)
    1802 {
    1803   bool ret_val = false;
     1801const void* regfi_reference_record(REGFI_FILE* file, const void* record)
     1802{
     1803  const void* ret_val = NULL;
     1804
    18041805  if(!regfi_lock(file, &file->mem_lock, "regfi_reference_record"))
    18051806    return ret_val;
    1806  
    1807   if(talloc_reference(NULL, record) != NULL)
    1808     ret_val = true;
     1807
     1808  ret_val = talloc_reference(NULL, record);
    18091809
    18101810  regfi_unlock(file, &file->mem_lock, "regfi_reference_record");
     
    19331933  if(subkey == NULL)
    19341934  {
    1935     regfi_log_add(REGFI_LOG_WARN, "Could not obtain cur_subkey during"
    1936                   " iterator_down with subkey index (%d) and key offset=%.8X\n",
    1937                   i->cur->cur_subkey, i->cur->offset);
    19381935    talloc_free(pos);
    19391936    return false;
     
    20262023/******************************************************************************
    20272024 *****************************************************************************/
    2028 bool regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path)
     2025bool regfi_iterator_descend(REGFI_ITERATOR* i, const char** path)
    20292026{
    20302027  uint32_t x;
     
    21752172/******************************************************************************
    21762173 *****************************************************************************/
    2177 const REGFI_NK** regfi_iterator_cur_path(REGFI_ITERATOR* i)
     2174const REGFI_NK** regfi_iterator_ancestry(REGFI_ITERATOR* i)
    21782175{
    21792176  REGFI_NK** ret_val;
     
    22032200  void_stack_iterator_free(iter);
    22042201
    2205   if(!regfi_lock(i->f, &i->f->mem_lock, "regfi_cur_path"))
     2202  if(!regfi_lock(i->f, &i->f->mem_lock, "regfi_iterator_ancestry"))
    22062203  {
    22072204    talloc_free(ret_val);
     
    22122209    talloc_reparent(NULL, ret_val, ret_val[k]);
    22132210
    2214   regfi_unlock(i->f, &i->f->mem_lock, "regfi_cur_path");
     2211  regfi_unlock(i->f, &i->f->mem_lock, "regfi_iterator_ancestry");
    22152212
    22162213  ret_val[k] = NULL;
  • trunk/python/pyregfi/__init__.py

    r233 r252  
    174174    i = 0
    175175    s = chars_pointer[i]
    176     while s != None:
     176    while s:
    177177        ret_val.append(s.decode('utf-8', 'replace'))
    178178        i += 1
     
    180180
    181181    return ret_val
     182
    182183
    183184
     
    316317            raise Exception("Could not create _GenericList; key is NULL."
    317318                            + "Current log:\n" + getLogMessages())
    318        
    319         if not regfi.regfi_reference_record(key._hive.file, key._base):
     319
     320        base = regfi.regfi_reference_record(key._hive.file, key._base)
     321        if not base:
    320322            raise Exception("Could not create _GenericList; memory error."
    321323                            + "Current log:\n" + getLogMessages())
    322         self._key_base = key._base
     324        self._key_base = cast(base, type(key._base))
    323325        self._length = self._fetch_num(self._key_base)
    324326        self._hive = key._hive
     
    461463            ret_val = super(Key, self).__getattr__(name)
    462464
    463             if ret_val == None:
     465            if not ret_val:
    464466                ret_val = self.name_raw
    465467            else:
     
    624626        ret_val = super(Value, self).__getattr__(name)
    625627        if name == "name":
    626             if ret_val == None:
     628            if not ret_val:
    627629                ret_val = self.name_raw
    628630            else:
     
    984986        return ret_val
    985987
    986 
    987988    ## Traverse downward multiple levels
    988989    #
     
    996997
    997998        self._lock.acquire()
    998         result = regfi.regfi_iterator_walk_path(self._iter, cpath)
     999        result = regfi.regfi_iterator_descend(self._iter, cpath)
    9991000        self._lock.release()
    10001001        if not result:
    10011002            # XXX: Use non-generic exception
    10021003            raise Exception('Could not locate path.\n'+getLogMessages())
     1004
     1005    ## Obtains a list of the current key's ancestry
     1006    #
     1007    # @return A list of all parent keys starting with the root Key and ending
     1008    #         with the current Key
     1009    def ancestry(self):
     1010        self._lock.acquire()
     1011        result = regfi.regfi_iterator_ancestry(self._iter)
     1012        self._lock.release()
     1013
     1014        ret_val = []
     1015        i = 0
     1016        k = result[i]
     1017        while k:
     1018            k = cast(regfi.regfi_reference_record(self._hive.file, k), POINTER(REGFI_NK))
     1019            ret_val.append(Key(self._hive, k))
     1020            i += 1
     1021            k = result[i]
     1022
     1023        regfi.regfi_free_record(self._hive.file, result)
     1024        return ret_val
     1025
     1026    ## Obtains the current path of the iterator
     1027    #
     1028    # @return A list of key names starting with the root up to and
     1029    #         including the current key
     1030    #
     1031    def current_path(self):
     1032        ancestry = self.ancestry()
     1033        return [str(a.name) for a in ancestry]
    10031034
    10041035
  • trunk/python/pyregfi/structures.py

    r233 r252  
    2020
    2121REGFI_DATA_TYPE = c_uint32
    22 
     22REGFI_NTTIME = c_uint64
    2323
    2424# Prototype everything first so we don't have to worry about reference order
    25 class REGFI_NTTIME(Structure):
    26     pass
    27 
    2825class REGFI_VK(Structure):
    2926    pass
     
    9794read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True)
    9895
    99 
    100 REGFI_NTTIME._fields_ = [('low', c_uint32),
    101                          ('high', c_uint32)]
    10296
    10397REGFI_VK._fields_ = [('offset', c_uint32),
     
    253247
    254248regfi.regfi_reference_record.argtypes = [POINTER(REGFI_FILE), c_void_p]
    255 regfi.regfi_reference_record.restype = c_bool
     249regfi.regfi_reference_record.restype = c_void_p
    256250
    257251regfi.regfi_fetch_num_subkeys.argtypes = [POINTER(REGFI_NK)]
     
    307301regfi.regfi_iterator_to_root.restype = c_bool
    308302
    309 regfi.regfi_iterator_walk_path.argtypes = [POINTER(REGFI_ITERATOR), POINTER(c_char_p)]
    310 regfi.regfi_iterator_walk_path.restype = c_bool
     303regfi.regfi_iterator_descend.argtypes = [POINTER(REGFI_ITERATOR), POINTER(c_char_p)]
     304regfi.regfi_iterator_descend.restype = c_bool
    311305
    312306regfi.regfi_iterator_cur_key.argtypes = [POINTER(REGFI_ITERATOR)]
     
    337331regfi.regfi_iterator_find_value.restype = c_bool
    338332
     333regfi.regfi_iterator_ancestry.argtypes = [POINTER(REGFI_ITERATOR)]
     334regfi.regfi_iterator_ancestry.restype = POINTER(POINTER(REGFI_NK))
    339335
    340336regfi.regfi_init.argtypes = []
  • trunk/src/reglookup.c

    r251 r252  
    227227  buf[0] = '\0';
    228228
    229   path = regfi_iterator_cur_path(i);
     229  path = regfi_iterator_ancestry(i);
    230230  if(path == NULL)
    231231  {
     
    381381
    382382  root = regfi_iterator_cur_key(iter);
    383   regfi_reference_record(iter->f, root);
    384   cur = root;
     383  cur = root = regfi_reference_record(iter->f, root);
    385384  regfi_iterator_first_subkey(iter);
    386385  sub = regfi_iterator_cur_subkey(iter);
     
    504503  }
    505504
    506   if(!regfi_iterator_walk_path(iter, tmp_path))
     505  if(!regfi_iterator_descend(iter, tmp_path))
    507506  {
    508507    printMsgs(iter->f);
Note: See TracChangeset for help on using the changeset viewer.