Vector35 / Vector35/binaryninja-api

Cannot create unions with bitfields when creating a type with C source

Open
#7,529 3 comments 0 reactions 1 assignee View on GitHub

@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:

  1. Load a binary view.
  2. Open "Create Types from C source"
  3. Create a type using the following source:
union Test
{
    uint8_t foo : 1;
    uint16_t bar : 2;
};
  1. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.