Skip to content

Support C++ inheritance syntax in type parser #7228

Description

@comex

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).

Activity

  1. added
    State: Awaiting Triage
    on Aug 12, 2025
  2. added this to the Io milestone on Aug 12, 2025
  3. CouleeApps commented on Aug 13, 2025

    @CouleeApps
    Member

    This is a known limitation of our support for parsing C++ as of now. It would probably be simple to handle single direct inheritance, but supporting broader C++ concepts like multiple or virtual inheritance is likely to be a significant task.

    I have unfinished code from 2022 attempting to add this for simple cases. It may be worth dusting off and seeing if it can be merged.

  4. added
    Component: Type Parser
    Effort: Low
    Impact: Medium
    and removed
    State: Awaiting Triage
    on Aug 13, 2025
  5. removed their assignment
    on Aug 13, 2025
  6. changed the title [-]Confusing behavior when importing header file using C++ inheritance syntax[/-] [+]Support C++ inheritance syntax in type parser[/+] on Aug 13, 2025
  7. removed this from the Io milestone on Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Type ParserEffort: LowImpact: Medium

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions