dissect.cstruct 4.6.dev2__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.dev2 → dissect_cstruct-4.6.dev4}/CHANGELOG.md +1 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/PKG-INFO +1 -1
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/compiler.py +4 -4
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/cstruct.py +7 -4
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/expression.py +1 -1
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/parser.py +2 -2
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/structure.py +1 -1
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/PKG-INFO +1 -1
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/pyproject.toml +2 -2
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_annotations.py +1 -1
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_basic.py +46 -2
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_parser.py +0 -1
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_structure.py +36 -2
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tox.ini +4 -2
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/.git-blame-ignore-revs +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/.gitattributes +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/COPYRIGHT +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/LICENSE +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/MANIFEST.in +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/README.md +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/__init__.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/bitbuffer.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/exceptions.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/tools/__init__.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/tools/stubgen.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/__init__.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/base.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/char.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/enum.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/flag.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/int.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/leb128.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/packed.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/pointer.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/void.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/types/wchar.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect/cstruct/utils.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/SOURCES.txt +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/entry_points.txt +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/requires.txt +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/top_level.txt +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/examples/disk.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/examples/mirai.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/examples/pe.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/examples/protobuf.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/examples/secdesc.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/setup.cfg +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/__init__.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/_data/testdef.txt +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/_docs/Makefile +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/_docs/__init__.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/_docs/conf.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/_docs/index.rst +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/conftest.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_align.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_bitbuffer.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_bitfield.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_compiler.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_ctypes.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_expression.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_tools_stubgen.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_base.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_char.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_custom.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_enum.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_flag.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_int.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_leb128.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_packed.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_pointer.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_union.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_void.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_types_wchar.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/test_utils.py +0 -0
- {dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/tests/utils.py +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
|
|
@@ -226,18 +226,18 @@ class _ReadSourceGenerator:
|
|
|
226
226
|
|
|
227
227
|
def _generate_structure(self, field: Field) -> Iterator[str]:
|
|
228
228
|
template = f"""
|
|
229
|
-
{
|
|
229
|
+
{"_s = stream.tell()" if field.type.dynamic else ""}
|
|
230
230
|
r["{field._name}"] = {self._map_field(field)}._read(stream, context=r)
|
|
231
|
-
{f's["{field._name}"] = stream.tell() - _s' if field.type.dynamic else
|
|
231
|
+
{f's["{field._name}"] = stream.tell() - _s' if field.type.dynamic else ""}
|
|
232
232
|
"""
|
|
233
233
|
|
|
234
234
|
yield dedent(template)
|
|
235
235
|
|
|
236
236
|
def _generate_array(self, field: Field) -> Iterator[str]:
|
|
237
237
|
template = f"""
|
|
238
|
-
{
|
|
238
|
+
{"_s = stream.tell()" if field.type.dynamic else ""}
|
|
239
239
|
r["{field._name}"] = {self._map_field(field)}._read(stream, context=r)
|
|
240
|
-
{f's["{field._name}"] = stream.tell() - _s' if field.type.dynamic else
|
|
240
|
+
{f's["{field._name}"] = stream.tell() - _s' if field.type.dynamic else ""}
|
|
241
241
|
"""
|
|
242
242
|
|
|
243
243
|
yield dedent(template)
|
|
@@ -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]
|
|
@@ -369,14 +372,14 @@ class cstruct:
|
|
|
369
372
|
"null_terminated": null_terminated,
|
|
370
373
|
}
|
|
371
374
|
|
|
372
|
-
return cast(type[Array], self._make_type(name, bases, size, alignment=type_.alignment, attrs=attrs))
|
|
375
|
+
return cast("type[Array]", self._make_type(name, bases, size, alignment=type_.alignment, attrs=attrs))
|
|
373
376
|
|
|
374
377
|
def _make_int_type(self, name: str, size: int, signed: bool, *, alignment: int | None = None) -> type[Int]:
|
|
375
|
-
return cast(type[Int], self._make_type(name, (Int,), size, alignment=alignment, attrs={"signed": signed}))
|
|
378
|
+
return cast("type[Int]", self._make_type(name, (Int,), size, alignment=alignment, attrs={"signed": signed}))
|
|
376
379
|
|
|
377
380
|
def _make_packed_type(self, name: str, packchar: str, base: type, *, alignment: int | None = None) -> type[Packed]:
|
|
378
381
|
return cast(
|
|
379
|
-
type[Packed],
|
|
382
|
+
"type[Packed]",
|
|
380
383
|
self._make_type(
|
|
381
384
|
name,
|
|
382
385
|
(base, Packed),
|
|
@@ -141,7 +141,7 @@ class ExpressionTokenizer:
|
|
|
141
141
|
self.tokens.append(">>")
|
|
142
142
|
elif self.match(expected="<", append=False) and self.match(expected="<", append=False):
|
|
143
143
|
self.tokens.append("<<")
|
|
144
|
-
elif self.match(expected={" ", "\t"}, append=False):
|
|
144
|
+
elif self.match(expected={" ", "\n", "\t"}, append=False):
|
|
145
145
|
continue
|
|
146
146
|
else:
|
|
147
147
|
raise ExpressionTokenizerError(
|
|
@@ -63,7 +63,7 @@ class TokenParser(Parser):
|
|
|
63
63
|
"ENUM",
|
|
64
64
|
)
|
|
65
65
|
TOK.add(r"(?<=})\s*(?P<defs>(?:[a-zA-Z0-9_]+\s*,\s*)+[a-zA-Z0-9_]+)\s*(?=;)", "DEFS")
|
|
66
|
-
TOK.add(r"(?P<name>\**?\s*[a-zA-Z0-9_]+)(?:\s*:\s*(?P<bits>\d+))?(?:\[(?P<count>[
|
|
66
|
+
TOK.add(r"(?P<name>\**?\s*[a-zA-Z0-9_]+)(?:\s*:\s*(?P<bits>\d+))?(?:\[(?P<count>[^;]*)\])?\s*(?=;)", "NAME")
|
|
67
67
|
TOK.add(r"#include\s+(?P<name>[^\s]+)\s*", "INCLUDE")
|
|
68
68
|
TOK.add(r"[a-zA-Z_][a-zA-Z0-9_]*", "IDENTIFIER")
|
|
69
69
|
TOK.add(r"[{}]", "BLOCK")
|
|
@@ -194,7 +194,7 @@ class TokenParser(Parser):
|
|
|
194
194
|
if tokens.next == self.TOK.NAME:
|
|
195
195
|
# As part of a struct field
|
|
196
196
|
# struct type_name field_name;
|
|
197
|
-
if not
|
|
197
|
+
if not names:
|
|
198
198
|
raise ParserError(f"line {self._lineno(tokens.next)}: unexpected anonymous struct")
|
|
199
199
|
return self.cstruct.resolve(names[0])
|
|
200
200
|
|
|
@@ -139,7 +139,7 @@ class StructureMetaType(MetaType):
|
|
|
139
139
|
|
|
140
140
|
if cls.__compiled__:
|
|
141
141
|
# If the previous class was compiled try to compile this too
|
|
142
|
-
from dissect.cstruct import compiler
|
|
142
|
+
from dissect.cstruct import compiler # noqa: PLC0415
|
|
143
143
|
|
|
144
144
|
try:
|
|
145
145
|
classdict["_read"] = compiler.Compiler(cls.cs).compile_read(fields, cls.__name__, align=cls.__align__)
|
|
@@ -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
|
|
@@ -42,7 +42,7 @@ cstruct-stubgen = "dissect.cstruct.tools.stubgen:main"
|
|
|
42
42
|
|
|
43
43
|
[tool.ruff]
|
|
44
44
|
line-length = 120
|
|
45
|
-
required-version = ">=0.
|
|
45
|
+
required-version = ">=0.12.0"
|
|
46
46
|
|
|
47
47
|
[tool.ruff.format]
|
|
48
48
|
docstring-code-format = true
|
|
@@ -85,7 +85,7 @@ select = [
|
|
|
85
85
|
ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
|
|
86
86
|
|
|
87
87
|
[tool.ruff.lint.per-file-ignores]
|
|
88
|
-
"tests/
|
|
88
|
+
"tests/_docs/**" = ["INP001"]
|
|
89
89
|
|
|
90
90
|
[tool.ruff.lint.isort]
|
|
91
91
|
known-first-party = ["dissect.cstruct"]
|
|
@@ -21,7 +21,7 @@ def test_cstruct_type_annotation(name: str, monkeypatch: pytest.MonkeyPatch) ->
|
|
|
21
21
|
for module in [module for module in sys.modules if module in ("dissect.cstruct.cstruct")]:
|
|
22
22
|
monkeypatch.delitem(sys.modules, module)
|
|
23
23
|
|
|
24
|
-
from dissect.cstruct import cstruct
|
|
24
|
+
from dissect.cstruct import cstruct # noqa: PLC0415
|
|
25
25
|
|
|
26
26
|
if name.startswith("__"):
|
|
27
27
|
name = f"_cstruct{name}"
|
|
@@ -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
|
|
|
@@ -265,8 +265,8 @@ def test_structure_definition_simple(cs: cstruct, compiled: bool) -> None:
|
|
|
265
265
|
with pytest.raises(AttributeError):
|
|
266
266
|
obj.nope # noqa: B018
|
|
267
267
|
|
|
268
|
-
assert obj.__dynamic_sizes__ == {
|
|
269
|
-
assert obj.__sizes__ == {
|
|
268
|
+
assert obj.__dynamic_sizes__ == {"string": 7, "wstring": 10}
|
|
269
|
+
assert obj.__sizes__ == {"magic": 4, "wmagic": 8, "a": 1, "b": 2, "c": 4, "string": 7, "wstring": 10}
|
|
270
270
|
assert len(obj) == len(buf)
|
|
271
271
|
assert obj.dumps() == buf
|
|
272
272
|
|
|
@@ -276,6 +276,7 @@ def test_structure_definition_simple(cs: cstruct, compiled: bool) -> None:
|
|
|
276
276
|
obj.write(fh)
|
|
277
277
|
assert fh.getvalue() == buf
|
|
278
278
|
|
|
279
|
+
|
|
279
280
|
def test_structure_values_dict(cs: cstruct, compiled: bool) -> None:
|
|
280
281
|
cdef = """
|
|
281
282
|
struct test {
|
|
@@ -810,3 +811,36 @@ def test_codegen_hashable(cs: cstruct) -> None:
|
|
|
810
811
|
|
|
811
812
|
assert hash(structure._generate_structure__init__(hashable_fields).__code__)
|
|
812
813
|
assert hash(structure._generate_structure__init__(unhashable_fields).__code__)
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
def test_structure_definition_newline(cs: cstruct, compiled: bool) -> None:
|
|
817
|
+
cdef = """
|
|
818
|
+
struct test {
|
|
819
|
+
char magic[4
|
|
820
|
+
];
|
|
821
|
+
|
|
822
|
+
wchar wmagic[4];
|
|
823
|
+
uint8 a;
|
|
824
|
+
uint16 b;
|
|
825
|
+
uint32 c;
|
|
826
|
+
char string[];
|
|
827
|
+
wchar wstring[];
|
|
828
|
+
};
|
|
829
|
+
"""
|
|
830
|
+
cs.endian = ">"
|
|
831
|
+
cs.load(cdef, compiled=compiled)
|
|
832
|
+
|
|
833
|
+
assert verify_compiled(cs.test, compiled)
|
|
834
|
+
|
|
835
|
+
buf = b"test\x00t\x00e\x00s\x00t\x01\x02\x03\x04\x05\x06\x07lalala\x00\x00t\x00e\x00s\x00t\x00\x00"
|
|
836
|
+
|
|
837
|
+
obj = cs.test()
|
|
838
|
+
obj.magic = b"test"
|
|
839
|
+
obj.wmagic = "test"
|
|
840
|
+
obj.a = 0x01
|
|
841
|
+
obj.b = 0x0203
|
|
842
|
+
obj.c = 0x04050607
|
|
843
|
+
obj.string = b"lalala"
|
|
844
|
+
obj.wstring = "test"
|
|
845
|
+
|
|
846
|
+
assert obj.dumps() == buf
|
|
@@ -32,16 +32,18 @@ commands =
|
|
|
32
32
|
[testenv:fix]
|
|
33
33
|
package = skip
|
|
34
34
|
deps =
|
|
35
|
-
ruff==0.
|
|
35
|
+
ruff==0.12.4
|
|
36
36
|
commands =
|
|
37
37
|
ruff format dissect tests
|
|
38
|
+
ruff check --fix dissect tests
|
|
38
39
|
|
|
39
40
|
[testenv:lint]
|
|
40
41
|
package = skip
|
|
41
42
|
deps =
|
|
42
|
-
ruff==0.
|
|
43
|
+
ruff==0.12.4
|
|
43
44
|
vermin
|
|
44
45
|
commands =
|
|
46
|
+
ruff format --check dissect tests
|
|
45
47
|
ruff check dissect tests
|
|
46
48
|
vermin -t=3.9- --no-tips --lint dissect tests
|
|
47
49
|
|
|
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.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{dissect_cstruct-4.6.dev2 → dissect_cstruct-4.6.dev4}/dissect.cstruct.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dissect_cstruct-4.6.dev2 → 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
|