Changeset 213 for trunk


Ignore:
Timestamp:
03/25/11 11:48:27 (14 years ago)
Author:
tim
Message:

fixed some pyregfi parameter bugs
fixed some iterator memory management problems
updated smoketest script to use ctypes pyregfi

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r209 r213  
    17801780  }
    17811781  ret_val->cur_key = root;
    1782   talloc_reference(ret_val, root);
     1782  talloc_reparent(NULL, ret_val, root);
    17831783
    17841784  ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH);
     
    18341834    return false;
    18351835  }
    1836   talloc_reference(i, subkey);
     1836  talloc_reparent(NULL, i, subkey);
    18371837
    18381838  i->cur_key = subkey;
     
    19201920const REGFI_NK* regfi_iterator_cur_key(REGFI_ITERATOR* i)
    19211921{
    1922   /* XXX: do we need to add a NULL talloc reference here? */
     1922  talloc_reference(NULL, i->cur_key);
    19231923  return i->cur_key;
    19241924}
  • trunk/python/pyregfi/__init__.py

    r212 r213  
    1515
    1616
    17 regfi.regfi_alloc.argtypes = [c_int]
     17regfi.regfi_alloc.argtypes = [c_int, REGFI_ENCODING]
    1818regfi.regfi_alloc.restype = POINTER(REGFI_FILE)
    1919
    20 regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE)]
     20regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE), REGFI_ENCODING]
    2121regfi.regfi_alloc_cb.restype = POINTER(REGFI_FILE)
    2222
     
    140140    s = chars_pointer[i]
    141141    while s != None:
    142         ret_val.append(s.decode('utf-8'))
     142        ret_val.append(s.decode('utf-8', 'replace'))
    143143        i += 1
    144144        s = chars_pointer[i]
     
    150150#  access to base structures 
    151151class _StructureWrapper(object):
    152 
    153152    hive = None
    154153    base = None
     
    161160    def __del__(self):
    162161        regfi.regfi_free_record(self.base)
     162        hive = None
    163163
    164164    def __getattr__(self, name):
     
    205205        self.length = self.fetch_num(key.base)
    206206   
     207    def __del__(self):
     208        self.key = None
     209
    207210    def __len__(self):
    208211        return self.length
     
    274277                ret_val = self.name_raw
    275278            else:
    276                 ret_val = ret_val.decode('utf-8')
     279                ret_val = ret_val.decode('utf-8', 'replace')
    277280               
    278281        elif name == "name_raw":
     
    307310            elif data_struct.type in (REG_SZ, REG_EXPAND_SZ, REG_LINK):
    308311                # Unicode strings
    309                 ret_val = data_struct.interpreted.string.decode('utf-8')
     312                ret_val = data_struct.interpreted.string.decode('utf-8', 'replace')
    310313            elif data_struct.type in (REG_DWORD, REG_DWORD_BE):
    311314                # 32 bit integers
     
    343346                    ret_val = self.name_raw
    344347                else:
    345                     ret_val = ret_val.decode('utf-8')
     348                    ret_val = ret_val.decode('utf-8', 'replace')
    346349
    347350            elif name == "name_raw":
     
    370373        try:
    371374            if hasattr(fh, 'fileno'):
    372                 self.file = regfi.regfi_alloc(fh.fileno())
     375                self.file = regfi.regfi_alloc(fh.fileno(), REGFI_ENCODING_UTF8)
    373376                return
    374377        except:
     
    379382        self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek)
    380383        self.raw_file.read = read_cb_type(self.raw_file.cb_read)
    381         self.file = regfi.regfi_alloc_cb(self.raw_file)
     384        self.file = regfi.regfi_alloc_cb(self.raw_file, REGFI_ENCODING_UTF8)
    382385
    383386    def __getattr__(self, name):
     
    387390        regfi.regfi_free(self.file)
    388391        if self.raw_file != None:
    389             regfi.regfi_free(self.file)
    390            
     392            self.raw_file = None
    391393
    392394    def __iter__(self):
     
    421423
    422424    def __init__(self, hive):
    423         # REGFI_ENCODING_UTF8==1
    424         self.iter = regfi.regfi_iterator_new(hive.file, 1)
     425        self.iter = regfi.regfi_iterator_new(hive.file, REGFI_ENCODING_UTF8)
    425426        if self.iter == None:
    426427            raise Exception("Could not create iterator.  Current log:\n"
     
    432433
    433434    def __del__(self):   
    434         regfi.regfi_iterator_free(self.iter)       
     435        regfi.regfi_iterator_free(self.iter)
    435436
    436437    def __iter__(self):
     
    440441    def __next__(self):
    441442        if self.iteration_root == None:
    442             self.iteration_root = self.current_key()           
     443            self.iteration_root = self.current_key()
    443444        elif not regfi.regfi_iterator_down(self.iter):
    444445            up_ret = regfi.regfi_iterator_up(self.iter)
  • trunk/python/pyregfi/structures.py

    r209 r213  
    1010# XXX: can we always be sure enums are this size?
    1111REGFI_ENCODING = c_uint32
     12REGFI_ENCODING_UTF8 = 1
     13
    1214REGFI_DATA_TYPE = c_uint32
    1315
  • trunk/src/reglookup.c

    r206 r213  
    406406      if(cur != root)
    407407      {
     408        regfi_free_record(cur);
    408409        /* We're done with this sub-tree, going up and hitting other branches. */
    409410        if(!regfi_iterator_up(iter))
     
    429430       * Let's move down and print this first sub-tree out.
    430431       */
     432      regfi_free_record(cur);
    431433      if(!regfi_iterator_down(iter))
    432434      {
     
    443445    printMsgs(iter->f);
    444446  } while(!((cur == root) && (sub == NULL)));
     447  regfi_free_record(root);
    445448
    446449  if(print_verbose)
Note: See TracChangeset for help on using the changeset viewer.