dissect.cstruct 5.0.dev6__py3-none-any.whl → 5.0.dev7__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.
@@ -294,8 +294,10 @@ class BaseArray(BaseType):
294
294
  if cls.null_terminated:
295
295
  return cls.type._write_0(stream, data, endian=endian)
296
296
 
297
- if not cls.dynamic and cls.num_entries != (actual_size := len(data)):
298
- raise ArraySizeError(f"Expected static array size {cls.num_entries}, got {actual_size} instead.")
297
+ if not cls.dynamic and (remaining := cls.num_entries - (actual_size := len(data))):
298
+ if remaining < 0:
299
+ raise ArraySizeError(f"Expected static array size {cls.num_entries}, got {actual_size} instead.")
300
+ data = data + [cls.type.__default__()] * remaining
299
301
 
300
302
  return cls.type._write_array(stream, data, endian=endian)
301
303
 
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from typing import TYPE_CHECKING, Any, BinaryIO
4
4
 
5
+ from dissect.cstruct.exception import ArraySizeError
5
6
  from dissect.cstruct.types.base import EOF, BaseArray, BaseType
6
7
 
7
8
  if TYPE_CHECKING:
@@ -22,15 +23,20 @@ class CharArray(bytes, BaseArray):
22
23
  return type.__call__(cls, super()._read(stream, context=context, endian=endian))
23
24
 
24
25
  @classmethod
25
- def _write(cls, stream: BinaryIO, data: bytes, *, endian: Endianness) -> int:
26
- if isinstance(data, list) and data and isinstance(data[0], int):
26
+ def _write(cls, stream: BinaryIO, data: bytes | str | list[int], *, endian: Endianness) -> int:
27
+ if isinstance(data, list):
27
28
  data = bytes(data)
28
-
29
29
  elif isinstance(data, str):
30
30
  data = data.encode("latin-1")
31
31
 
32
32
  if cls.null_terminated:
33
- return stream.write(data + b"\x00")
33
+ data += b"\x00"
34
+
35
+ if not cls.dynamic and (remaining := cls.num_entries - (actual_size := len(data))):
36
+ if remaining < 0:
37
+ raise ArraySizeError(f"Expected static array size {cls.num_entries}, got {actual_size} instead.")
38
+ data += b"\x00" * remaining
39
+
34
40
  return stream.write(data)
35
41
 
36
42
 
@@ -252,7 +252,7 @@ class StructureMetaType(MetaType):
252
252
  offset = stream.tell()
253
253
 
254
254
  if field.offset is not None and offset != struct_start + field.offset:
255
- # Field is at a specific offset, either alligned or added that way
255
+ # Field is at a specific offset, either aligned or added that way
256
256
  offset = struct_start + field.offset
257
257
  stream.seek(offset)
258
258
 
@@ -318,7 +318,7 @@ class StructureMetaType(MetaType):
318
318
  offset = stream.tell()
319
319
 
320
320
  if field.offset is not None and offset < struct_start + field.offset:
321
- # Field is at a specific offset, either alligned or added that way
321
+ # Field is at a specific offset, either aligned or added that way
322
322
  stream.write(b"\x00" * (struct_start + field.offset - offset))
323
323
  offset = struct_start + field.offset
324
324
 
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import sys
4
4
  from typing import TYPE_CHECKING, Any, BinaryIO, ClassVar
5
5
 
6
+ from dissect.cstruct.exception import ArraySizeError
6
7
  from dissect.cstruct.types.base import EOF, BaseArray, BaseType
7
8
 
8
9
  if TYPE_CHECKING:
@@ -26,6 +27,12 @@ class WcharArray(str, BaseArray):
26
27
  def _write(cls, stream: BinaryIO, data: str, *, endian: Endianness) -> int:
27
28
  if cls.null_terminated:
28
29
  data += "\x00"
30
+
31
+ if not cls.dynamic and (remaining := cls.num_entries - (actual_size := len(data))):
32
+ if remaining < 0:
33
+ raise ArraySizeError(f"Expected static array size {cls.num_entries}, got {actual_size} instead.")
34
+ data += "\x00" * remaining
35
+
29
36
  return stream.write(data.encode(Wchar.__encoding_map__[endian]))
30
37
 
31
38
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.cstruct
3
- Version: 5.0.dev6
3
+ Version: 5.0.dev7
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
@@ -10,23 +10,23 @@ dissect/cstruct/util.py,sha256=S__kLEb9HKZg_WZR4CGtXDxkIkERLKbzFTHoU8FT8tU,15313
10
10
  dissect/cstruct/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  dissect/cstruct/tools/stubgen.py,sha256=FLQieYE-MeKK31DcrDzwNUropUYHPjwdfcDb1X2L6j4,7651
12
12
  dissect/cstruct/types/__init__.py,sha256=6P71Pu94Dv7RNjZpDZ19pqzx-G0QzmQw4q0-3zWALso,911
13
- dissect/cstruct/types/base.py,sha256=TkU2a1TK1oDafz_9PTQfZuQT7g4aTRsKnG_-Q4jelsQ,12652
14
- dissect/cstruct/types/char.py,sha256=XAXlKZXbo88WJN-JPW4w4vzcuNgyvLl3Bpn8RLs9pVo,2707
13
+ dissect/cstruct/types/base.py,sha256=rU1S2FQllx7X7BQG7qMOwNa7waxAJyuTHTNwtkiAz0g,12763
14
+ dissect/cstruct/types/char.py,sha256=s4zDmnbuOjwHgcsnEihjSqgC6H3t1jsfBTYH2ykwvHU,2997
15
15
  dissect/cstruct/types/enum.py,sha256=YIWyP3H0tdxmuSI82enoULiN0YevpnU0UaY5ioBCYfI,8518
16
16
  dissect/cstruct/types/flag.py,sha256=7xxQjFEDPHSQOxBHgcc75WzPiAxflOquwr7Z7c3erLE,2347
17
17
  dissect/cstruct/types/int.py,sha256=Ewejng5pBYnQHPtzL5W0wQMJVUPYyrY8ALES8mFaabI,1324
18
18
  dissect/cstruct/types/leb128.py,sha256=V97XTJT_Xbw1LpTwTN1OkjPHuQQAQUxd8OGuA6yEDmE,2387
19
19
  dissect/cstruct/types/packed.py,sha256=78nQWm-yylgfK3858nN-XZhO5jiqyO-piGNEyPD2ps4,2458
20
20
  dissect/cstruct/types/pointer.py,sha256=eGMrB_tTnKXKmYrcqyA_12IdukXcxRG3WOeQ1dgt7lk,3927
21
- dissect/cstruct/types/structure.py,sha256=_oMqkXtiF4PFHOh2eRXlkKo0Sb9T0CtrHZMvijJWtmM,37573
21
+ dissect/cstruct/types/structure.py,sha256=7pBg0moZbszeRomFEp5CbAHZcd1J8IVTmEG9Mo2eKS0,37571
22
22
  dissect/cstruct/types/void.py,sha256=LCYnTcxsFPaxln36QEUxWuCZVioHRRckMuqtlm6tH54,1218
23
- dissect/cstruct/types/wchar.py,sha256=YwYE2T-QYYjvO-5O83_VUlzPtrjX_w0bD9Q3rtsO7sM,2870
24
- dissect_cstruct-5.0.dev6.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
25
- dissect_cstruct-5.0.dev6.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
26
- dissect_cstruct-5.0.dev6.dist-info/METADATA,sha256=i6LEcERc5fpAuARF_fyAa5tF6dDifNqK1ME9k8w7eLg,9255
27
- dissect_cstruct-5.0.dev6.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
28
- dissect_cstruct-5.0.dev6.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
29
- dissect_cstruct-5.0.dev6.dist-info/scm_file_list.json,sha256=qZZ_g1Xx93SzRIqQt_5slI4M_CHi3AeoUBF9uqiDfDQ,2306
30
- dissect_cstruct-5.0.dev6.dist-info/scm_version.json,sha256=fQVyKh0noL65fQHScjM0BBhoAJ2DxEOsu4SaVlpzeWs,162
31
- dissect_cstruct-5.0.dev6.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
32
- dissect_cstruct-5.0.dev6.dist-info/RECORD,,
23
+ dissect/cstruct/types/wchar.py,sha256=YCYlu91D9AMVpWOLbVMdpvDDURH-EqyppM5UMDU5UQw,3200
24
+ dissect_cstruct-5.0.dev7.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
25
+ dissect_cstruct-5.0.dev7.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
26
+ dissect_cstruct-5.0.dev7.dist-info/METADATA,sha256=IUF-_jFf7_GABYqAww23JWUTr-f73OKwmaICtDcOGc8,9255
27
+ dissect_cstruct-5.0.dev7.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
28
+ dissect_cstruct-5.0.dev7.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
29
+ dissect_cstruct-5.0.dev7.dist-info/scm_file_list.json,sha256=nuFWhDGL6VmjcwOB94CSfjNBblnsa9imUy8X4BLyvhw,2306
30
+ dissect_cstruct-5.0.dev7.dist-info/scm_version.json,sha256=wMGNV4ui6dgAUOW0hK23797wTuOlVvhVvvLFz_dXXFk,162
31
+ dissect_cstruct-5.0.dev7.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
32
+ dissect_cstruct-5.0.dev7.dist-info/RECORD,,
@@ -1,78 +1,78 @@
1
1
  {
2
2
  "files": [
3
- "README.md",
4
- "tox.ini",
5
- "LICENSE",
6
- "pyproject.toml",
3
+ ".gitignore",
7
4
  "COPYRIGHT",
5
+ "README.md",
8
6
  "CHANGELOG.md",
9
7
  ".git-blame-ignore-revs",
8
+ "tox.ini",
10
9
  ".gitattributes",
10
+ "pyproject.toml",
11
11
  "MANIFEST.in",
12
- ".gitignore",
13
- "dissect/cstruct/cstruct.py",
14
- "dissect/cstruct/__init__.py",
12
+ "LICENSE",
13
+ ".github/pull_request_template.md",
14
+ ".github/workflows/dissect-ci.yml",
15
+ "dissect/cstruct/parser.py",
15
16
  "dissect/cstruct/compiler.py",
16
- "dissect/cstruct/expression.py",
17
17
  "dissect/cstruct/exception.py",
18
- "dissect/cstruct/parser.py",
19
- "dissect/cstruct/lexer.py",
20
- "dissect/cstruct/bitbuffer.py",
21
18
  "dissect/cstruct/util.py",
22
- "dissect/cstruct/types/int.py",
23
- "dissect/cstruct/types/__init__.py",
24
- "dissect/cstruct/types/leb128.py",
25
- "dissect/cstruct/types/flag.py",
26
- "dissect/cstruct/types/void.py",
27
- "dissect/cstruct/types/char.py",
19
+ "dissect/cstruct/cstruct.py",
20
+ "dissect/cstruct/bitbuffer.py",
21
+ "dissect/cstruct/lexer.py",
22
+ "dissect/cstruct/expression.py",
23
+ "dissect/cstruct/__init__.py",
24
+ "dissect/cstruct/types/base.py",
28
25
  "dissect/cstruct/types/pointer.py",
29
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",
30
31
  "dissect/cstruct/types/enum.py",
31
- "dissect/cstruct/types/base.py",
32
+ "dissect/cstruct/types/char.py",
32
33
  "dissect/cstruct/types/wchar.py",
33
- "dissect/cstruct/types/packed.py",
34
- "dissect/cstruct/tools/__init__.py",
34
+ "dissect/cstruct/types/leb128.py",
35
+ "dissect/cstruct/types/__init__.py",
35
36
  "dissect/cstruct/tools/stubgen.py",
36
- "tests/test_types_char.py",
37
- "tests/test_ctypes.py",
38
- "tests/test_types_custom.py",
39
- "tests/__init__.py",
40
- "tests/test_types_leb128.py",
41
- "tests/test_types_union.py",
42
- "tests/test_tools_stubgen.py",
43
- "tests/test_basic.py",
44
- "tests/test_lexer.py",
45
- "tests/test_types_int.py",
46
- "tests/test_expression.py",
47
- "tests/utils.py",
48
- "tests/test_align.py",
49
- "tests/test_utils.py",
50
- "tests/test_compiler.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",
51
43
  "tests/test_types_enum.py",
44
+ "tests/test_types_pointer.py",
45
+ "tests/test_types_leb128.py",
46
+ "tests/test_annotations.py",
52
47
  "tests/test_types_wchar.py",
53
- "tests/test_bitfield.py",
54
- "tests/test_types_structure.py",
55
48
  "tests/test_parser.py",
56
- "tests/test_annotations.py",
49
+ "tests/test_ctypes.py",
50
+ "tests/test_bitbuffer.py",
57
51
  "tests/conftest.py",
58
- "tests/test_types_void.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",
59
60
  "tests/test_types_flag.py",
60
61
  "tests/test_benchmark.py",
61
- "tests/test_types_pointer.py",
62
- "tests/test_types_packed.py",
62
+ "tests/test_types_char.py",
63
+ "tests/test_compiler.py",
64
+ "tests/test_types_int.py",
65
+ "tests/test_types_void.py",
63
66
  "tests/test_types_base.py",
64
- "tests/test_bitbuffer.py",
65
- "tests/_data/testdef.txt",
66
- "tests/_docs/__init__.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",
67
73
  "tests/_docs/Makefile",
68
74
  "tests/_docs/index.rst",
69
- "tests/_docs/conf.py",
70
- "examples/secdesc.py",
71
- "examples/disk.py",
72
- "examples/pe.py",
73
- "examples/mirai.py",
74
- "examples/protobuf.py",
75
- ".github/pull_request_template.md",
76
- ".github/workflows/dissect-ci.yml"
75
+ "tests/_docs/__init__.py",
76
+ "tests/_data/testdef.txt"
77
77
  ]
78
78
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "5.0.dev0",
3
+ "distance": 7,
4
+ "node": "g32253fe9f286383a8bda6b953c7c85571cd89833",
5
+ "dirty": true,
6
+ "branch": "main",
7
+ "node_date": "2026-07-20"
8
+ }
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "5.0.dev0",
3
- "distance": 6,
4
- "node": "g8fd15061a9f9618417a62277bc6f2d625768fdd2",
5
- "dirty": true,
6
- "branch": "main",
7
- "node_date": "2026-07-16"
8
- }