From 237120312aaf590cb7b652ef015333cbf7755352 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Fri, 1 Mar 2024 10:14:21 +0100 Subject: [PATCH] Applied updates for dfWinReg (#101) --- .github/workflows/test_docker.yml | 2 +- config/dpkg/control | 2 +- dependencies.ini | 2 +- dfimagetools/windows_registry.py | 103 ++++++------------------------ requirements.txt | 2 +- setup.cfg | 4 +- 6 files changed, 27 insertions(+), 88 deletions(-) diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 16f5aee..9fe405b 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: ['38'] + version: ['39'] container: image: registry.fedoraproject.org/fedora:${{ matrix.version }} steps: diff --git a/config/dpkg/control b/config/dpkg/control index 39dbdf0..5616ad3 100644 --- a/config/dpkg/control +++ b/config/dpkg/control @@ -9,7 +9,7 @@ Homepage: https://github.com/log2timeline/dfimagetools Package: python3-dfimagetools Architecture: all -Depends: libbde-python3 (>= 20220121), libcaes-python3 (>= 20240114), libcreg-python3 (>= 20200725), libewf-python3 (>= 20131210), libfcrypto-python3 (>= 20240114), libfsapfs-python3 (>= 20220709), libfsext-python3 (>= 20220829), libfsfat-python3 (>= 20220925), libfshfs-python3 (>= 20220831), libfsntfs-python3 (>= 20211229), libfsxfs-python3 (>= 20220829), libfvde-python3 (>= 20220121), libfwnt-python3 (>= 20210717), libluksde-python3 (>= 20220121), libmodi-python3 (>= 20210405), libphdi-python3 (>= 20220228), libqcow-python3 (>= 20201213), libregf-python3 (>= 20201002), libsigscan-python3 (>= 20230109), libsmdev-python3 (>= 20140529), libsmraw-python3 (>= 20140612), libvhdi-python3 (>= 20201014), libvmdk-python3 (>= 20140421), libvsapm-python3 (>= 20230506), libvsgpt-python3 (>= 20211115), libvshadow-python3 (>= 20160109), libvslvm-python3 (>= 20160109), python3-artifacts (>= 20220219), python3-cffi-backend (>= 1.9.1), python3-dfdatetime (>= 20221112), python3-dfvfs (>= 20240115), python3-dfwinreg (>= 20211207), python3-dtfabric (>= 20230518), python3-idna (>= 2.5), python3-pytsk3 (>= 20210419), python3-xattr (>= 0.7.2), python3-yaml (>= 3.10), ${misc:Depends} +Depends: libbde-python3 (>= 20220121), libcaes-python3 (>= 20240114), libcreg-python3 (>= 20200725), libewf-python3 (>= 20131210), libfcrypto-python3 (>= 20240114), libfsapfs-python3 (>= 20220709), libfsext-python3 (>= 20220829), libfsfat-python3 (>= 20220925), libfshfs-python3 (>= 20220831), libfsntfs-python3 (>= 20211229), libfsxfs-python3 (>= 20220829), libfvde-python3 (>= 20220121), libfwnt-python3 (>= 20210717), libluksde-python3 (>= 20220121), libmodi-python3 (>= 20210405), libphdi-python3 (>= 20220228), libqcow-python3 (>= 20201213), libregf-python3 (>= 20201002), libsigscan-python3 (>= 20230109), libsmdev-python3 (>= 20140529), libsmraw-python3 (>= 20140612), libvhdi-python3 (>= 20201014), libvmdk-python3 (>= 20140421), libvsapm-python3 (>= 20230506), libvsgpt-python3 (>= 20211115), libvshadow-python3 (>= 20160109), libvslvm-python3 (>= 20160109), python3-artifacts (>= 20220219), python3-cffi-backend (>= 1.9.1), python3-dfdatetime (>= 20221112), python3-dfvfs (>= 20240115), python3-dfwinreg (>= 20240229), python3-dtfabric (>= 20230518), python3-idna (>= 2.5), python3-pytsk3 (>= 20210419), python3-xattr (>= 0.7.2), python3-yaml (>= 3.10), ${misc:Depends} Description: Python 3 module of dfImageTools Collection of tools to process storage media images. diff --git a/dependencies.ini b/dependencies.ini index af67f47..3d9e898 100644 --- a/dependencies.ini +++ b/dependencies.ini @@ -25,7 +25,7 @@ version_property: __version__ [dfwinreg] dpkg_name: python3-dfwinreg -minimum_version: 20211207 +minimum_version: 20240229 rpm_name: python3-dfwinreg version_property: __version__ diff --git a/dfimagetools/windows_registry.py b/dfimagetools/windows_registry.py index 394fd87..370736e 100644 --- a/dfimagetools/windows_registry.py +++ b/dfimagetools/windows_registry.py @@ -14,95 +14,28 @@ from dfimagetools import environment_variables -class WindowsRegistryFile(dfwinreg_interface.WinRegistryFile): - """Windows Registry file. - - This class manages a Windows Registry file-like object. - """ - - def __init__(self, ascii_codepage='cp1252', key_path_prefix=''): - """Initializes a Windows Registry file. - - Args: - ascii_codepage (Optional[str]): ASCII string codepage. - key_path_prefix (Optional[str]): Windows Registry key path prefix. - """ - super(WindowsRegistryFile, self).__init__() - self._file_object = None - self._registry_file = None +class CREGWindowsRegistryFile(dfwinreg_creg.CREGWinRegistryFile): + """Windows 9x/Me Registry file (CREG).""" def Close(self): """Closes the Windows Registry file.""" - self._registry_file.Close() - self._registry_file = None + self._creg_file.close() if not isinstance(self._file_object, dfvfs_file_io.FileIO): self._file_object.close() self._file_object = None - def GetKeyByPath(self, key_path): - """Retrieves the key for a specific path. - - Args: - key_path (str): Windows Registry key path. - - Returns: - WinRegistryKey: Windows Registry key or None if not available. - """ - return self._registry_file.GetKeyByPath(key_path) - - def GetRootKey(self): - """Retrieves the root key. - - Returns: - WinRegistryKey: Windows Registry root key or None if not available. - """ - return self._registry_file.GetRootKey() - - def Open(self, file_object): - """Opens the Windows Registry file using a file-like object. - - Args: - file_object (file): file-like object. - - Raises: - IOError: if the Windows Registry file cannot be opened. - OSError: if the Windows Registry file cannot be opened. - """ - try: - registry_file = dfwinreg_regf.REGFWinRegistryFile( - ascii_codepage=self._ascii_codepage, - key_path_prefix=self._key_path_prefix) - - registry_file.Open(file_object) - - except IOError: - registry_file = None - - if not registry_file: - try: - registry_file = dfwinreg_creg.CREGWinRegistryFile( - ascii_codepage=self._ascii_codepage, - key_path_prefix=self._key_path_prefix) - - except IOError: - registry_file = None - if not registry_file: - raise IOError('Unable to open Windows Registry file.') +class REGFWindowsRegistryFile(dfwinreg_regf.REGFWinRegistryFile): + """Windows NT Registry file (REGF).""" - self._file_object = file_object - self._registry_file = registry_file - - def SetKeyPathPrefix(self, key_path_prefix): - """Sets the Window Registry key path prefix. + def Close(self): + """Closes the Windows Registry file.""" + self._regf_file.close() - Args: - key_path_prefix (str): Windows Registry key path prefix. - """ - super(WindowsRegistryFile, self).SetKeyPathPrefix(key_path_prefix) - if self._registry_file: - self._registry_file.SetKeyPathPrefix(key_path_prefix) + if not isinstance(self._file_object, dfvfs_file_io.FileIO): + self._file_object.close() + self._file_object = None class StorageMediaImageWindowsRegistryFileReader( @@ -131,7 +64,7 @@ def Open(self, path, ascii_codepage='cp1252'): ascii_codepage (Optional[str]): ASCII string codepage. Returns: - WinRegistryFile: Windows Registry file or None if the file cannot + dfwinreg.WinRegistryFile: Windows Registry file or None if the file cannot be opened. """ path_spec = self._path_resolver.ResolvePath(path) @@ -142,11 +75,17 @@ def Open(self, path, ascii_codepage='cp1252'): if file_object is None: return None - registry_file = WindowsRegistryFile(ascii_codepage=ascii_codepage) - try: + signature = file_object.read(4) + + if signature == b'regf': + registry_file = REGFWindowsRegistryFile(ascii_codepage=ascii_codepage) + else: + registry_file = CREGWindowsRegistryFile(ascii_codepage=ascii_codepage) + + # Note that registry_file takes over management of file_object. registry_file.Open(file_object) - # Note that WindowsRegistryFile takes over management of file_object. + except IOError: file_object.close() return None diff --git a/requirements.txt b/requirements.txt index be26533..f19a8eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ artifacts >= 20220219 cffi >= 1.9.1 dfdatetime >= 20221112 dfvfs >= 20240115 -dfwinreg >= 20211207 +dfwinreg >= 20240229 dtfabric >= 20230518 libbde-python >= 20220121 libcaes-python >= 20240114 diff --git a/setup.cfg b/setup.cfg index 8048d85..4d963fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = dfimagetools -version = 20240211 +version = 20240229 description = Storage media image tools long_description = Collection of tools to process storage media images. long_description_content_type = text/plain @@ -89,7 +89,7 @@ requires = python3-cffi >= 1.9.1 python3-dfdatetime >= 20221112 python3-dfvfs >= 20240115 - python3-dfwinreg >= 20211207 + python3-dfwinreg >= 20240229 python3-dtfabric >= 20230518 python3-idna >= 2.5 python3-pytsk3 >= 20210419