Changeset 226 for trunk/python/pyregfi
- Timestamp:
- 04/05/11 15:01:41 (14 years ago)
- Location:
- trunk/python/pyregfi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/pyregfi/__init__.py
r225 r226 177 177 def GetLogMessages(): 178 178 msgs = regfi.regfi_log_get_str() 179 if msgs == None:179 if not msgs: 180 180 return '' 181 181 return msgs.decode('utf-8') … … 625 625 # @note Supplied file must be seekable 626 626 def __init__(self, fh): 627 # The fileno method may not exist, or it may throw an exception 628 # when called if the file isn't backed with a descriptor. 629 fn = None 627 630 try: 628 # The fileno method may not exist, or it may throw an exception 629 # when called if the file isn't backed with a descriptor. 630 if hasattr(fh, 'fileno'): 631 self.file = regfi.regfi_alloc(fh.fileno(), REGFI_ENCODING_UTF8) 632 return 631 # XXX: Native calls to Windows filenos don't seem to work. 632 # Need to investigate why. 633 if not is_win32 and hasattr(fh, 'fileno'): 634 fn = fh.fileno() 633 635 except: 634 636 pass 635 636 fh.seek(0) 637 self.raw_file = structures.REGFI_RAW_FILE() 638 self.raw_file.fh = fh 639 self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek) 640 self.raw_file.read = read_cb_type(self.raw_file.cb_read) 641 self.file = regfi.regfi_alloc_cb(pointer(self.raw_file), REGFI_ENCODING_UTF8) 642 if not self.file: 643 # XXX: switch to non-generic exception 644 raise Exception("Could not open registry file. Current log:\n" 645 + GetLogMessages()) 637 638 if fn != None: 639 self.file = regfi.regfi_alloc(fn, REGFI_ENCODING_UTF8) 640 if not self.file: 641 # XXX: switch to non-generic exception 642 raise Exception("Could not open registry file. Current log:\n" 643 + GetLogMessages()) 644 else: 645 fh.seek(0) 646 self.raw_file = structures.REGFI_RAW_FILE() 647 self.raw_file.fh = fh 648 self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek) 649 self.raw_file.read = read_cb_type(self.raw_file.cb_read) 650 self.file = regfi.regfi_alloc_cb(pointer(self.raw_file), REGFI_ENCODING_UTF8) 651 if not self.file: 652 # XXX: switch to non-generic exception 653 raise Exception("Could not open registry file. Current log:\n" 654 + GetLogMessages()) 655 646 656 647 657 def __getattr__(self, name): … … 703 713 def __init__(self, hive): 704 714 self._iter = regfi.regfi_iterator_new(hive.file, REGFI_ENCODING_UTF8) 705 if self._iter == None:715 if not self._iter: 706 716 raise Exception("Could not create iterator. Current log:\n" 707 717 + GetLogMessages()) -
trunk/python/pyregfi/structures.py
r225 r226 13 13 from ctypes import * 14 14 15 is_win32 = hasattr(ctypes, 'windll') 15 16 16 17 # XXX: can we always be sure enums are this size? … … 61 62 except Exception: 62 63 traceback.print_exc() 63 # XXX: os.EX_IOERR may not be available on Windoze 64 set_errno(os.EX_IOERR) 64 set_errno(74) # os.EX_IOERR 65 65 return -1 66 66 … … 76 76 except Exception: 77 77 traceback.print_exc() 78 # XXX: os.EX_IOERR may not be available on Windoze 79 set_errno(os.EX_IOERR) 78 set_errno(74) # os.EX_IOERR 80 79 return -1 81 80 return len(tmp) … … 84 83 # Load libregfi according to platform 85 84 regfi = None 86 if hasattr(ctypes, 'windll'): 85 if is_win32: 86 # XXX: Using C calling conventions on cross-compiled DLLs seems to work fine 87 # on Windows, but I'm not sure if stdcall symbols are supported 88 # correctly for native Windows binaries... 87 89 #regfi = ctypes.windll.libregfi 88 regfi = ctypes.WinDLL('libregfi.dll', use_errno=True) 89 CB_FACTORY = ctypes.WINFUNCTYPE 90 #CB_FACTORY = ctypes.WINFUNCTYPE 91 regfi = ctypes.CDLL('libregfi.dll', use_errno=True) 92 CB_FACTORY = ctypes.CFUNCTYPE 90 93 else: 91 94 regfi = ctypes.CDLL(ctypes.util.find_library('regfi'), use_errno=True) 92 95 CB_FACTORY = ctypes.CFUNCTYPE 93 96 94 # XXX: how can we know for sure the size of off_t? 95 # -D_FILE_OFFSET_BITS=64 might help, need to research this 96 # Also, may need to use something like ctypes_configure 97 #seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True) 98 seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int) 99 #read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True) 100 read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t) 97 seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True) 98 read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True) 101 99 102 100
Note: See TracChangeset
for help on using the changeset viewer.