Vector35 / Vector35/binaryninja-api

Add the ability to add bitfield members via the `StructureBuilder::AddMember` API

Open
#7,532 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Core: Types Effort: Low Impact: Low
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

What is the feature you'd like to have?
I would like a parameter for the API function StructureBuilder::AddMember that can be used to specify a bitfield size.

Is your feature request related to a problem?
With the newly added bitfield support the way to add them to structures via the API is to call StructureBuilder::AddMemberAtOffset. The problem with this is it requires knowing the byte offset to put the field at. The offset isn't particularly trivial to determine and I would rather rely on the Binary Ninja type backend to figure out the byte offset as I believe its just Clang.

Are any alternative solutions acceptable?
I'm not sure.

Additional Information:
Calculating the byte offset of the next field isn't always obvious due to alignment. For instance consider the following structure:

struct Foobar {
    uint16_t foo;
    uint32_t bar : 23;
    uint8_t baz;
};

Due to the size of bar it is 4 byte aligned and starts at byte offset 4 within Foobar. However if it had the following definition:

struct Foobar {
    uint16_t foo;
    uint32_t bar : 15;
    uint8_t baz;
};

In this case bar starts at byte offset 2 within Foobar.

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.

Research direction

Start by locating the StructureBuilder::AddMember and StructureBuilder::AddMemberAtOffset API declarations and implementations, then inspect the existing bitfield support. Define the bitfield-size parameter and verify that AddMember can determine offsets for both Foobar examples without requiring callers to supply byte offsets.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, reverse-engineering
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.