Skip to content

Commit 4fa9e89

Browse files
committed
Compatibility with cstruct v4
1 parent ac1c890 commit 4fa9e89

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

dissect/squashfs/c_squashfs.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import stat
22

3-
from dissect import cstruct
3+
from dissect.cstruct import cstruct
44

55
squashfs_def = """
66
#define SQUASHFS_MAGIC 0x73717368
@@ -319,8 +319,7 @@
319319
};
320320
"""
321321

322-
c_squashfs = cstruct.cstruct()
323-
c_squashfs.load(squashfs_def)
322+
c_squashfs = cstruct().load(squashfs_def)
324323

325324
INODE_STRUCT_MAP = {
326325
c_squashfs.SQUASHFS_DIR_TYPE: c_squashfs.squashfs_dir_inode_header,

dissect/squashfs/squashfs.py

+40-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from functools import cache, cached_property, lru_cache
1212
from typing import BinaryIO, Iterator, Optional, Union
1313

14-
from dissect.cstruct import Instance
1514
from dissect.util import ts
1615
from dissect.util.stream import RunlistStream
1716

@@ -213,7 +212,27 @@ def __init__(
213212
def __repr__(self) -> str:
214213
return f"<inode {self.inode_number} ({self.block}, {self.offset})>"
215214

216-
def _metadata(self) -> tuple[Instance, int, int]:
215+
def _metadata(
216+
self,
217+
) -> tuple[
218+
c_squashfs.squashfs_base_inode_header
219+
| c_squashfs.squashfs_dir_inode_header
220+
| c_squashfs.squashfs_reg_inode_header
221+
| c_squashfs.squashfs_symlink_inode_header
222+
| c_squashfs.squashfs_dev_inode_header
223+
| c_squashfs.squashfs_dev_inode_header
224+
| c_squashfs.squashfs_base_inode_header
225+
| c_squashfs.squashfs_base_inode_header
226+
| c_squashfs.squashfs_ldir_inode_header
227+
| c_squashfs.squashfs_lreg_inode_header
228+
| c_squashfs.squashfs_symlink_inode_header
229+
| c_squashfs.squashfs_ldev_inode_header
230+
| c_squashfs.squashfs_ldev_inode_header
231+
| c_squashfs.squashfs_lipc_inode_header
232+
| c_squashfs.squashfs_lipc_inode_header,
233+
int,
234+
int,
235+
]:
217236
base_struct = c_squashfs.squashfs_base_inode_header
218237

219238
block = self.fs.sb.inode_table_start + self.block
@@ -235,7 +254,25 @@ def _metadata(self) -> tuple[Instance, int, int]:
235254
return header, data_block, data_offset
236255

237256
@cached_property
238-
def header(self) -> Instance:
257+
def header(
258+
self,
259+
) -> (
260+
c_squashfs.squashfs_base_inode_header
261+
| c_squashfs.squashfs_dir_inode_header
262+
| c_squashfs.squashfs_reg_inode_header
263+
| c_squashfs.squashfs_symlink_inode_header
264+
| c_squashfs.squashfs_dev_inode_header
265+
| c_squashfs.squashfs_dev_inode_header
266+
| c_squashfs.squashfs_base_inode_header
267+
| c_squashfs.squashfs_base_inode_header
268+
| c_squashfs.squashfs_ldir_inode_header
269+
| c_squashfs.squashfs_lreg_inode_header
270+
| c_squashfs.squashfs_symlink_inode_header
271+
| c_squashfs.squashfs_ldev_inode_header
272+
| c_squashfs.squashfs_ldev_inode_header
273+
| c_squashfs.squashfs_lipc_inode_header
274+
| c_squashfs.squashfs_lipc_inode_header
275+
):
239276
header, _, _ = self._metadata()
240277
return header
241278

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ classifiers = [
2525
"Topic :: Utilities",
2626
]
2727
dependencies = [
28-
"dissect.cstruct>=3.0.dev,<4.0.dev",
29-
"dissect.util>=3.0.dev,<4.0.dev",
28+
"dissect.cstruct>3,<5",
29+
"dissect.util>2,<4",
3030
]
3131
dynamic = ["version"]
3232

tox.ini

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ minversion = 4.4.3
1111
requires = virtualenv>=20.16.6
1212

1313
[testenv]
14-
extras = full
1514
deps =
1615
pytest
1716
pytest-cov
1817
coverage
18+
# Unfortunately, tox does not allow separate installation flags for the project
19+
# dependencies and the test dependencies. When running tox, we want to install the
20+
# project dependencies with the --pre flag, so that we get the latest version of all
21+
# dependencies. We do the installation step ourselves for this reason.
22+
skip_install = true
23+
commands_pre =
24+
pip install --pre -e .[full]
1925
commands =
2026
pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests}
2127
coverage report

0 commit comments

Comments
 (0)