dissect.cstruct 4.6.dev3__tar.gz → 4.6.dev4__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.6.dev3 → dissect_cstruct-4.6.dev4}/CHANGELOG.md +1 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/PKG-INFO +1 -1
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/cstruct.py +4 -1
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/PKG-INFO +1 -1
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_basic.py +46 -2
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/.git-blame-ignore-revs +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/.gitattributes +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/COPYRIGHT +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/LICENSE +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/MANIFEST.in +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/README.md +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/__init__.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/bitbuffer.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/compiler.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/exceptions.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/expression.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/parser.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/tools/__init__.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/tools/stubgen.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/__init__.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/base.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/char.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/enum.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/flag.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/int.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/leb128.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/packed.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/pointer.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/structure.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/void.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/wchar.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect/cstruct/utils.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/SOURCES.txt +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/entry_points.txt +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/requires.txt +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/top_level.txt +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/examples/disk.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/examples/mirai.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/examples/pe.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/examples/protobuf.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/examples/secdesc.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/pyproject.toml +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/setup.cfg +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/__init__.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/_data/testdef.txt +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/_docs/Makefile +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/_docs/__init__.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/_docs/conf.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/_docs/index.rst +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/conftest.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_align.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_annotations.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_bitbuffer.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_bitfield.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_compiler.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_ctypes.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_expression.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_parser.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_tools_stubgen.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_base.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_char.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_custom.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_enum.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_flag.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_int.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_leb128.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_packed.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_pointer.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_structure.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_union.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_void.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_types_wchar.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/test_utils.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tests/utils.py +0 -0
- {dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/tox.ini +0 -0
|
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
11
11
|
- Optimize storage of field sizes.
|
|
12
12
|
- Rename `_sizes` property of `Structure` to `__sizes__`.
|
|
13
13
|
- Rename `_values` property of `Structure` to `__values__`.
|
|
14
|
+
- Added `load` argument to `cstruct` class, allowing direct initialization with a definition (i.e. `cstruct(cdef)` instead of `cstruct().load(cdef)`. Other arguments to `cstruct` are now keyword only.
|
|
14
15
|
|
|
15
16
|
## [4.5] - 20-05-2025
|
|
16
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 4.6.
|
|
3
|
+
Version: 4.6.dev4
|
|
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
|
|
@@ -48,7 +48,7 @@ class cstruct:
|
|
|
48
48
|
DEF_CSTYLE = 1
|
|
49
49
|
DEF_LEGACY = 2
|
|
50
50
|
|
|
51
|
-
def __init__(self, endian: str = "<", pointer: str | None = None):
|
|
51
|
+
def __init__(self, load: str = "", *, endian: str = "<", pointer: str | None = None):
|
|
52
52
|
self.endian = endian
|
|
53
53
|
|
|
54
54
|
self.consts = {}
|
|
@@ -188,6 +188,9 @@ class cstruct:
|
|
|
188
188
|
self.pointer: type[BaseType] = self.resolve(pointer)
|
|
189
189
|
self._anonymous_count = 0
|
|
190
190
|
|
|
191
|
+
if load:
|
|
192
|
+
self.load(load)
|
|
193
|
+
|
|
191
194
|
def __getattr__(self, attr: str) -> Any:
|
|
192
195
|
try:
|
|
193
196
|
return self.consts[attr]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 4.6.
|
|
3
|
+
Version: 4.6.dev4
|
|
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
|
|
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, BinaryIO
|
|
|
6
6
|
|
|
7
7
|
import pytest
|
|
8
8
|
|
|
9
|
+
from dissect.cstruct.cstruct import cstruct
|
|
9
10
|
from dissect.cstruct.exceptions import ArraySizeError, ParserError, ResolveError
|
|
10
11
|
from dissect.cstruct.types import BaseType
|
|
11
12
|
|
|
@@ -14,8 +15,6 @@ from .utils import verify_compiled
|
|
|
14
15
|
if TYPE_CHECKING:
|
|
15
16
|
from pathlib import Path
|
|
16
17
|
|
|
17
|
-
from dissect.cstruct.cstruct import cstruct
|
|
18
|
-
|
|
19
18
|
|
|
20
19
|
def test_duplicate_type(cs: cstruct, compiled: bool) -> None:
|
|
21
20
|
cdef = """
|
|
@@ -41,6 +40,51 @@ def test_load_file(cs: cstruct, compiled: bool, tmp_path: Path) -> None:
|
|
|
41
40
|
assert "test" in cs.typedefs
|
|
42
41
|
|
|
43
42
|
|
|
43
|
+
def test_load_init() -> None:
|
|
44
|
+
cdef = """
|
|
45
|
+
struct test {
|
|
46
|
+
DWORD a;
|
|
47
|
+
QWORD b;
|
|
48
|
+
};
|
|
49
|
+
"""
|
|
50
|
+
# load with first positional argument
|
|
51
|
+
cs = cstruct(cdef)
|
|
52
|
+
assert "test" in cs.typedefs
|
|
53
|
+
assert cs.endian == "<"
|
|
54
|
+
|
|
55
|
+
# load from keyword argument and big endian
|
|
56
|
+
cs = cstruct(load=cdef, endian=">")
|
|
57
|
+
assert "test" in cs.typedefs
|
|
58
|
+
a = cs.test(a=0xBADC0DE, b=0xACCE55ED)
|
|
59
|
+
assert len(bytes(a)) == 12
|
|
60
|
+
assert bytes(a) == a.dumps()
|
|
61
|
+
assert bytes(a) == b"\x0b\xad\xc0\xde\x00\x00\x00\x00\xac\xce\x55\xed"
|
|
62
|
+
|
|
63
|
+
# load using positional argument and little endian
|
|
64
|
+
cs = cstruct(cdef, endian="<")
|
|
65
|
+
assert "test" in cs.typedefs
|
|
66
|
+
a = cs.test(a=0xBADC0DE, b=0xACCE55ED)
|
|
67
|
+
assert len(bytes(a)) == 12
|
|
68
|
+
assert bytes(a) == a.dumps()
|
|
69
|
+
assert bytes(a) == b"\xde\xc0\xad\x0b\xed\x55\xce\xac\x00\x00\x00\x00"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_load_init_kwargs_only() -> None:
|
|
73
|
+
cdef = """
|
|
74
|
+
struct test {
|
|
75
|
+
uint32 a;
|
|
76
|
+
};
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
# kwargs only check
|
|
80
|
+
with pytest.raises(TypeError, match="takes from .* positional arguments but .* were given"):
|
|
81
|
+
cs = cstruct(cdef, ">")
|
|
82
|
+
|
|
83
|
+
cs = cstruct(cdef, endian=">")
|
|
84
|
+
assert "test" in cs.typedefs
|
|
85
|
+
assert cs.endian == ">"
|
|
86
|
+
|
|
87
|
+
|
|
44
88
|
def test_read_type_name(cs: cstruct) -> None:
|
|
45
89
|
assert cs.read("uint32", b"\x01\x00\x00\x00") == 1
|
|
46
90
|
|
|
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-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dissect_cstruct-4.6.dev3 → dissect_cstruct-4.6.dev4}/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
|