Skip to content

Commit

Permalink
Compatibility with cstruct v4 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Jun 4, 2024
1 parent ac1c890 commit d84a056
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
5 changes: 2 additions & 3 deletions dissect/squashfs/c_squashfs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stat

from dissect import cstruct
from dissect.cstruct import cstruct

squashfs_def = """
#define SQUASHFS_MAGIC 0x73717368
Expand Down Expand Up @@ -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,
Expand Down
43 changes: 40 additions & 3 deletions dissect/squashfs/squashfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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
Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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>=4.dev,<5",
"dissect.util>=3,<4",
]
dynamic = ["version"]

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ minversion = 4.4.3
requires = virtualenv>=20.16.6

[testenv]
extras = full
extras = dev
deps =
pytest
pytest-cov
Expand Down

0 comments on commit d84a056

Please sign in to comment.