Skip to content

Commit

Permalink
Merge pull request #8 from ACRIOS-Systems/feature/allowArrayOfStructures
Browse files Browse the repository at this point in the history
This enables dumping structure data into bytearray for array of structures
  • Loading branch information
Hadatko authored Aug 3, 2022
2 parents 52fab6b + 876116d commit 2fbcb1c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions dissect/cstruct/cstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@ def _write(self, stream, data):

return num

def _write_0(self, stream, data):
num=0
for d in data:
num+=self._write(stream, d)
pass
return num

def add_fields(self, name, type_, offset=None, commentAttributes:typeCommentAttributes={}):
"""Add a field to this structure.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="dissect.cstruct",
version="1.0.0",
version="1.2.1",
author="Fox-IT",
description="Structure parsing in Python made easy.",
long_description=long_description,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,10 @@ def test_struct_definitions():
// uint32 comment
uint32 b;
} test, test1;
struct test_struct {
structure _test structure[];
};
""", compiled=False)

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

test_struct_data = b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00'
test_struct = c.test_struct(structure=c.test[2](test_struct_data))
assert test_struct_data == test_struct.dumps()

with pytest.raises(cstruct.ParserError):
c.load("""
struct {
Expand Down

0 comments on commit 2fbcb1c

Please sign in to comment.