dissect.cstruct 4.8.dev8__py3-none-any.whl → 5.0.dev0__py3-none-any.whl
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/cstruct.py +32 -9
- dissect/cstruct/exceptions.py +4 -4
- dissect/cstruct/expression.py +189 -271
- dissect/cstruct/lexer.py +574 -0
- dissect/cstruct/parser.py +425 -592
- dissect/cstruct/utils.py +24 -10
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/METADATA +1 -1
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/RECORD +15 -12
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/WHEEL +1 -1
- dissect_cstruct-5.0.dev0.dist-info/scm_file_list.json +78 -0
- dissect_cstruct-5.0.dev0.dist-info/scm_version.json +8 -0
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/entry_points.txt +0 -0
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/licenses/COPYRIGHT +0 -0
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/licenses/LICENSE +0 -0
- {dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/top_level.txt +0 -0
dissect/cstruct/utils.py
CHANGED
|
@@ -7,13 +7,13 @@ import sys
|
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from typing import TYPE_CHECKING
|
|
9
9
|
|
|
10
|
-
from dissect.cstruct.types.pointer import Pointer
|
|
11
|
-
from dissect.cstruct.types.structure import Structure
|
|
12
|
-
|
|
13
10
|
if TYPE_CHECKING:
|
|
14
11
|
from collections.abc import Iterator
|
|
15
12
|
from typing import Literal
|
|
16
13
|
|
|
14
|
+
from dissect.cstruct.types.base import BaseType
|
|
15
|
+
from dissect.cstruct.types.structure import Structure
|
|
16
|
+
|
|
17
17
|
# Regular ANSI colors
|
|
18
18
|
COLOR_RED = "\033[0;31m"
|
|
19
19
|
COLOR_GREEN = "\033[0;32m"
|
|
@@ -263,14 +263,15 @@ def _dumpstruct(
|
|
|
263
263
|
continue
|
|
264
264
|
|
|
265
265
|
value = getattr(structure, field._name)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
elif isinstance(value, int):
|
|
266
|
+
|
|
267
|
+
if isinstance(value, int) and not isinstance(value, Enum):
|
|
269
268
|
value = hex(value)
|
|
270
269
|
elif isinstance(value, list):
|
|
271
270
|
value = pprint.pformat(value)
|
|
272
271
|
if "\n" in value:
|
|
273
272
|
value = value.replace("\n", f"\n{' ' * (len(field._name) + 4)}")
|
|
273
|
+
else:
|
|
274
|
+
value = repr(value)
|
|
274
275
|
|
|
275
276
|
if color:
|
|
276
277
|
foreground, background = colors[ci % len(colors)]
|
|
@@ -316,11 +317,10 @@ def dumpstruct(
|
|
|
316
317
|
if output not in ("print", "string"):
|
|
317
318
|
raise ValueError(f"Invalid output argument: {output!r} (should be 'print' or 'string').")
|
|
318
319
|
|
|
319
|
-
if isinstance(obj,
|
|
320
|
-
return _dumpstruct(obj, obj.dumps(), offset, color, output, autoskip)
|
|
321
|
-
if issubclass(obj, Structure) and data is not None:
|
|
320
|
+
if isinstance(obj, type) and data is not None:
|
|
322
321
|
return _dumpstruct(obj(data), data, offset, color, output, autoskip)
|
|
323
|
-
|
|
322
|
+
|
|
323
|
+
return _dumpstruct(obj, obj.dumps(), offset, color, output, autoskip)
|
|
324
324
|
|
|
325
325
|
|
|
326
326
|
def pack(value: int, size: int | None = None, endian: str = "little") -> bytes:
|
|
@@ -468,3 +468,17 @@ def swap64(value: int) -> int:
|
|
|
468
468
|
value: Integer to swap.
|
|
469
469
|
"""
|
|
470
470
|
return swap(value, 64)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def sizeof(type_: type[BaseType] | BaseType) -> int:
|
|
474
|
+
"""Get the size of a type in bytes."""
|
|
475
|
+
return len(type_)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def offsetof(type_: type[Structure], name: str) -> int:
|
|
479
|
+
"""Get the offset of a field in a structure."""
|
|
480
|
+
if (field := type_.fields.get(name)) is None:
|
|
481
|
+
raise ValueError(f"Structure '{type_.__name__}' does not have a field named '{name}'")
|
|
482
|
+
if (offset := field.offset) is None:
|
|
483
|
+
raise ValueError(f"Field '{field._name}' of structure '{type_.__name__}' does not have a known offset")
|
|
484
|
+
return offset
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version:
|
|
3
|
+
Version: 5.0.dev0
|
|
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
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
dissect/cstruct/__init__.py,sha256=Z47dU_PpbZyc2ZSyu-ww-ncX6igaTw0ItVHzVgiaiKI,1380
|
|
2
2
|
dissect/cstruct/bitbuffer.py,sha256=bid_N4ZsaTeC3x5Fzs8viUrldT863dMPtEDih20Nt6k,2644
|
|
3
3
|
dissect/cstruct/compiler.py,sha256=uOjteLdoUIVNSX71TsBAusW8U085RRH9dXkbK3dp1vY,14203
|
|
4
|
-
dissect/cstruct/cstruct.py,sha256=
|
|
5
|
-
dissect/cstruct/exceptions.py,sha256=
|
|
6
|
-
dissect/cstruct/expression.py,sha256=
|
|
7
|
-
dissect/cstruct/
|
|
8
|
-
dissect/cstruct/
|
|
4
|
+
dissect/cstruct/cstruct.py,sha256=Rq7RodLtegSbJzB0fYtSnbdBcx39Oxwm6rKZoKZVIeY,20129
|
|
5
|
+
dissect/cstruct/exceptions.py,sha256=RqD08LuBkbMqa3iQ1A05DNN8XgEmQR_SUnguwe9LGo8,316
|
|
6
|
+
dissect/cstruct/expression.py,sha256=BIqSs-xvCb4WvUb0_xjg2A4hclH8cs_W0lIGydzluIE,8027
|
|
7
|
+
dissect/cstruct/lexer.py,sha256=NEU1Ww29jWjOfhODNXMGhsBR9b-_ITnz5J-4A3kf688,19178
|
|
8
|
+
dissect/cstruct/parser.py,sha256=7F_QmlY7SZRXq-SOnbu7C6M2D8FKN63zvNNfE0D4bvQ,20545
|
|
9
|
+
dissect/cstruct/utils.py,sha256=3ZEeZ_bAZRm7IcyeB6i9h7qrcYB42LW9GJR9BtKTUDg,14650
|
|
9
10
|
dissect/cstruct/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
11
|
dissect/cstruct/tools/stubgen.py,sha256=wvl07h3VnJZWe9ygX4QMxjEH1ZcWaI_6_pSdAJoOEXk,7820
|
|
11
12
|
dissect/cstruct/types/__init__.py,sha256=6P71Pu94Dv7RNjZpDZ19pqzx-G0QzmQw4q0-3zWALso,911
|
|
@@ -20,10 +21,12 @@ dissect/cstruct/types/pointer.py,sha256=PqeJOoNBUfMd5uO2kpF6OHeW7Q6R1N1W1V4q1Mak
|
|
|
20
21
|
dissect/cstruct/types/structure.py,sha256=I9LVeZ81rNE5GDT6wxpUL-PqMO31Ae6TVLLzTGyd6mM,33012
|
|
21
22
|
dissect/cstruct/types/void.py,sha256=Gvh0HqI6jQSj2uesdo3J8-G41brWCz8pmP16l8xTBxE,1074
|
|
22
23
|
dissect/cstruct/types/wchar.py,sha256=N9Y_XX2_hZEe2DwepJjxsB6xuRJ6zINRalcUofR59kY,2608
|
|
23
|
-
dissect_cstruct-
|
|
24
|
-
dissect_cstruct-
|
|
25
|
-
dissect_cstruct-
|
|
26
|
-
dissect_cstruct-
|
|
27
|
-
dissect_cstruct-
|
|
28
|
-
dissect_cstruct-
|
|
29
|
-
dissect_cstruct-
|
|
24
|
+
dissect_cstruct-5.0.dev0.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
|
|
25
|
+
dissect_cstruct-5.0.dev0.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
|
|
26
|
+
dissect_cstruct-5.0.dev0.dist-info/METADATA,sha256=ujB3Cdxy5Yc--uXeWI4IIE24zn_t5r70jW_xmC7OBzc,9255
|
|
27
|
+
dissect_cstruct-5.0.dev0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
28
|
+
dissect_cstruct-5.0.dev0.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
|
|
29
|
+
dissect_cstruct-5.0.dev0.dist-info/scm_file_list.json,sha256=K27Mlh84EZbq__O4ajx8gV0dOE5BF81hxo0Hvtrzz1U,2308
|
|
30
|
+
dissect_cstruct-5.0.dev0.dist-info/scm_version.json,sha256=He7zR_9aI3hjUAyokmxGFi-iCH_17nbqSm6K2gebcEo,163
|
|
31
|
+
dissect_cstruct-5.0.dev0.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
32
|
+
dissect_cstruct-5.0.dev0.dist-info/RECORD,,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
".gitignore",
|
|
4
|
+
"COPYRIGHT",
|
|
5
|
+
"README.md",
|
|
6
|
+
"CHANGELOG.md",
|
|
7
|
+
".git-blame-ignore-revs",
|
|
8
|
+
"tox.ini",
|
|
9
|
+
".gitattributes",
|
|
10
|
+
"pyproject.toml",
|
|
11
|
+
"MANIFEST.in",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
".github/pull_request_template.md",
|
|
14
|
+
".github/workflows/dissect-ci.yml",
|
|
15
|
+
"dissect/cstruct/parser.py",
|
|
16
|
+
"dissect/cstruct/compiler.py",
|
|
17
|
+
"dissect/cstruct/cstruct.py",
|
|
18
|
+
"dissect/cstruct/bitbuffer.py",
|
|
19
|
+
"dissect/cstruct/utils.py",
|
|
20
|
+
"dissect/cstruct/exceptions.py",
|
|
21
|
+
"dissect/cstruct/lexer.py",
|
|
22
|
+
"dissect/cstruct/expression.py",
|
|
23
|
+
"dissect/cstruct/__init__.py",
|
|
24
|
+
"dissect/cstruct/types/base.py",
|
|
25
|
+
"dissect/cstruct/types/pointer.py",
|
|
26
|
+
"dissect/cstruct/types/structure.py",
|
|
27
|
+
"dissect/cstruct/types/void.py",
|
|
28
|
+
"dissect/cstruct/types/int.py",
|
|
29
|
+
"dissect/cstruct/types/flag.py",
|
|
30
|
+
"dissect/cstruct/types/packed.py",
|
|
31
|
+
"dissect/cstruct/types/enum.py",
|
|
32
|
+
"dissect/cstruct/types/char.py",
|
|
33
|
+
"dissect/cstruct/types/wchar.py",
|
|
34
|
+
"dissect/cstruct/types/leb128.py",
|
|
35
|
+
"dissect/cstruct/types/__init__.py",
|
|
36
|
+
"dissect/cstruct/tools/stubgen.py",
|
|
37
|
+
"dissect/cstruct/tools/__init__.py",
|
|
38
|
+
"examples/secdesc.py",
|
|
39
|
+
"examples/pe.py",
|
|
40
|
+
"examples/mirai.py",
|
|
41
|
+
"examples/protobuf.py",
|
|
42
|
+
"examples/disk.py",
|
|
43
|
+
"tests/test_types_enum.py",
|
|
44
|
+
"tests/test_types_pointer.py",
|
|
45
|
+
"tests/test_types_leb128.py",
|
|
46
|
+
"tests/test_annotations.py",
|
|
47
|
+
"tests/test_types_wchar.py",
|
|
48
|
+
"tests/test_parser.py",
|
|
49
|
+
"tests/test_ctypes.py",
|
|
50
|
+
"tests/test_bitbuffer.py",
|
|
51
|
+
"tests/conftest.py",
|
|
52
|
+
"tests/test_types_packed.py",
|
|
53
|
+
"tests/test_types_structure.py",
|
|
54
|
+
"tests/test_types_union.py",
|
|
55
|
+
"tests/test_expression.py",
|
|
56
|
+
"tests/test_tools_stubgen.py",
|
|
57
|
+
"tests/test_types_custom.py",
|
|
58
|
+
"tests/utils.py",
|
|
59
|
+
"tests/test_lexer.py",
|
|
60
|
+
"tests/test_types_flag.py",
|
|
61
|
+
"tests/test_benchmark.py",
|
|
62
|
+
"tests/test_types_char.py",
|
|
63
|
+
"tests/test_compiler.py",
|
|
64
|
+
"tests/test_types_int.py",
|
|
65
|
+
"tests/test_types_void.py",
|
|
66
|
+
"tests/test_types_base.py",
|
|
67
|
+
"tests/test_align.py",
|
|
68
|
+
"tests/test_basic.py",
|
|
69
|
+
"tests/test_bitfield.py",
|
|
70
|
+
"tests/test_utils.py",
|
|
71
|
+
"tests/__init__.py",
|
|
72
|
+
"tests/_docs/conf.py",
|
|
73
|
+
"tests/_docs/Makefile",
|
|
74
|
+
"tests/_docs/index.rst",
|
|
75
|
+
"tests/_docs/__init__.py",
|
|
76
|
+
"tests/_data/testdef.txt"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
File without changes
|
{dissect_cstruct-4.8.dev8.dist-info → dissect_cstruct-5.0.dev0.dist-info}/licenses/COPYRIGHT
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|