source: trunk/python/pyregfi/__init__.py @ 204

Last change on this file since 204 was 204, checked in by tim, 14 years ago

reorganizing wrappers

File size: 1.3 KB
Line 
1#!/usr/bin/env python
2
3import sys
4from pyregfi.structures import *
5
6import ctypes
7import ctypes.util
8from ctypes import c_char,c_char_p,c_int,POINTER
9
10regfi = ctypes.CDLL(ctypes.util.find_library('regfi'), use_errno=True)
11
12
13regfi.regfi_alloc.argtypes = [c_int]
14regfi.regfi_alloc.restype = POINTER(REGFI_FILE)
15
16regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE)]
17regfi.regfi_alloc_cb.restype = POINTER(REGFI_FILE)
18
19regfi.regfi_log_get_str.argtypes = []
20regfi.regfi_log_get_str.restype = c_char_p
21
22regfi.regfi_init.argtypes = []
23regfi.regfi_init.restype = None
24regfi.regfi_init()
25
26
27class Hive(ctypes.Structure):
28   
29    file = None
30    raw_file = None
31   
32    def __init__(self, fh):
33       
34        if hasattr(fh, 'fileno') and 1==0:
35            self.file = regfi.regfi_alloc(fh.fileno())
36        else:
37            self.raw_file = structures.REGFI_RAW_FILE()
38            self.raw_file.fh = fh
39            self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek)
40            self.raw_file.read = read_cb_type(self.raw_file.cb_read)
41            self.file = regfi.regfi_alloc_cb(self.raw_file)
42            print(regfi.regfi_log_get_str())
43
44    def __getattr__(self, name):
45        return getattr(self.file.contents, name)
46
47    def test(self):
48        print(self.magic)
49        print(self.sequence1)
50        print(self.sequence2)
51
Note: See TracBrowser for help on using the repository browser.