From 4fa9e892de7cc1c585a10ff31b25c0254d697fc7 Mon Sep 17 00:00:00 2001 From: Schamper <1254028+Schamper@users.noreply.github.com> Date: Fri, 24 May 2024 21:09:45 +0200 Subject: [PATCH 1/2] Compatibility with cstruct v4 --- dissect/squashfs/c_squashfs.py | 5 ++-- dissect/squashfs/squashfs.py | 43 +++++++++++++++++++++++++++++++--- pyproject.toml | 4 ++-- tox.ini | 8 ++++++- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/dissect/squashfs/c_squashfs.py b/dissect/squashfs/c_squashfs.py index 9578e1b..6a4a460 100644 --- a/dissect/squashfs/c_squashfs.py +++ b/dissect/squashfs/c_squashfs.py @@ -1,6 +1,6 @@ import stat -from dissect import cstruct +from dissect.cstruct import cstruct squashfs_def = """ #define SQUASHFS_MAGIC 0x73717368 @@ -319,8 +319,7 @@ }; """ -c_squashfs = cstruct.cstruct() -c_squashfs.load(squashfs_def) +c_squashfs = cstruct().load(squashfs_def) INODE_STRUCT_MAP = { c_squashfs.SQUASHFS_DIR_TYPE: c_squashfs.squashfs_dir_inode_header, diff --git a/dissect/squashfs/squashfs.py b/dissect/squashfs/squashfs.py index abced67..1653a45 100644 --- a/dissect/squashfs/squashfs.py +++ b/dissect/squashfs/squashfs.py @@ -11,7 +11,6 @@ from functools import cache, cached_property, lru_cache from typing import BinaryIO, Iterator, Optional, Union -from dissect.cstruct import Instance from dissect.util import ts from dissect.util.stream import RunlistStream @@ -213,7 +212,27 @@ def __init__( def __repr__(self) -> str: return f"" - def _metadata(self) -> tuple[Instance, int, int]: + def _metadata( + self, + ) -> tuple[ + c_squashfs.squashfs_base_inode_header + | c_squashfs.squashfs_dir_inode_header + | c_squashfs.squashfs_reg_inode_header + | c_squashfs.squashfs_symlink_inode_header + | c_squashfs.squashfs_dev_inode_header + | c_squashfs.squashfs_dev_inode_header + | c_squashfs.squashfs_base_inode_header + | c_squashfs.squashfs_base_inode_header + | c_squashfs.squashfs_ldir_inode_header + | c_squashfs.squashfs_lreg_inode_header + | c_squashfs.squashfs_symlink_inode_header + | c_squashfs.squashfs_ldev_inode_header + | c_squashfs.squashfs_ldev_inode_header + | c_squashfs.squashfs_lipc_inode_header + | c_squashfs.squashfs_lipc_inode_header, + int, + int, + ]: base_struct = c_squashfs.squashfs_base_inode_header block = self.fs.sb.inode_table_start + self.block @@ -235,7 +254,25 @@ def _metadata(self) -> tuple[Instance, int, int]: return header, data_block, data_offset @cached_property - def header(self) -> Instance: + def header( + self, + ) -> ( + c_squashfs.squashfs_base_inode_header + | c_squashfs.squashfs_dir_inode_header + | c_squashfs.squashfs_reg_inode_header + | c_squashfs.squashfs_symlink_inode_header + | c_squashfs.squashfs_dev_inode_header + | c_squashfs.squashfs_dev_inode_header + | c_squashfs.squashfs_base_inode_header + | c_squashfs.squashfs_base_inode_header + | c_squashfs.squashfs_ldir_inode_header + | c_squashfs.squashfs_lreg_inode_header + | c_squashfs.squashfs_symlink_inode_header + | c_squashfs.squashfs_ldev_inode_header + | c_squashfs.squashfs_ldev_inode_header + | c_squashfs.squashfs_lipc_inode_header + | c_squashfs.squashfs_lipc_inode_header + ): header, _, _ = self._metadata() return header diff --git a/pyproject.toml b/pyproject.toml index c732822..7a15acc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,8 +25,8 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "dissect.cstruct>=3.0.dev,<4.0.dev", - "dissect.util>=3.0.dev,<4.0.dev", + "dissect.cstruct>3,<5", + "dissect.util>2,<4", ] dynamic = ["version"] diff --git a/tox.ini b/tox.ini index 1fa283f..5bea6cd 100644 --- a/tox.ini +++ b/tox.ini @@ -11,11 +11,17 @@ minversion = 4.4.3 requires = virtualenv>=20.16.6 [testenv] -extras = full deps = pytest pytest-cov coverage +# Unfortunately, tox does not allow separate installation flags for the project +# dependencies and the test dependencies. When running tox, we want to install the +# project dependencies with the --pre flag, so that we get the latest version of all +# dependencies. We do the installation step ourselves for this reason. +skip_install = true +commands_pre = + pip install --pre -e .[full] commands = pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests} coverage report From 5bf3088de76a1cf433b80a881e9020766daccdca Mon Sep 17 00:00:00 2001 From: pyrco <105293448+pyrco@users.noreply.github.com> Date: Thu, 30 May 2024 14:24:28 +0200 Subject: [PATCH 2/2] Use a dev extra instead of installing with --pre --- pyproject.toml | 9 +++++++-- tox.ini | 8 +------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7a15acc..15fb466 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,8 +25,8 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "dissect.cstruct>3,<5", - "dissect.util>2,<4", + "dissect.cstruct>=4.dev,<5", + "dissect.util>=3,<4", ] dynamic = ["version"] @@ -43,6 +43,11 @@ full = [ "python-lzo; platform_system != 'Windows' or platform_python_implementation != 'PyPy'", "zstandard", ] +dev = [ + "dissect.squashfs[full]", + "dissect.cstruct>=4.0.dev,<5.0.dev", + "dissect.util>=3.0.dev,<4.0.dev", +] [tool.black] line-length = 120 diff --git a/tox.ini b/tox.ini index 5bea6cd..7bd2890 100644 --- a/tox.ini +++ b/tox.ini @@ -11,17 +11,11 @@ minversion = 4.4.3 requires = virtualenv>=20.16.6 [testenv] +extras = dev deps = pytest pytest-cov coverage -# Unfortunately, tox does not allow separate installation flags for the project -# dependencies and the test dependencies. When running tox, we want to install the -# project dependencies with the --pre flag, so that we get the latest version of all -# dependencies. We do the installation step ourselves for this reason. -skip_install = true -commands_pre = - pip install --pre -e .[full] commands = pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests} coverage report