dissect.cstruct 5.0.dev20__py3-none-any.whl → 5.0.dev21__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.
@@ -722,7 +722,7 @@ class _ReadSourceGenerator(_SourceGenerator):
722
722
  if issubclass(read_type, Int):
723
723
  # Everything that's read as an integer type is sliced directly out of the buffer
724
724
  elem_size = read_type.__size__
725
- signed = bool(read_type.signed)
725
+ signed = bool(read_type.__signed__)
726
726
  lines.append(f"_array_buf = {getter}")
727
727
  raw = f"_int_from_bytes(_array_buf[i:i + {elem_size}], _byteorder[endian], signed={signed})"
728
728
  getter = f"[{raw} for i in range(0, {count}, {elem_size})]"
@@ -753,7 +753,7 @@ class _ReadSourceGenerator(_SourceGenerator):
753
753
  elif issubclass(field_type, (Enum, Flag)):
754
754
  # Fast path the member lookup, the slow path takes care of unknown values
755
755
  if issubclass(read_type, Int):
756
- raw = f"_int_from_bytes({getter}, _byteorder[endian], signed={bool(read_type.signed)})"
756
+ raw = f"_int_from_bytes({getter}, _byteorder[endian], signed={bool(read_type.__signed__)})"
757
757
  else:
758
758
  raw = getter
759
759
 
@@ -762,7 +762,7 @@ class _ReadSourceGenerator(_SourceGenerator):
762
762
  lines.extend(target(field, "_member"))
763
763
 
764
764
  elif issubclass(read_type, Int):
765
- signed = bool(read_type.signed)
765
+ signed = bool(read_type.__signed__)
766
766
  value = f"_int_from_bytes({getter}, _byteorder[endian], signed={signed})"
767
767
  lines.extend(target(field, f"_type_call({self._type_symbol(field.type)}, {value})"))
768
768
 
@@ -1208,7 +1208,7 @@ def _has_default_write(type_: type[BaseType], base: type[BaseType]) -> bool:
1208
1208
 
1209
1209
  def _int_to_bytes(type_: type[Int], value: str) -> str:
1210
1210
  """Return the code to convert a value of an integer type to bytes."""
1211
- return f"{value}.to_bytes({type_.__size__}, _byteorder[endian], signed={bool(type_.signed)})"
1211
+ return f"{value}.to_bytes({type_.__size__}, _byteorder[endian], signed={bool(type_.__signed__)})"
1212
1212
 
1213
1213
 
1214
1214
  def _get_attribute(var: str, name: str) -> str:
@@ -90,8 +90,8 @@ class cstruct:
90
90
  "int128": self._make_int_type("int128", 16, True, alignment=16),
91
91
  "uint128": self._make_int_type("uint128", 16, False, alignment=16),
92
92
 
93
- "uleb128": self._make_type("uleb128", (LEB128,), None, attrs={"signed": False}),
94
- "ileb128": self._make_type("ileb128", (LEB128,), None, attrs={"signed": True}),
93
+ "uleb128": self._make_type("uleb128", (LEB128,), None, attrs={"__signed__": False}),
94
+ "ileb128": self._make_type("ileb128", (LEB128,), None, attrs={"__signed__": True}),
95
95
 
96
96
  "void": self._make_type("void", (Void,), 0),
97
97
 
@@ -552,7 +552,7 @@ class cstruct:
552
552
  return cast("type[Array]", self._make_type(name, bases, size, alignment=type_.__alignment__, attrs=attrs))
553
553
 
554
554
  def _make_int_type(self, name: str, size: int, signed: bool, *, alignment: int | None = None) -> type[Int]:
555
- return cast("type[Int]", self._make_type(name, (Int,), size, alignment=alignment, attrs={"signed": signed}))
555
+ return cast("type[Int]", self._make_type(name, (Int,), size, alignment=alignment, attrs={"__signed__": signed}))
556
556
 
557
557
  def _make_packed_type(self, name: str, fmt: str, base: type, *, alignment: int | None = None) -> type[Packed]:
558
558
  return cast(
@@ -562,7 +562,7 @@ class cstruct:
562
562
  (base, Packed),
563
563
  struct.calcsize(fmt),
564
564
  alignment=alignment,
565
- attrs={"__fmt__": fmt},
565
+ attrs={"__fmt__": fmt, "__signed__": fmt.islower()},
566
566
  ),
567
567
  )
568
568
 
@@ -1,9 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import warnings
3
4
  from typing import TYPE_CHECKING, Any, BinaryIO
4
5
 
5
6
  from dissect.cstruct.types.base import EOF, BaseType, MetaType
6
- from dissect.cstruct.util import ENDIANNESS_TO_BYTEORDER_MAP
7
+ from dissect.cstruct.util import ENDIANNESS_TO_BYTEORDER_MAP, classproperty
7
8
 
8
9
  if TYPE_CHECKING:
9
10
  from typing_extensions import Self
