Skip to content

Commit

Permalink
Applied updates for dfWinReg
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Feb 29, 2024
1 parent 36b5904 commit 9e3163f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['38']
version: ['39']
container:
image: registry.fedoraproject.org/fedora:${{ matrix.version }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion config/dpkg/control
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion dependencies.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
103 changes: 21 additions & 82 deletions dfimagetools/windows_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e3163f

Please sign in to comment.