Vector35 / Vector35/binaryninja-api
Cannot create unions with bitfields when creating a type with C source
Open
@emesare is already working on this.
Since Oct 28, 2025.
Core: Types
Effort: Trivial
Impact: Low
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 298
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 19
Description
Version and Platform (required):
- Binary Ninja Version: 5.2.8464-dev (ea2f9317)
- Edition: Commercial
- OS: macOS
- OS Version: 15.5
- CPU Architecture: M1
Bug Description:
Unions do not allow for bitfields when creating them via C source.
Steps To Reproduce:
- Load a binary view.
- Open "Create Types from C source"
- Create a type using the following source:
union Test
{
uint8_t foo : 1;
uint16_t bar : 2;
};
- Observe the created type will look like this where the fields are not bitfields:
union Test
{
uint8_t foo;
uint16_t bar;
};
Additional Information:
Creating the same type using the python API works as expected:
builder = binaryninja.TypeBuilder.structure()
builder.type = StructureVariant.UnionStructureType
builder.add_member_at_offset("foo", Type.int(1), offset=0, bit_position=0, bit_width=1, overwrite_existing=False)
builder.add_member_at_offset("bar", Type.int(2), offset=0, bit_position=0, bit_width=2, overwrite_existing=False)
bv.define_user_type("Test", builder.immutable_copy())
Results in:
union Test
{
char foo : 1;
int16_t bar : 2;
};
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.