dissect.cstruct 4.0.dev1__tar.gz → 4.0.dev3__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-4.0.dev1/dissect.cstruct.egg-info → dissect_cstruct-4.0.dev3}/PKG-INFO +1 -1
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/enum.py +12 -7
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/structure.py +1 -1
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3/dissect.cstruct.egg-info}/PKG-INFO +1 -1
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_enum.py +12 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_structure.py +9 -1
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/COPYRIGHT +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/LICENSE +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/MANIFEST.in +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/README.md +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/__init__.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/bitbuffer.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/compiler.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/cstruct.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/exceptions.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/expression.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/parser.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/__init__.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/base.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/char.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/flag.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/int.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/leb128.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/packed.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/pointer.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/void.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/types/wchar.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect/cstruct/utils.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect.cstruct.egg-info/SOURCES.txt +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect.cstruct.egg-info/top_level.txt +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/examples/disk.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/examples/mirai.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/examples/pe.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/examples/protobuf.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/examples/secdesc.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/pyproject.toml +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/setup.cfg +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/__init__.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/conftest.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/data/testdef.txt +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/docs/Makefile +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/docs/conf.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/docs/index.rst +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_align.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_basic.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_bitbuffer.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_bitfield.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_compiler.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_ctypes.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_expression.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_parser.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_base.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_char.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_custom.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_flag.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_int.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_leb128.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_packed.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_pointer.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_union.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_void.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_types_wchar.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/test_utils.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tests/utils.py +0 -0
- {dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 4.0.
|
|
3
|
+
Version: 4.0.dev3
|
|
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: Apache License 2.0
|
|
@@ -11,6 +11,7 @@ if TYPE_CHECKING:
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
PY_311 = sys.version_info >= (3, 11, 0)
|
|
14
|
+
PY_312 = sys.version_info >= (3, 12, 0)
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class EnumMetaType(EnumMeta, MetaType):
|
|
@@ -56,6 +57,13 @@ class EnumMetaType(EnumMeta, MetaType):
|
|
|
56
57
|
|
|
57
58
|
__len__ = MetaType.__len__
|
|
58
59
|
|
|
60
|
+
if not PY_312:
|
|
61
|
+
# Backport __contains__ from CPython 3.12
|
|
62
|
+
def __contains__(cls, value: Any) -> bool:
|
|
63
|
+
if isinstance(value, cls):
|
|
64
|
+
return True
|
|
65
|
+
return value in cls._value2member_map_
|
|
66
|
+
|
|
59
67
|
def _read(cls, stream: BinaryIO, context: dict[str, Any] = None) -> Enum:
|
|
60
68
|
return cls(cls.type._read(stream, context))
|
|
61
69
|
|
|
@@ -174,10 +182,7 @@ class Enum(BaseType, IntEnum, metaclass=EnumMetaType):
|
|
|
174
182
|
@classmethod
|
|
175
183
|
def _missing_(cls, value: int) -> Enum:
|
|
176
184
|
# Emulate FlagBoundary.KEEP for enum (allow values other than the defined members)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
new_member._value_ = value
|
|
182
|
-
pseudo_member = cls._value2member_map_.setdefault(value, new_member)
|
|
183
|
-
return pseudo_member
|
|
185
|
+
new_member = int.__new__(cls, value)
|
|
186
|
+
new_member._name_ = None
|
|
187
|
+
new_member._value_ = value
|
|
188
|
+
return new_member
|
|
@@ -49,7 +49,7 @@ class StructureMetaType(MetaType):
|
|
|
49
49
|
|
|
50
50
|
def __new__(metacls, name: str, bases: tuple[type, ...], classdict: dict[str, Any]) -> MetaType:
|
|
51
51
|
if (fields := classdict.pop("fields", None)) is not None:
|
|
52
|
-
metacls._update_fields(metacls, fields, align=classdict.get("
|
|
52
|
+
metacls._update_fields(metacls, fields, align=classdict.get("__align__", False), classdict=classdict)
|
|
53
53
|
|
|
54
54
|
return super().__new__(metacls, name, bases, classdict)
|
|
55
55
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 4.0.
|
|
3
|
+
Version: 4.0.dev3
|
|
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: Apache License 2.0
|
|
@@ -34,6 +34,18 @@ def test_enum(cs: cstruct, TestEnum: type[Enum]) -> None:
|
|
|
34
34
|
assert TestEnum(0).name is None
|
|
35
35
|
assert TestEnum(0).value == 0
|
|
36
36
|
|
|
37
|
+
assert 0 not in TestEnum
|
|
38
|
+
assert 1 in TestEnum
|
|
39
|
+
assert 2 in TestEnum
|
|
40
|
+
assert 3 in TestEnum
|
|
41
|
+
assert 4 not in TestEnum
|
|
42
|
+
|
|
43
|
+
assert TestEnum.A in TestEnum
|
|
44
|
+
|
|
45
|
+
# Mixing enums is not allowed
|
|
46
|
+
OtherEnum = cs._make_enum("Other", cs.uint8, {"A": 1, "B": 2, "C": 3})
|
|
47
|
+
assert OtherEnum.A not in TestEnum
|
|
48
|
+
|
|
37
49
|
|
|
38
50
|
def test_enum_read(TestEnum: type[Enum]) -> None:
|
|
39
51
|
assert TestEnum(b"\x02") == TestEnum.B
|
|
@@ -9,7 +9,7 @@ from dissect.cstruct.cstruct import cstruct
|
|
|
9
9
|
from dissect.cstruct.exceptions import ParserError
|
|
10
10
|
from dissect.cstruct.types.base import Array, BaseType
|
|
11
11
|
from dissect.cstruct.types.pointer import Pointer
|
|
12
|
-
from dissect.cstruct.types.structure import Field, Structure
|
|
12
|
+
from dissect.cstruct.types.structure import Field, Structure, StructureMetaType
|
|
13
13
|
|
|
14
14
|
from .utils import verify_compiled
|
|
15
15
|
|
|
@@ -529,3 +529,11 @@ def test_structure_definition_self(cs: cstruct) -> None:
|
|
|
529
529
|
|
|
530
530
|
assert issubclass(cs.test.fields["b"].type, Pointer)
|
|
531
531
|
assert cs.test.fields["b"].type.type is cs.test
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def test_align_struct_in_struct(cs: cstruct) -> None:
|
|
535
|
+
with patch.object(StructureMetaType, "_update_fields") as update_fields:
|
|
536
|
+
cs._make_struct("test", [Field("a", cs.uint64)], align=True)
|
|
537
|
+
|
|
538
|
+
_, kwargs = update_fields.call_args
|
|
539
|
+
assert kwargs["align"]
|
|
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-4.0.dev1 → dissect_cstruct-4.0.dev3}/dissect.cstruct.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{dissect_cstruct-4.0.dev1 → dissect_cstruct-4.0.dev3}/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
|