dissect.cstruct 5.0.dev23__tar.gz → 5.0.dev24__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/CHANGELOG.md +1 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/PKG-INFO +1 -1
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/cstruct.py +21 -1
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/PKG-INFO +1 -1
- dissect_cstruct-5.0.dev24/dissect.cstruct.egg-info/scm_version.json +8 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_basic.py +30 -0
- dissect_cstruct-5.0.dev23/dissect.cstruct.egg-info/scm_version.json +0 -8
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/.git-blame-ignore-revs +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/.gitattributes +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/COPYRIGHT +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/LICENSE +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/MANIFEST.in +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/README.md +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/__init__.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/bitbuffer.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/compiler.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/declarative.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/dump.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/exception.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/expression.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/lexer.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/parser.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/tools/__init__.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/tools/stubgen.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/__init__.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/base.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/char.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/enum.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/flag.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/int.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/leb128.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/packed.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/pointer.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/structure.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/void.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/types/wchar.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect/cstruct/util.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/SOURCES.txt +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/entry_points.txt +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/requires.txt +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/scm_file_list.json +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/top_level.txt +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/examples/disk.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/examples/mirai.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/examples/pe.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/examples/protobuf.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/examples/secdesc.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/pyproject.toml +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/setup.cfg +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/__init__.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/_data/testdef.txt +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/_docs/Makefile +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/_docs/__init__.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/_docs/conf.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/_docs/index.rst +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/conftest.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_align.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_annotations.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_benchmark.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_bitbuffer.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_bitfield.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_compiler.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_ctypes.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_declarative.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_dump.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_exception.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_expression.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_lexer.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_parser.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_tools_stubgen.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_base.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_char.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_custom.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_enum.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_flag.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_int.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_leb128.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_packed.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_pointer.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_structure.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_union.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_void.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_types_wchar.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/test_util.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tests/util.py +0 -0
- {dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/tox.ini +0 -0
|
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
15
15
|
### Changed
|
|
16
16
|
|
|
17
17
|
- Optimize storage of field sizes.
|
|
18
|
+
- Setting the `endian` attribute of a `cstruct` instance accepts the same values as the `endian` argument, e.g. `cs.endian = "big"`, and raises a `ValueError` for an invalid value.
|
|
18
19
|
- Rename `_sizes` property of `Structure` to `__sizes__`.
|
|
19
20
|
- Rename `_values` property of `Structure` to `__values__`.
|
|
20
21
|
- Rename the `signed` attribute of integer and LEB128 types to `__signed__`, like the other attributes of types. The `signed` property is deprecated.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.dev24
|
|
4
4
|
Summary: A Dissect module implementing a parser for C-like structures: structure parsing in Python made easy
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -60,7 +60,7 @@ class cstruct:
|
|
|
60
60
|
DEF_LEGACY = 2
|
|
61
61
|
|
|
62
62
|
def __init__(self, load: str = "", *, endian: AllowedEndianness = "<", pointer: str | None = None):
|
|
63
|
-
self.endian =
|
|
63
|
+
self.endian = endian
|
|
64
64
|
|
|
65
65
|
self.consts: dict[str, int | str | bytes] = {}
|
|
66
66
|
self.types: dict[str, type[BaseType]] = {}
|
|
@@ -260,6 +260,17 @@ class cstruct:
|
|
|
260
260
|
|
|
261
261
|
return cs
|
|
262
262
|
|
|
263
|
+
# Hidden from type checkers, which otherwise accept assigning any attribute, e.g. a misspelled one
|
|
264
|
+
if not TYPE_CHECKING:
|
|
265
|
+
|
|
266
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
267
|
+
# Normalize ``endian`` when it's set, so ``cs.endian = "big"`` works like the ``endian`` argument.
|
|
268
|
+
# This is done in __setattr__ because ``cs.endian`` is read on every parse, so this keeps reading fast.
|
|
269
|
+
# All alternatives cause slowdowns when reading (property, descriptor)
|
|
270
|
+
if name == "endian":
|
|
271
|
+
value = normalize_endianness(value)
|
|
272
|
+
super().__setattr__(name, value)
|
|
273
|
+
|
|
263
274
|
def _next_anonymous(self) -> str:
|
|
264
275
|
name = f"__anonymous_{self._anonymous_count}__"
|
|
265
276
|
self._anonymous_count += 1
|
|
@@ -622,6 +633,15 @@ class cstruct:
|
|
|
622
633
|
_int = int
|
|
623
634
|
_float = float
|
|
624
635
|
|
|
636
|
+
# At runtime ``endian`` is a plain attribute that ``__setattr__`` normalizes, so reading it stays fast.
|
|
637
|
+
# Type checkers see a property, so that setting accepts every allowed value and reading gives the
|
|
638
|
+
# normalized one.
|
|
639
|
+
@property
|
|
640
|
+
def endian(self) -> Endianness: ...
|
|
641
|
+
|
|
642
|
+
@endian.setter
|
|
643
|
+
def endian(self, value: AllowedEndianness) -> None: ...
|
|
644
|
+
|
|
625
645
|
class int8(_int, Packed[_int]): ...
|
|
626
646
|
|
|
627
647
|
class uint8(_int, Packed[_int]): ...
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.dev24
|
|
4
4
|
Summary: A Dissect module implementing a parser for C-like structures: structure parsing in Python made easy
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -721,6 +721,36 @@ def test_endianness(cs: cstruct) -> None:
|
|
|
721
721
|
assert little_endian_cs.uint32(b"\x01\x00\x00\x00") == 1
|
|
722
722
|
|
|
723
723
|
|
|
724
|
+
@pytest.mark.parametrize(
|
|
725
|
+
("endian", "expected"),
|
|
726
|
+
[
|
|
727
|
+
("<", "<"),
|
|
728
|
+
(">", ">"),
|
|
729
|
+
("little", "<"),
|
|
730
|
+
("big", ">"),
|
|
731
|
+
("network", "!"),
|
|
732
|
+
],
|
|
733
|
+
)
|
|
734
|
+
def test_endian_attribute(cs: cstruct, endian: str, expected: str) -> None:
|
|
735
|
+
"""Test that setting the endian attribute accepts the same values as the endian argument."""
|
|
736
|
+
cs.load("struct test { uint16 a; };")
|
|
737
|
+
|
|
738
|
+
cs.endian = endian
|
|
739
|
+
assert cs.endian == expected
|
|
740
|
+
|
|
741
|
+
value = 1 if expected in (">", "!") else 0x100
|
|
742
|
+
assert cs.uint16(b"\x00\x01") == value
|
|
743
|
+
assert cs.test(b"\x00\x01").a == value
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
def test_endian_attribute_invalid(cs: cstruct) -> None:
|
|
747
|
+
"""Test that setting an invalid endianness raises immediately and keeps the current endianness."""
|
|
748
|
+
with pytest.raises(ValueError, match="Invalid endianness: 'middle'"):
|
|
749
|
+
cs.endian = "middle"
|
|
750
|
+
|
|
751
|
+
assert cs.endian == "<"
|
|
752
|
+
|
|
753
|
+
|
|
724
754
|
def test_deprecation_warnings(cs: cstruct) -> None:
|
|
725
755
|
cdef = """
|
|
726
756
|
struct test {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/requires.txt
RENAMED
|
File without changes
|
{dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/scm_file_list.json
RENAMED
|
File without changes
|
{dissect_cstruct-5.0.dev23 → dissect_cstruct-5.0.dev24}/dissect.cstruct.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|