Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with cstruct v4 #24

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading