dissect.cstruct 4.6.dev2__py3-none-any.whl → 4.6.dev4__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/compiler.py +4 -4
- dissect/cstruct/cstruct.py +7 -4
- dissect/cstruct/expression.py +1 -1
- dissect/cstruct/parser.py +2 -2
- dissect/cstruct/types/structure.py +1 -1
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/METADATA +1 -1
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/RECORD +12 -12
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/WHEEL +0 -0
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/entry_points.txt +0 -0
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/licenses/COPYRIGHT +0 -0
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/licenses/LICENSE +0 -0
- {dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/top_level.txt +0 -0
dissect/cstruct/compiler.py
CHANGED
|
@@ -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)
|
dissect/cstruct/cstruct.py
CHANGED
|
@@ -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),
|
dissect/cstruct/expression.py
CHANGED
|
@@ -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(
|
dissect/cstruct/parser.py
CHANGED
|
@@ -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
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
dissect/cstruct/__init__.py,sha256=mILXFvtajLG5EqAPSeCJ2g5klZSnRbu7uqyGcH_DF2k,1344
|
|
2
2
|
dissect/cstruct/bitbuffer.py,sha256=bid_N4ZsaTeC3x5Fzs8viUrldT863dMPtEDih20Nt6k,2644
|
|
3
|
-
dissect/cstruct/compiler.py,sha256=
|
|
4
|
-
dissect/cstruct/cstruct.py,sha256=
|
|
3
|
+
dissect/cstruct/compiler.py,sha256=WqkO23EE_iOpVuV7FqCFPX0Q0Mcfk0oyPacV-aCGKpk,14153
|
|
4
|
+
dissect/cstruct/cstruct.py,sha256=p765dkRS-i1idodHalZYEPuyrPV0JZjkP22_SvMzJjs,19440
|
|
5
5
|
dissect/cstruct/exceptions.py,sha256=WqsUW4OiIpRLQLvixfLrfKl0rtvU1qx7pvfBrz9Sz-I,293
|
|
6
|
-
dissect/cstruct/expression.py,sha256=
|
|
7
|
-
dissect/cstruct/parser.py,sha256=
|
|
6
|
+
dissect/cstruct/expression.py,sha256=KUoKxEG-KrlovIGbt_Uskjpcgafow8_sfPaBZXJo4y8,10810
|
|
7
|
+
dissect/cstruct/parser.py,sha256=QcNrgZU5QhmLu936kZSAYwP2w1SfQYTIRy3NAc2cXf8,21315
|
|
8
8
|
dissect/cstruct/utils.py,sha256=6cU1QHTZnHXQaPoxMH93ELkwIIUgYw-TtxieEcVvYvw,10537
|
|
9
9
|
dissect/cstruct/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
dissect/cstruct/tools/stubgen.py,sha256=x-jlIet9mzONfl4sbaz6fTgEJ-FXg50HqdLhFKCEJAo,7661
|
|
@@ -17,13 +17,13 @@ dissect/cstruct/types/int.py,sha256=MGsdUxJt-lj3nl9wzAgGX8cb_vJOtGLiCHwYZs1j_IA,
|
|
|
17
17
|
dissect/cstruct/types/leb128.py,sha256=kDmsWGXX6vr1bm4uJcilsrQ7JABdQRio16rBZV21pno,2243
|
|
18
18
|
dissect/cstruct/types/packed.py,sha256=tpZpb8tiSMXr1np6p0-nZqT4sY7zieO-4E16lmMmqJA,2128
|
|
19
19
|
dissect/cstruct/types/pointer.py,sha256=PqeJOoNBUfMd5uO2kpF6OHeW7Q6R1N1W1V4q1MakN4I,3912
|
|
20
|
-
dissect/cstruct/types/structure.py,sha256=
|
|
20
|
+
dissect/cstruct/types/structure.py,sha256=jHiSKGJDms2qIe7-f9XEazKg6VQ9BLuwPElze3YZQBY,31778
|
|
21
21
|
dissect/cstruct/types/void.py,sha256=Gvh0HqI6jQSj2uesdo3J8-G41brWCz8pmP16l8xTBxE,1074
|
|
22
22
|
dissect/cstruct/types/wchar.py,sha256=N9Y_XX2_hZEe2DwepJjxsB6xuRJ6zINRalcUofR59kY,2608
|
|
23
|
-
dissect_cstruct-4.6.
|
|
24
|
-
dissect_cstruct-4.6.
|
|
25
|
-
dissect_cstruct-4.6.
|
|
26
|
-
dissect_cstruct-4.6.
|
|
27
|
-
dissect_cstruct-4.6.
|
|
28
|
-
dissect_cstruct-4.6.
|
|
29
|
-
dissect_cstruct-4.6.
|
|
23
|
+
dissect_cstruct-4.6.dev4.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
|
|
24
|
+
dissect_cstruct-4.6.dev4.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
|
|
25
|
+
dissect_cstruct-4.6.dev4.dist-info/METADATA,sha256=Q21VyYDUj3OUK4492osFe0D80aPybEfGzBpQBhvvn7s,8738
|
|
26
|
+
dissect_cstruct-4.6.dev4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
27
|
+
dissect_cstruct-4.6.dev4.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
|
|
28
|
+
dissect_cstruct-4.6.dev4.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
29
|
+
dissect_cstruct-4.6.dev4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{dissect_cstruct-4.6.dev2.dist-info → dissect_cstruct-4.6.dev4.dist-info}/licenses/COPYRIGHT
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|