diff options
| author | Mason Reed <mason@vector35.com> | 2025-10-07 20:40:50 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-10-23 14:29:15 -0400 |
| commit | a1960efb34f26411d87e0d59ef50b5c7eef874a7 (patch) | |
| tree | 8336c093339012ef92f226ab6971e9d1dfa0e2f6 /docs/dev | |
| parent | c35849163319ee606a28eb4d8bfd585b1f4eddcf (diff) | |
Update developer documentation for creating bitfields
Diffstat (limited to 'docs/dev')
| -rw-r--r-- | docs/dev/annotation.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/dev/annotation.md b/docs/dev/annotation.md index d350700f..f084588b 100644 --- a/docs/dev/annotation.md +++ b/docs/dev/annotation.md @@ -238,6 +238,24 @@ StructureType.create(members=[(Type.int(4), 'field_0'), (Type.int(4), 'field_4') StructureType.create(members=[(Type.int(4), 'field_0')], type=StructureVariant.ClassStructureType) ``` +#### Create Bitfields in a Structure + +To create a bitfield in a structure, you can use the `bit_position` and `bit_width` parameters when inserting a member at an offset. + +```pycon +>>> t = TypeBuilder.structure() +>>> t.insert(0, Type.int(4), "field_0") +>>> t.insert(4, Type.int(4), "bitfield_1", bit_width=4) +>>> t.insert(4, Type.int(4), "bitfield_2", bit_position=4, bit_width=4) +>>> t.members +[<int32_t field_0, offset 0x0>, <int32_t bitfield_1, offset 0x4, bit 0:4>, <int32_t bitfield_2, offset 0x4, bit 4:4>] +``` + +It is important to note the distinction between the `bit_position` and `offset` parameters. The `offset` is a byte offset +from the start of the structure, and the `bit_position` is a bit offset from the start of byte offset. The reason member +offsets are byte offsets instead of bit offsets is historical, previous versions of Binary Ninja had no concept of bitwise +structures. + #### Create Enumerations ```python |
