dissect.cstruct 5.0.dev19__py3-none-any.whl → 5.0.dev20__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 +2 -5
- dissect/cstruct/dump.py +1 -1
- dissect/cstruct/types/enum.py +7 -9
- dissect/cstruct/types/structure.py +2 -1
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/METADATA +1 -1
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/RECORD +11 -11
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/WHEEL +0 -0
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/entry_points.txt +0 -0
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/licenses/COPYRIGHT +0 -0
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/licenses/LICENSE +0 -0
- {dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/top_level.txt +0 -0
dissect/cstruct/compiler.py
CHANGED
|
@@ -948,9 +948,8 @@ class _WriteSourceGenerator(_SourceGenerator):
|
|
|
948
948
|
other = []
|
|
949
949
|
remaining = type_.__size__ * 8
|
|
950
950
|
for field in fields:
|
|
951
|
+
# Enum members and plain integers are shifted the same way
|
|
951
952
|
value = self._load_value(field, _get_attribute("data", field._name), pack)
|
|
952
|
-
if issubclass(field.type, (Enum, Flag)):
|
|
953
|
-
value += "._value_"
|
|
954
953
|
|
|
955
954
|
remaining -= field.bits
|
|
956
955
|
little.append(f"{value} << {type_.__size__ * 8 - remaining - field.bits}")
|
|
@@ -1069,9 +1068,7 @@ class _WriteSourceGenerator(_SourceGenerator):
|
|
|
1069
1068
|
|
|
1070
1069
|
pack.add(count, "s", var)
|
|
1071
1070
|
|
|
1072
|
-
|
|
1073
|
-
self._pack_number(read_type, f"{self._load_value(field, value, pack)}._value_", pack)
|
|
1074
|
-
|
|
1071
|
+
# Enum members and plain integers are packed the same way, as the integer type of the enum
|
|
1075
1072
|
elif issubclass(read_type, Packed):
|
|
1076
1073
|
pack.add(1, read_type.__fmt__, value, f"_or_default({value}, {type_})")
|
|
1077
1074
|
|
dissect/cstruct/dump.py
CHANGED
|
@@ -318,7 +318,7 @@ def _describe_value(
|
|
|
318
318
|
Structures and unions, and arrays of them, get their fields or elements as child nodes. Other values, including
|
|
319
319
|
arrays of other types, are formatted as a human-readable ``display``.
|
|
320
320
|
"""
|
|
321
|
-
|
|
321
|
+
while isinstance(value, UnionProxy):
|
|
322
322
|
# Nested Structure members inside a Union are proxied; unwrap to the real Structure
|
|
323
323
|
value = value.__target__
|
|
324
324
|
|
dissect/cstruct/types/enum.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
|
-
from enum import Enum as _Enum
|
|
5
4
|
from enum import EnumMeta, IntEnum, IntFlag
|
|
6
5
|
from typing import TYPE_CHECKING, Any, BinaryIO, TypeVar, overload
|
|
7
6
|
|
|
@@ -100,16 +99,15 @@ class EnumMetaType(EnumMeta, MetaType):
|
|
|
100
99
|
def _read_0(cls, stream: BinaryIO, *, context: dict[str, Any] | None = None, endian: Endianness) -> list[Self]:
|
|
101
100
|
return list(map(cls, cls.__type__._read_0(stream, context=context, endian=endian)))
|
|
102
101
|
|
|
103
|
-
def _write(cls, stream: BinaryIO, data: Enum, *, endian: Endianness) -> int:
|
|
104
|
-
|
|
102
|
+
def _write(cls, stream: BinaryIO, data: Enum | int, *, endian: Endianness) -> int:
|
|
103
|
+
# Enum members are integers, so the integer type writes them like plain integers
|
|
104
|
+
return cls.__type__._write(stream, data, endian=endian)
|
|
105
105
|
|
|
106
|
-
def _write_array(cls, stream: BinaryIO, array: list[
|
|
107
|
-
|
|
108
|
-
return cls.__type__._write_array(stream, data, endian=endian)
|
|
106
|
+
def _write_array(cls, stream: BinaryIO, array: list[Enum | int], *, endian: Endianness) -> int:
|
|
107
|
+
return cls.__type__._write_array(stream, array, endian=endian)
|
|
109
108
|
|
|
110
|
-
def _write_0(cls, stream: BinaryIO, array: list[
|
|
111
|
-
|
|
112
|
-
return cls._write_array(stream, [*data, cls.__type__.__default__()], endian=endian)
|
|
109
|
+
def _write_0(cls, stream: BinaryIO, array: list[Enum | int], *, endian: Endianness) -> int:
|
|
110
|
+
return cls.__type__._write_0(stream, array, endian=endian)
|
|
113
111
|
|
|
114
112
|
def cdef(cls) -> str:
|
|
115
113
|
"""Render this enum (or flag) back to its C-style definition.
|
|
@@ -342,7 +342,8 @@ class StructureMetaType(MetaType):
|
|
|
342
342
|
bit_buffer = BitBuffer(stream, endian=endian)
|
|
343
343
|
|
|
344
344
|
if isinstance(field_type, EnumMetaType):
|
|
345
|
-
|
|
345
|
+
# Enum members and plain integers are shifted into the buffer the same way
|
|
346
|
+
bit_buffer.write(field_type.__type__, value, field.bits)
|
|
346
347
|
else:
|
|
347
348
|
bit_buffer.write(field_type, value, field.bits)
|
|
348
349
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.dev20
|
|
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,9 +1,9 @@
|
|
|
1
1
|
dissect/cstruct/__init__.py,sha256=ti1VYFx1MtZuDcMks14haNvUw0IZYjRo346ChzhqPls,1647
|
|
2
2
|
dissect/cstruct/bitbuffer.py,sha256=aNzY4lkWe8ffAc8j7FODXzwZc8gZwbey77UosyoYCsw,2711
|
|
3
|
-
dissect/cstruct/compiler.py,sha256=
|
|
3
|
+
dissect/cstruct/compiler.py,sha256=3dlVVzU8-i-G5PKti8sMTKLF3BdQ9g6_tHaKn0KDqJA,54440
|
|
4
4
|
dissect/cstruct/cstruct.py,sha256=mJerzPouWV29RdK5LqjGitDDMvNKcadoT2hj1zpExnM,26551
|
|
5
5
|
dissect/cstruct/declarative.py,sha256=5ubPtOyy6L5gJMFaPcbW3xYbTijZGMp0XJGxBeed1nE,14505
|
|
6
|
-
dissect/cstruct/dump.py,sha256=
|
|
6
|
+
dissect/cstruct/dump.py,sha256=W5ISbaZ-1YmWXKzh-x6pDt5_SlpFRDhD9GGNyv1MnLw,19016
|
|
7
7
|
dissect/cstruct/exception.py,sha256=box-mw6FoP6c3vndvYLcTeJCZVgIG8IQVPEAg4zW0C8,380
|
|
8
8
|
dissect/cstruct/expression.py,sha256=SbZRv7ueasYU4k-4k2eV1fjwL3JTAgF2UBaBvNjwiv4,10736
|
|
9
9
|
dissect/cstruct/lexer.py,sha256=N7eqCOlcaQriUUIswJv16i-CE_sahYXGO-YdFO0IKKY,20421
|
|
@@ -14,19 +14,19 @@ dissect/cstruct/tools/stubgen.py,sha256=MeZkLmSeNSLNcAEwlAdIGv1lKvlvK3UQ4WN85ovs
|
|
|
14
14
|
dissect/cstruct/types/__init__.py,sha256=6P71Pu94Dv7RNjZpDZ19pqzx-G0QzmQw4q0-3zWALso,911
|
|
15
15
|
dissect/cstruct/types/base.py,sha256=NdCP9dJk6lrKPERYjR9qeD2gFzWd6krVSN4tAOqqkvI,18357
|
|
16
16
|
dissect/cstruct/types/char.py,sha256=N19R7Zzn2uMuG-ULW5X2UgmgkLvjaBj1Td7AQQI93Fg,3417
|
|
17
|
-
dissect/cstruct/types/enum.py,sha256=
|
|
17
|
+
dissect/cstruct/types/enum.py,sha256=VICmKWRuzTicq6pNKpAG_xfFzC5pVLp48qe9lFyXqoc,9029
|
|
18
18
|
dissect/cstruct/types/flag.py,sha256=YxQHix8ZhK1qQX3J_Og7GJp_4JAxCwzUbUibuJeDaWQ,3479
|
|
19
19
|
dissect/cstruct/types/int.py,sha256=9RbdrkvAI28zATM97VVORQnras0XhLaVMtdPjJwpTH4,2089
|
|
20
20
|
dissect/cstruct/types/leb128.py,sha256=V97XTJT_Xbw1LpTwTN1OkjPHuQQAQUxd8OGuA6yEDmE,2387
|
|
21
21
|
dissect/cstruct/types/packed.py,sha256=NgCX0YWX8SH8z47atq0f39w9MBjU_eBFJtUisUWdO-M,3867
|
|
22
22
|
dissect/cstruct/types/pointer.py,sha256=FNuB9bfENWRebbKX-R6Vs6xWPMHepjvOhhomeUhr7I8,3985
|
|
23
|
-
dissect/cstruct/types/structure.py,sha256=
|
|
23
|
+
dissect/cstruct/types/structure.py,sha256=cwLzetR0AEDBVqOIeOxo6viWxbTRvt5tYDkbZEISk_U,43165
|
|
24
24
|
dissect/cstruct/types/void.py,sha256=fV4hKk50uop_EKbR1nfy1cdtAzvUYrSymXsdakCyFk8,1222
|
|
25
25
|
dissect/cstruct/types/wchar.py,sha256=VrnPXsP_lsyA-1xr4D2aSIVijumMhUuZWNlDHcn12-s,3964
|
|
26
|
-
dissect_cstruct-5.0.
|
|
27
|
-
dissect_cstruct-5.0.
|
|
28
|
-
dissect_cstruct-5.0.
|
|
29
|
-
dissect_cstruct-5.0.
|
|
30
|
-
dissect_cstruct-5.0.
|
|
31
|
-
dissect_cstruct-5.0.
|
|
32
|
-
dissect_cstruct-5.0.
|
|
26
|
+
dissect_cstruct-5.0.dev20.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
|
|
27
|
+
dissect_cstruct-5.0.dev20.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
|
|
28
|
+
dissect_cstruct-5.0.dev20.dist-info/METADATA,sha256=PTh5qmB9Hrn-h2yQbC1r_V3eZjE_iit0oL9mKRErugo,12661
|
|
29
|
+
dissect_cstruct-5.0.dev20.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
30
|
+
dissect_cstruct-5.0.dev20.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
|
|
31
|
+
dissect_cstruct-5.0.dev20.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
32
|
+
dissect_cstruct-5.0.dev20.dist-info/RECORD,,
|
|
File without changes
|
{dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/licenses/COPYRIGHT
RENAMED
|
File without changes
|
{dissect_cstruct-5.0.dev19.dist-info → dissect_cstruct-5.0.dev20.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|