Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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