Changeset 228 for trunk/python
- Timestamp:
- 04/18/11 16:25:46 (14 years ago)
- Location:
- trunk/python/pyregfi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/pyregfi/__init__.py
r227 r228 95 95 import sys 96 96 import time 97 from pyregfi.structures import *98 99 97 import ctypes 100 98 import ctypes.util 99 import threading 100 from pyregfi.structures import * 101 101 102 102 103 ## An enumeration of registry Value data types … … 218 219 219 220 220 221 221 ## Abstract class for most objects returned by the library 222 222 class _StructureWrapper(object): … … 239 239 # Memory management for most regfi structures is taken care of here 240 240 def __del__(self): 241 regfi.regfi_free_record(self._ base)241 regfi.regfi_free_record(self._hive.file, self._base) 242 242 243 243 … … 299 299 + "Current log:\n" + GetLogMessages()) 300 300 301 if not regfi.regfi_reference_record(key._ base):301 if not regfi.regfi_reference_record(key._hive.file, key._base): 302 302 raise Exception("Could not create _GenericList; memory error." 303 303 + "Current log:\n" + GetLogMessages()) … … 308 308 309 309 def __del__(self): 310 regfi.regfi_free_record(self._ key_base)311 310 regfi.regfi_free_record(self._hive.file, self._key_base) 311 312 312 313 313 ## Length of list … … 486 486 ret_val = _buffer2bytearray(cn_struct.raw, 487 487 cn_struct.size) 488 regfi.regfi_free_record( cn_p)488 regfi.regfi_free_record(self._hive.file, cn_p) 489 489 490 490 return ret_val … … 581 581 data_struct.interpreted_size) 582 582 583 regfi.regfi_free_record( data_p)583 regfi.regfi_free_record(self._hive.file, data_p) 584 584 return ret_val 585 585 … … 599 599 ret_val = _buffer2bytearray(data_struct.raw, 600 600 data_struct.size) 601 regfi.regfi_free_record( data_p)601 regfi.regfi_free_record(self._hive.file, data_p) 602 602 return ret_val 603 603 … … 747 747 _iter = None 748 748 _iteration_root = None 749 _lock = None 749 750 750 751 def __init__(self, hive): 751 self._iter = regfi.regfi_iterator_new(hive.file , REGFI_ENCODING_UTF8)752 self._iter = regfi.regfi_iterator_new(hive.file) 752 753 if not self._iter: 753 754 raise Exception("Could not create iterator. Current log:\n" 754 755 + GetLogMessages()) 755 756 self._hive = hive 756 757 self._lock = threading.RLock() 758 757 759 def __getattr__(self, name): 758 return getattr(self.file.contents, name) 759 760 def __del__(self): 760 self._lock.acquire() 761 ret_val = getattr(self._iter.contents, name) 762 self._lock.release() 763 return ret_val 764 765 def __del__(self): 766 self._lock.acquire() 761 767 regfi.regfi_iterator_free(self._iter) 768 self._lock.release() 762 769 763 770 def __iter__(self): 771 self._lock.acquire() 764 772 self._iteration_root = None 773 self._lock.release() 765 774 return self 766 775 767 776 def __next__(self): 777 self._lock.acquire() 768 778 if self._iteration_root == None: 769 self._iteration_root = self.current_key() 779 self._iteration_root = self.current_key().offset 770 780 elif not regfi.regfi_iterator_down(self._iter): 771 781 up_ret = regfi.regfi_iterator_up(self._iter) 772 782 while (up_ret and 773 783 not regfi.regfi_iterator_next_subkey(self._iter)): 774 if self._iteration_root == self.current_key() :784 if self._iteration_root == self.current_key().offset: 775 785 self._iteration_root = None 786 self._lock.release() 776 787 raise StopIteration('') 777 788 up_ret = regfi.regfi_iterator_up(self._iter) … … 779 790 if not up_ret: 780 791 self._iteration_root = None 792 self._lock.release() 781 793 raise StopIteration('') 782 794 783 795 # XXX: Use non-generic exception 784 796 if not regfi.regfi_iterator_down(self._iter): 797 self._lock.release() 785 798 raise Exception('Error traversing iterator downward.'+ 786 799 ' Current log:\n'+ GetLogMessages()) 787 800 788 801 regfi.regfi_iterator_first_subkey(self._iter) 789 return self.current_key() 802 ret_val = self.current_key() 803 self._lock.release() 804 805 return ret_val 806 790 807 791 808 # For Python 2.x … … 806 823 # @return True if successful, False otherwise 807 824 def down(self, subkey_name=None): 825 ret_val = None 808 826 if subkey_name == None: 809 return regfi.regfi_iterator_down(self._iter) 827 self._lock.acquire() 828 ret_val = regfi.regfi_iterator_down(self._iter) 810 829 else: 811 830 if name != None: 812 831 name = name.encode('utf-8') 813 return (regfi.regfi_iterator_find_subkey(self._iter, name) 814 and regfi.regfi_iterator_down(self._iter)) 832 self._lock.acquire() 833 ret_val = (regfi.regfi_iterator_find_subkey(self._iter, name) 834 and regfi.regfi_iterator_down(self._iter)) 835 836 self._lock.release() 837 return ret_val 815 838 816 839 … … 824 847 # default selections. 825 848 def up(self): 826 return regfi.regfi_iterator_up(self._iter) 849 self._lock.acquire() 850 ret_val = regfi.regfi_iterator_up(self._iter) 851 self._lock.release() 852 return ret_val 827 853 828 854 … … 832 858 # None on error or if the current key has no subkeys. 833 859 def first_subkey(self): 860 ret_val = None 861 self._lock.acquire() 834 862 if regfi.regfi_iterator_first_subkey(self._iter): 835 return self.current_subkey() 836 return None 863 ret_val = self.current_subkey() 864 self._lock.release() 865 return ret_val 837 866 838 867 … … 842 871 # None on error or if the current key has no values. 843 872 def first_value(self): 873 ret_val = None 874 self._lock.acquire() 844 875 if regfi.regfi_iterator_first_value(self._iter): 845 return self.current_value() 846 return None 876 ret_val = self.current_value() 877 self._lock.release() 878 return ret_val 847 879 848 880 … … 852 884 # None if there are no remaining subkeys or an error occurred. 853 885 def next_subkey(self): 886 ret_val = None 887 self._lock.acquire() 854 888 if regfi.regfi_iterator_next_subkey(self._iter): 855 return self.current_subkey() 856 return None 889 ret_val = self.current_subkey() 890 self._lock.release() 891 return ret_val 857 892 858 893 … … 862 897 # None if there are no remaining values or an error occurred. 863 898 def next_value(self): 899 ret_val = None 900 self._lock.acquire() 864 901 if regfi.regfi_iterator_next_value(self._iter): 865 return self.current_value() 866 return None 902 ret_val = self.current_value() 903 self._lock.release() 904 return ret_val 867 905 868 906 … … 874 912 if name != None: 875 913 name = name.encode('utf-8') 914 ret_val = None 915 self._lock.acquire() 876 916 if regfi.regfi_iterator_find_subkey(self._iter, name): 877 return self.current_subkey() 878 return None 917 ret_val = self.current_subkey() 918 self._lock.release() 919 return ret_val 879 920 880 921 … … 886 927 if name != None: 887 928 name = name.encode('utf-8') 929 ret_val = None 930 self._lock.acquire() 888 931 if regfi.regfi_iterator_find_value(self._iter, name): 889 return self.current_value() 890 return None 932 ret_val = self.current_value() 933 self._lock.release() 934 return ret_val 891 935 892 936 ## Retrieves the currently selected subkey … … 894 938 # @return A Key instance of the current subkey 895 939 def current_subkey(self): 896 return Key(self._hive, regfi.regfi_iterator_cur_subkey(self._iter)) 940 self._lock.acquire() 941 ret_val = Key(self._hive, regfi.regfi_iterator_cur_subkey(self._iter)) 942 self._lock.release() 943 return ret_val 897 944 898 945 ## Retrieves the currently selected value … … 900 947 # @return A Value instance of the current value 901 948 def current_value(self): 902 return Value(self._hive, regfi.regfi_iterator_cur_value(self._iter)) 949 self._lock.acquire() 950 ret_val = Value(self._hive, regfi.regfi_iterator_cur_value(self._iter)) 951 self._lock.release() 952 return ret_val 903 953 904 954 ## Retrieves the current key … … 906 956 # @return A Key instance of the current position of the iterator 907 957 def current_key(self): 908 return Key(self._hive, regfi.regfi_iterator_cur_key(self._iter)) 958 self._lock.acquire() 959 ret_val = Key(self._hive, regfi.regfi_iterator_cur_key(self._iter)) 960 self._lock.release() 961 return ret_val 909 962 910 963 … … 919 972 cpath = _strlist2charss(path) 920 973 921 # XXX: Use non-generic exception 922 if not regfi.regfi_iterator_walk_path(self._iter, cpath): 974 self._lock.acquire() 975 result = regfi.regfi_iterator_walk_path(self._iter, cpath) 976 self._lock.release() 977 if not result: 978 # XXX: Use non-generic exception 923 979 raise Exception('Could not locate path.\n'+GetLogMessages()) 924 980 -
trunk/python/pyregfi/structures.py
r227 r228 171 171 REGFI_VALUE_LIST._fields_ = [('offset', c_uint32), 172 172 ('cell_size', c_uint32), 173 ('num_children', c_uint32),174 173 ('num_values', c_uint32), 175 174 ('elements', c_void_p), … … 247 246 regfi.regfi_get_rootkey.restype = POINTER(REGFI_NK) 248 247 249 regfi.regfi_free_record.argtypes = [ c_void_p]248 regfi.regfi_free_record.argtypes = [POINTER(REGFI_FILE), c_void_p] 250 249 regfi.regfi_free_record.restype = None 251 250 252 regfi.regfi_reference_record.argtypes = [ c_void_p]251 regfi.regfi_reference_record.argtypes = [POINTER(REGFI_FILE), c_void_p] 253 252 regfi.regfi_reference_record.restype = c_bool 254 253 … … 290 289 regfi.regfi_nt2unix_time.restype = c_double 291 290 292 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE) , REGFI_ENCODING]291 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE)] 293 292 regfi.regfi_iterator_new.restype = POINTER(REGFI_ITERATOR) 294 293 … … 305 304 regfi.regfi_iterator_to_root.restype = c_bool 306 305 307 regfi.regfi_iterator_walk_path.argtypes = [POINTER(REGFI_ITERATOR) ]306 regfi.regfi_iterator_walk_path.argtypes = [POINTER(REGFI_ITERATOR), POINTER(c_char_p)] 308 307 regfi.regfi_iterator_walk_path.restype = c_bool 309 308
Note: See TracChangeset
for help on using the changeset viewer.