Skip to content

Missing this parameter for C++ methods with symbols #6775

Open
@SlidyBat

Description

@SlidyBat

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions