Skip to content

Commit 876116d

Browse files
committed
This enables dumping structure data into bytearray for array of structures
Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent 52fab6b commit 876116d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

dissect/cstruct/cstruct.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@ def _write(self, stream, data):
965965

966966
return num
967967

968+
def _write_0(self, stream, data):
969+
num=0
970+
for d in data:
971+
num+=self._write(stream, d)
972+
pass
973+
return num
974+
968975
def add_fields(self, name, type_, offset=None, commentAttributes:typeCommentAttributes={}):
969976
"""Add a field to this structure.
970977

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="dissect.cstruct",
8-
version="1.0.0",
8+
version="1.2.1",
99
author="Fox-IT",
1010
description="Structure parsing in Python made easy.",
1111
long_description=long_description,

tests/test_basic.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ def test_struct_definitions():
669669
// uint32 comment
670670
uint32 b;
671671
} test, test1;
672+
673+
struct test_struct {
674+
structure _test structure[];
675+
};
672676
""", compiled=False)
673677

674678
assert c._test == c.test == c.test1
@@ -678,6 +682,10 @@ def test_struct_definitions():
678682
assert 'a' in c.test.lookup
679683
assert 'b' in c.test.lookup
680684

685+
test_struct_data = b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00'
686+
test_struct = c.test_struct(structure=c.test[2](test_struct_data))
687+
assert test_struct_data == test_struct.dumps()
688+
681689
with pytest.raises(cstruct.ParserError):
682690
c.load("""
683691
struct {

0 commit comments

Comments
 (0)