dissect.cstruct 4.0.dev6__tar.gz → 4.1.dev1__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.dev6/dissect.cstruct.egg-info → dissect_cstruct-4.1.dev1}/PKG-INFO +1 -1
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/parser.py +3 -1
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/structure.py +14 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1/dissect.cstruct.egg-info}/PKG-INFO +1 -1
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_parser.py +16 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_structure.py +3 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_union.py +3 -1
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/COPYRIGHT +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/LICENSE +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/MANIFEST.in +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/README.md +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/__init__.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/bitbuffer.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/compiler.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/cstruct.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/exceptions.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/expression.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/__init__.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/base.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/char.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/enum.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/flag.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/int.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/leb128.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/packed.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/pointer.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/void.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/types/wchar.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect/cstruct/utils.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect.cstruct.egg-info/SOURCES.txt +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/dissect.cstruct.egg-info/top_level.txt +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/examples/disk.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/examples/mirai.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/examples/pe.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/examples/protobuf.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/examples/secdesc.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/pyproject.toml +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/setup.cfg +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/__init__.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/conftest.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/data/testdef.txt +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/docs/Makefile +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/docs/conf.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/docs/index.rst +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_align.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_basic.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_bitbuffer.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_bitfield.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_compiler.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_ctypes.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_expression.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_base.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_char.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_custom.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_enum.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_flag.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_int.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_leb128.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_packed.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_pointer.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_void.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_types_wchar.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/test_utils.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tests/utils.py +0 -0
- {dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.1.dev1
|
|
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
|
|
@@ -251,8 +251,10 @@ class TokenParser(Parser):
|
|
|
251
251
|
type_ = self.cstruct.resolve(self._identifier(tokens))
|
|
252
252
|
elif tokens.next == self.TOK.STRUCT:
|
|
253
253
|
type_ = self._struct(tokens)
|
|
254
|
+
|
|
254
255
|
if tokens.next != self.TOK.NAME:
|
|
255
|
-
|
|
256
|
+
type_, name, bits = self._parse_field_type(type_, type_.__name__)
|
|
257
|
+
return Field(name.strip(), type_, bits)
|
|
256
258
|
|
|
257
259
|
if tokens.next != self.TOK.NAME:
|
|
258
260
|
raise ParserError(f"line {self._lineno(tokens.next)}: expected name")
|
|
@@ -111,6 +111,8 @@ class StructureMetaType(MetaType):
|
|
|
111
111
|
classdict["__init__"] = _patch_args_and_attributes(_make__init__(len(init_names)), init_names)
|
|
112
112
|
classdict["__eq__"] = _patch_attributes(_make__eq__(num_fields), field_names, 1)
|
|
113
113
|
|
|
114
|
+
classdict["__hash__"] = _patch_attributes(_make__hash__(num_fields), field_names, 1)
|
|
115
|
+
|
|
114
116
|
# If we're calling this as a class method or a function on the metaclass
|
|
115
117
|
if issubclass(cls, type):
|
|
116
118
|
size, alignment = cls._calculate_size_and_offsets(cls, fields, align)
|
|
@@ -676,3 +678,15 @@ def _make__bool__(fields: list[str]) -> str:
|
|
|
676
678
|
"""
|
|
677
679
|
|
|
678
680
|
return dedent(code)
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
@_codegen
|
|
684
|
+
def _make__hash__(fields: list[str]) -> str:
|
|
685
|
+
vals = ", ".join(f"self.{name}" for name in fields)
|
|
686
|
+
|
|
687
|
+
code = f"""
|
|
688
|
+
def __hash__(self):
|
|
689
|
+
return hash(({vals}))
|
|
690
|
+
"""
|
|
691
|
+
|
|
692
|
+
return dedent(code)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.1.dev1
|
|
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
|
|
@@ -8,6 +8,22 @@ from dissect.cstruct.parser import TokenParser
|
|
|
8
8
|
from dissect.cstruct.types import ArrayMetaType, Pointer
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
def test_nested_structs(cs: cstruct, compiled: bool) -> None:
|
|
12
|
+
cdef = """
|
|
13
|
+
struct nest {
|
|
14
|
+
struct {
|
|
15
|
+
uint32 b;
|
|
16
|
+
} a[4];
|
|
17
|
+
};
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
cs.load(cdef, compiled=compiled)
|
|
21
|
+
data = b"\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00"
|
|
22
|
+
obj = cs.nest(data)
|
|
23
|
+
for i in range(0, 4):
|
|
24
|
+
assert obj.a[i].b == i
|
|
25
|
+
|
|
26
|
+
|
|
11
27
|
def test_preserve_comment_newlines() -> None:
|
|
12
28
|
cdef = """
|
|
13
29
|
// normal comment
|
|
@@ -46,6 +46,9 @@ def test_structure(TestStruct: type[Structure]) -> None:
|
|
|
46
46
|
assert obj.b is None
|
|
47
47
|
assert len(obj) == 8
|
|
48
48
|
|
|
49
|
+
# Test hashing of values
|
|
50
|
+
assert hash((obj.a, obj.b)) == hash(obj)
|
|
51
|
+
|
|
49
52
|
|
|
50
53
|
def test_structure_read(TestStruct: type[Structure]) -> None:
|
|
51
54
|
obj = TestStruct(b"\x01\x00\x00\x00\x02\x00\x00\x00")
|
|
@@ -41,6 +41,8 @@ def test_union(TestUnion: type[Union]) -> None:
|
|
|
41
41
|
assert obj.b is None
|
|
42
42
|
assert len(obj) == 4
|
|
43
43
|
|
|
44
|
+
assert hash((obj.a, obj.b)) == hash(obj)
|
|
45
|
+
|
|
44
46
|
|
|
45
47
|
def test_union_read(TestUnion: type[Union]) -> None:
|
|
46
48
|
obj = TestUnion(b"\x01\x00\x00\x00")
|
|
@@ -288,7 +290,7 @@ def test_union_update(cs: cstruct) -> None:
|
|
|
288
290
|
assert obj.a == 2
|
|
289
291
|
obj.b = 0xFFFF
|
|
290
292
|
assert obj.a == 0xFF
|
|
291
|
-
assert obj.dumps() == b"\
|
|
293
|
+
assert obj.dumps() == b"\xff\xff"
|
|
292
294
|
|
|
293
295
|
|
|
294
296
|
def test_union_nested_update(cs: cstruct) -> None:
|
|
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.dev6 → dissect_cstruct-4.1.dev1}/dissect.cstruct.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{dissect_cstruct-4.0.dev6 → dissect_cstruct-4.1.dev1}/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
|