Vector35 / Vector35/binaryninja-api

Missing `this` parameter for C++ methods with symbols

Open
#6,775 8 comments 12 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Component: Core Effort: Medium 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.1.7363-dev Personal (acd6c39c)
  • OS: Mac
  • OS Version: 14.6.1
  • CPU Architecture: M1

Bug Description:
When analyzing any C++ binary that has symbols, it seems that binja tries to automatically set the function arguments based on this symbol information. However, it misses any hidden parameters, e.g. this or the return value pointer for functions that return an object.

Steps To Reproduce:

I made this small test program to demonstrate the issue:

#include <stdio.h>
#include <string.h>

class MyClass
{
public:
    void Init()
    {
        x = 1.0f;
        y = true;
        strcpy(z, "Hello");
    }

    void Print(const char* prefix)
    {
        printf("%s: x=%g y=%i z=%s\n", prefix, x, y, z);
    }

    MyClass Copy()
    {
        return *this;
    }
private:
    float x;
    bool y;
    char z[0x10];
};

int main(int argc, const char* argv[])
{
    MyClass a;
    a.Init();
    a.Print("a");

    MyClass b;
    b = a.Copy();
    b.Print("b");

    return 0;
}

Please provide all steps required to reproduce the behavior:

  1. Compile the binary with symbols g++ test.cpp -o symbols_test and open in binja
  2. Look at MyClass::Init and MyClass::Print methods and observe that they're missing the this argument
  3. Look at MyClass::Copy method and observe that it is missing return value argument and this argument
  4. Strip the binary strip symbols_test -o nosymbols_test and open in binja
  5. Look at the same methods and see that they now have the correct number of arguments (1 for Init/Print, 2 for Copy)

Incorrect output screenshot:

Image

Expected Behavior:

For thiscall methods, the implicit this parameter should be accounted for. For methods that return an object, a return value argument should also be accounted for.

For the example case above, this is what the manually fixed up output looks like:

Image

Screenshots/Video Recording:
If applicable, please add screenshots/video recording here to help explain your problem.

Binary:

test.zip

Additional Information:
Please add any other context about the problem here.

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.