Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 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>3,<5",
"dissect.util>2,<4",
]
dynamic = ["version"]

Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down