Vector35 / Vector35/binaryninja-api

Support C++ inheritance syntax in type parser

Open
#7,228 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Type Parser Effort: Low Impact: Medium
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.8071-dev
  • Edition: Commercial
  • OS: macOS
  • OS Version: 15.5 (24F74)
  • CPU Architecture: arm64

Bug Description:
When importing this header file:

struct foo { int a; };
struct bar : foo { int b; };

the type bar is created as:

struct bar
{
    __padding char _0[4];
    int32_t b;
};

The field b is at the correct offset (4 instead of 0), but the space where the superclass field should be is just blank.

Expected Behavior:

I realize that this is the 'wrong' inheritance syntax and Binary Ninja has its own syntax. Sure enough, if I add __base(foo, 0) before bar, then things work as expected.

However, it's confusing to accept C++ syntax but only partially. Binary Ninja should either give a warning, or, better, just add the proper inheritance relationship in this case.

For one thing, this would be useful when importing actual C++ headers.

In my particular case, though, the header I was trying to import was not real C++ code but rather an export from IDA. Here too, it would be nice if the import would 'just work', for the sake of better interoperability between reverse engineering tools. Admittedly, fixing the inheritance issue wouldn't solve IDA header import as there were some other manual fixups required, but most of those are trivial (custom keywords like _DWORD)… I should file a separate issue about those. If you're wondering why I didn't just use the IDB importer, I tried it and unfortunately it was completely broken (making for another issue I should file).

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 with the C++ type parser path that handles struct declarations and inheritance, using the supplied foo/bar header as the reproduction. Compare the generated bar layout with the expected superclass relationship; done when importing the header preserves the inheritance relationship without requiring __base(foo, 0).

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.