dissect.cstruct 4.0.dev2__py3-none-any.whl → 4.0.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.
@@ -26,6 +26,7 @@ from dissect.cstruct.types import (
26
26
  Wchar,
27
27
  WcharArray,
28
28
  )
29
+ from dissect.cstruct.types.enum import EnumMetaType
29
30
  from dissect.cstruct.types.packed import _struct
30
31
 
31
32
  if TYPE_CHECKING:
@@ -108,6 +109,7 @@ class _ReadSourceGenerator:
108
109
  preamble = """
109
110
  r = {}
110
111
  s = {}
112
+ o = stream.tell()
111
113
  """
112
114
 
113
115
  if any(field.bits for field in self.fields):
@@ -149,7 +151,7 @@ class _ReadSourceGenerator:
149
151
 
150
152
  if field.offset is not None and field.offset != current_offset:
151
153
  # If a field has a set offset and it's not the same as the current tracked offset, seek to it
152
- yield f"stream.seek({field.offset})"
154
+ yield f"stream.seek(o + {field.offset})"
153
155
  current_offset = field.offset
154
156
 
155
157
  if self.align and field.offset is None:
@@ -158,6 +160,9 @@ class _ReadSourceGenerator:
158
160
  for field in self.fields:
159
161
  field_type = self.cs.resolve(field.type)
160
162
 
163
+ if isinstance(field_type, EnumMetaType):
164
+ field_type = field_type.type
165
+
161
166
  if not issubclass(field_type, SUPPORTED_TYPES):
162
167
  raise TypeError(f"Unsupported type for compiler: {field_type}")
163
168
 
@@ -190,10 +195,10 @@ class _ReadSourceGenerator:
190
195
  # Bit fields
191
196
  elif field.bits:
192
197
  if not prev_was_bits:
193
- prev_bits_type = field.type
198
+ prev_bits_type = field_type
194
199
  prev_was_bits = True
195
200
 
196
- if bits_remaining == 0 or prev_bits_type != field.type:
201
+ if bits_remaining == 0 or prev_bits_type != field_type:
197
202
  bits_remaining = (size * 8) - field.bits
198
203
  bits_rollover = True
199
204
 
@@ -49,7 +49,7 @@ class StructureMetaType(MetaType):
49
49
 
50
50
  def __new__(metacls, name: str, bases: tuple[type, ...], classdict: dict[str, Any]) -> MetaType:
51
51
  if (fields := classdict.pop("fields", None)) is not None:
52
- metacls._update_fields(metacls, fields, align=classdict.get("align", False), classdict=classdict)
52
+ metacls._update_fields(metacls, fields, align=classdict.get("__align__", False), classdict=classdict)
53
53
 
54
54
  return super().__new__(metacls, name, bases, classdict)
55
55
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.cstruct
3
- Version: 4.0.dev2
3
+ Version: 4.0.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,6 +1,6 @@
1
1
  dissect/cstruct/__init__.py,sha256=E8HT9kh67nPR6cnUmTmTJIdGANNfInG_htxb8mPjSik,1344
2
2
  dissect/cstruct/bitbuffer.py,sha256=phqKSE-BS8crZ_sdzssF3E831bD5Gk8LOXIE7iQJXa8,2218
3
- dissect/cstruct/compiler.py,sha256=MYhlvXqhXwrjov5SFO3i8eftdsvjdrIXszQrflr6kQU,13810
3
+ dissect/cstruct/compiler.py,sha256=dB7Wi1GC0pYoVe5x3olZDmAT3ypbyV-1h-BMefJk5dU,13991
4
4
  dissect/cstruct/cstruct.py,sha256=W-17FFc8OM2je7VTMMVQc-hivCAjaRj9qSdf4cEDrCY,14851
5
5
  dissect/cstruct/exceptions.py,sha256=WqsUW4OiIpRLQLvixfLrfKl0rtvU1qx7pvfBrz9Sz-I,293
6
6
  dissect/cstruct/expression.py,sha256=giBNkbFgsbsw2K2EvQi42GRlm9Z97UvhDhcHnNMG2dg,10763
@@ -15,12 +15,12 @@ dissect/cstruct/types/int.py,sha256=pBdr9InRY3EMHlULBmzBZCI2Qdh2XygsUelDWBrIRhc,
15
15
  dissect/cstruct/types/leb128.py,sha256=yHkWqcGEWkf-8ZzfLv_5p937fzrMRvlZXwxowEl36CU,2168
16
16
  dissect/cstruct/types/packed.py,sha256=gmNxtNRf9feY8k_7UYMGADe31dtXkw5fQYG1CtyvJBo,1973
17
17
  dissect/cstruct/types/pointer.py,sha256=kWfEBCgW7TDnJihZiDGUlldD3QSxVY19r8LGz7olswk,3644
18
- dissect/cstruct/types/structure.py,sha256=Pqdo4IjdF-XzTVTtDZqu9EUTxdsQ1a5HwAEgF9HbLg8,23954
18
+ dissect/cstruct/types/structure.py,sha256=CqiT_Hzb33yVh5pCNbn-0MkgZcIhXOYfNlOqPnEgjgw,23958
19
19
  dissect/cstruct/types/void.py,sha256=RGBlM1yBYCFUM9yLyOETMZBd_nEp9-6vH5xFXaphK8o,438
20
20
  dissect/cstruct/types/wchar.py,sha256=5kap4GDypRmt5IoLhMnREbWaWTEMhY_xVLCFginbwFo,2536
21
- dissect.cstruct-4.0.dev2.dist-info/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
22
- dissect.cstruct-4.0.dev2.dist-info/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
23
- dissect.cstruct-4.0.dev2.dist-info/METADATA,sha256=EJQTgpQ_60wUCcHxQ2d1cqBK7FYjpuIL7T67XG2N-58,8303
24
- dissect.cstruct-4.0.dev2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
25
- dissect.cstruct-4.0.dev2.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
26
- dissect.cstruct-4.0.dev2.dist-info/RECORD,,
21
+ dissect.cstruct-4.0.dev4.dist-info/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
22
+ dissect.cstruct-4.0.dev4.dist-info/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
23
+ dissect.cstruct-4.0.dev4.dist-info/METADATA,sha256=40l7igJ3GhdnATO1fAbVDfb9MiSjf2ExjBZKQUyV-jE,8303
24
+ dissect.cstruct-4.0.dev4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
25
+ dissect.cstruct-4.0.dev4.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
26
+ dissect.cstruct-4.0.dev4.dist-info/RECORD,,