c_struct_data_parser
Intended to facilitate declarative, dynamic definition of C data structures.
The library will autogenerate a parser which you can connect to a BytesReader or some IO based variant.
You're better off looking at https://github.com/fox-it/dissect.cstruct
Examples from test_basic.py:
Struct2Int = create_struct_definition(
"Struct2Int",
{
"value_a": Int4Definition,
"value_b": Int4Definition,
},
)
def test_struct2Int() -> None:
value_a = 0x12345678
value_b = 0x99887766
bs = b"".join(map(int_to_le_bytes_4, [value_a, value_b]))
bytes_reader = BytesReader(address=0, bs=bs)
struct_2_int, new_reader = Struct2Int.parser(bytes_reader)
assert struct_2_int.value_a.value == value_a
assert struct_2_int.value_b.value == value_b
print(struct_2_int)
BitFieldsExample = create_bit_fields_definition(
"BitFieldsExample",
Int4Definition,
{
"field_a": 4,
"reserved_1": 5,
"field_b": 5,
},
)
def test_bit_fields() -> None:
val = 0x123456
bs = int_to_le_bytes_4(val)
bytes_reader = BytesReader(address=0, bs=bs)
bit_fields_example, new_reader = BitFieldsExample.parser(bytes_reader)
assert bit_fields_example.field_a.value == val & 0xF
assert bit_fields_example.field_b.value == (val >> 9) & 0x1F
print(bit_fields_example)
Struct2IntPointer = create_pointer_definition(
Struct2Int,
Int4Definition,
)
def test_pointer_type() -> None:
value_a = 0x12345678
value_b = 0x99887766
bs_struct = b"".join(map(int_to_le_bytes_4, [value_a, value_b]))
bs_pointer = int_to_le_bytes_4(0x2000)
bs = b"".join([bs_struct, bs_pointer])
bytes_reader = BytesReader(address=0x2000, bs=bs)
struct_2_int, new_reader = Struct2Int.parser(bytes_reader)
assert struct_2_int.value_a.value == value_a
assert struct_2_int.value_b.value == value_b
p_struct_2_int, new_reader_2 = Struct2IntPointer.parser(new_reader)
print(p_struct_2_int)
struct_2_int_copy = p_struct_2_int.resolve(new_reader_2)
assert struct_2_int_copy.value_a.value == value_a
assert struct_2_int_copy.value_b.value == value_b
Metadata
Release files for c-struct-data-parser 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| c_struct_data_parser-0.5.2-py3-none-any.whl | Python 3 | none | any | Details for c_struct_data_parser-0.5.2-py3-none-any.whl |
Release files / c_struct_data_parser-0.5.2-py3-none-any.whl
| Download URL | c_struct_data_parser-0.5.2-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4db0a8e28ed4fb81c5e1d8dbab650f14a60a254144ef74037a241619a6b8a9e
|
|
BLAKE2b-256 checksum How to use checksums |
729638955aaa6db6e39afb52f585cb3fa025bc95abc0f3361431e48a3a27a98d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.8
|
Security for c-struct-data-parser 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.