@@ -14,7 +15,7 @@ if TYPE_CHECKING:
14
15
  class Int(int, BaseType):
15
16
  """Integer type that can span an arbitrary amount of bytes."""
16
17
 
17
- signed: bool
18
+ __signed__: bool
18
19
 
19
20
  @classmethod
20
21
  def _read(cls, stream: BinaryIO, *, context: dict[str, Any] | None = None, endian: Endianness) -> Self:
@@ -23,7 +24,7 @@ class Int(int, BaseType):
23
24
  if len(data) != cls.__size__:
24
25
  raise EOFError(f"Read {len(data)} bytes, but expected {cls.__size__}")
25
26
 
26
- return type.__call__(cls, int.from_bytes(data, ENDIANNESS_TO_BYTEORDER_MAP[endian], signed=cls.signed))
27
+ return type.__call__(cls, int.from_bytes(data, ENDIANNESS_TO_BYTEORDER_MAP[endian], signed=cls.__signed__))
27
28
 
28
29
  @classmethod
29
30
  def _read_array(
@@ -40,7 +41,7 @@ class Int(int, BaseType):
40
41
 
41
42
  byteorder = ENDIANNESS_TO_BYTEORDER_MAP[endian]
42
43
  return [
43
- type.__call__(cls, int.from_bytes(data[i : i + size], byteorder, signed=cls.signed))
44
+ type.__call__(cls, int.from_bytes(data[i : i + size], byteorder, signed=cls.__signed__))
44
45
  for i in range(0, length, size)
45
46
  ]
46
47
 
@@ -58,4 +59,14 @@ class Int(int, BaseType):
58
59
 
59
60
  @classmethod
60
61
  def _write(cls, stream: BinaryIO, data: int, *, endian: Endianness) -> int:
61
- return stream.write(data.to_bytes(cls.__size__, ENDIANNESS_TO_BYTEORDER_MAP[endian], signed=cls.signed))
62
+ return stream.write(data.to_bytes(cls.__size__, ENDIANNESS_TO_BYTEORDER_MAP[endian], signed=cls.__signed__))
63
+
64
+ @classproperty
65
+ def signed(cls) -> bool:
66
+ """Access whether this integer type is signed."""
67
+ warnings.warn(
68
+ "The 'signed' property is deprecated, use '__signed__' instead.",
69
+ DeprecationWarning,
70
+ stacklevel=2,
71
+ )
72
+ return cls.__signed__
@@ -1,8 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import warnings
3
4
  from typing import TYPE_CHECKING, Any, BinaryIO
4
5
 
5
6
  from dissect.cstruct.types.base import BaseType
7
+ from dissect.cstruct.util import classproperty
6
8
 
7
9
  if TYPE_CHECKING:
8
10
  from typing_extensions import Self
@@ -16,7 +18,7 @@ class LEB128(int, BaseType):
16
18
  See https://en.wikipedia.org/wiki/LEB128 for more information and an explanation of the algorithm.
17
19
  """
18
20
 
19
- signed: bool
21
+ __signed__: bool
20
22
 
21
23
  @classmethod
22
24
  def _read(cls, stream: BinaryIO, *, context: dict[str, Any] | None = None, endian: Endianness) -> Self:
@@ -33,7 +35,7 @@ class LEB128(int, BaseType):
33
35
  if (b & 0x80) == 0:
34
36
  break
35
37
 
36
- if cls.signed and b & 0x40 != 0:
38
+ if cls.__signed__ and b & 0x40 != 0:
37
39
  result |= ~0 << shift
38
40
 
39
41
  return cls.__new__(cls, result)
@@ -53,7 +55,7 @@ class LEB128(int, BaseType):
53
55
  @classmethod
54
56
  def _write(cls, stream: BinaryIO, data: int, *, endian: Endianness) -> int:
55
57
  # only write negative numbers when in signed mode
56
- if data < 0 and not cls.signed:
58
+ if data < 0 and not cls.__signed__:
57
59
  raise ValueError("Attempt to encode a negative integer using unsigned LEB128 encoding")
58
60
 
59
61
  result = bytearray()
@@ -64,8 +66,8 @@ class LEB128(int, BaseType):
64
66
 
65
67
  # function works similar for signed- and unsigned integers, except for the check when to stop
66
68
  # the encoding process.
67
- if ((cls.signed and (data == 0 and byte & 0x40 == 0)) or (data == -1 and byte & 0x40 != 0)) or (
68
- not cls.signed and data == 0
69
+ if ((cls.__signed__ and (data == 0 and byte & 0x40 == 0)) or (data == -1 and byte & 0x40 != 0)) or (
70
+ not cls.__signed__ and data == 0
69
71
  ):
70
72
  result.append(byte)
71
73
  break
@@ -75,3 +77,13 @@ class LEB128(int, BaseType):
75
77
 
76
78
  stream.write(result)
77
79
  return len(result)
80
+
81
+ @classproperty
82
+ def signed(cls) -> bool:
83
+ """Access whether this integer type is signed."""
84
+ warnings.warn(
85
+ "The 'signed' property is deprecated, use '__signed__' instead.",
86
+ DeprecationWarning,
87
+ stacklevel=2,
88
+ )
89
+ return cls.__signed__
@@ -48,6 +48,7 @@ class Packed(BaseType, Generic[T], metaclass=PackedMetaType):
48
48
  """Packed type for Python struct (un)packing."""
49
49
 
50
50
  __fmt__: str
51
+ __signed__: bool
51
52
 
52
53
  @classmethod
53
54
  def _read(cls, stream: BinaryIO, *, context: dict[str, Any] | None = None, endian: Endianness) -> Self:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.cstruct
3
- Version: 5.0.dev20
3
+ Version: 5.0.dev21
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,7 +1,7 @@
1
1
  dissect/cstruct/__init__.py,sha256=ti1VYFx1MtZuDcMks14haNvUw0IZYjRo346ChzhqPls,1647
2
2
  dissect/cstruct/bitbuffer.py,sha256=aNzY4lkWe8ffAc8j7FODXzwZc8gZwbey77UosyoYCsw,2711
3
- dissect/cstruct/compiler.py,sha256=3dlVVzU8-i-G5PKti8sMTKLF3BdQ9g6_tHaKn0KDqJA,54440
4
- dissect/cstruct/cstruct.py,sha256=mJerzPouWV29RdK5LqjGitDDMvNKcadoT2hj1zpExnM,26551
3
+ dissect/cstruct/compiler.py,sha256=cnx9_sAj6YTHgb4XB73FjuWi7Tv2m8Y7txHpuXdu5YQ,54456
4
+ dissect/cstruct/cstruct.py,sha256=mMwnu-0UmCxmuCoQlNvFs3acmQnQYZ9Ds-m6fG06HGs,26592
5
5
  dissect/cstruct/declarative.py,sha256=5ubPtOyy6L5gJMFaPcbW3xYbTijZGMp0XJGxBeed1nE,14505
6
6
  dissect/cstruct/dump.py,sha256=W5ISbaZ-1YmWXKzh-x6pDt5_SlpFRDhD9GGNyv1MnLw,19016
7
7
  dissect/cstruct/exception.py,sha256=box-mw6FoP6c3vndvYLcTeJCZVgIG8IQVPEAg4zW0C8,380
@@ -16,17 +16,17 @@ dissect/cstruct/types/base.py,sha256=NdCP9dJk6lrKPERYjR9qeD2gFzWd6krVSN4tAOqqkvI
16
16
  dissect/cstruct/types/char.py,sha256=N19R7Zzn2uMuG-ULW5X2UgmgkLvjaBj1Td7AQQI93Fg,3417
17
17
  dissect/cstruct/types/enum.py,sha256=VICmKWRuzTicq6pNKpAG_xfFzC5pVLp48qe9lFyXqoc,9029
18
18
  dissect/cstruct/types/flag.py,sha256=YxQHix8ZhK1qQX3J_Og7GJp_4JAxCwzUbUibuJeDaWQ,3479
19
- dissect/cstruct/types/int.py,sha256=9RbdrkvAI28zATM97VVORQnras0XhLaVMtdPjJwpTH4,2089
20
- dissect/cstruct/types/leb128.py,sha256=V97XTJT_Xbw1LpTwTN1OkjPHuQQAQUxd8OGuA6yEDmE,2387
21
- dissect/cstruct/types/packed.py,sha256=NgCX0YWX8SH8z47atq0f39w9MBjU_eBFJtUisUWdO-M,3867
19
+ dissect/cstruct/types/int.py,sha256=DpeCVBuNljNARTZ5jkLU8LkDVjuSRXLzIGQH4GTVUIY,2442
20
+ dissect/cstruct/types/leb128.py,sha256=UFGoHD6c6jlfhrgqKi7pcK9OdKT8U8dStCmgM1XwVXw,2776
21
+ dissect/cstruct/types/packed.py,sha256=kfZZm36Kff6iUGefkXsDOU3QrxDpVveTtMWz_a9q-lM,3888
22
22
  dissect/cstruct/types/pointer.py,sha256=FNuB9bfENWRebbKX-R6Vs6xWPMHepjvOhhomeUhr7I8,3985
23
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.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,,
26
+ dissect_cstruct-5.0.dev21.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
27
+ dissect_cstruct-5.0.dev21.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
28
+ dissect_cstruct-5.0.dev21.dist-info/METADATA,sha256=2PXj2VAGAfb8JdVmpv3QVgyYiOgrCTUtPeWZxR42N3o,12661
29
+ dissect_cstruct-5.0.dev21.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
30
+ dissect_cstruct-5.0.dev21.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
31
+ dissect_cstruct-5.0.dev21.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
32
+ dissect_cstruct-5.0.dev21.dist-info/RECORD,,