Changeset 213 for trunk/python


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/python/pyregfi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.