Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type library for certain std::string::operator+=(char*) has wrong number of arguments #6400

Open
zsarge opened this issue Feb 7, 2025 · 2 comments
Labels
Component: Type Libraries Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround
Milestone

Comments

@zsarge
Copy link

zsarge commented Feb 7, 2025

Version and Platform (required):

  • Binary Ninja Version: 4.2.6455 free, 2c8da1e
  • OS: fedora
  • OS Version: 40
  • CPU Architecture: x86_64

Bug Description:

Binary Ninja does not properly represent C++'s += operator when acting on short strings.

I'm seeing the decompiled result:

std::string::operator+=(this: &var_68)
std::string::operator+=(this: &var_68)

when I would expect something like:

std::string::operator+=(this: &var_68, "k")
std::string::operator+=(this: &var_68, "car")

Steps To Reproduce:

I've attached a .zip file with my writeup and the offending binary:

issue-with-plus-equals.zip

This comes from this problem from CrackMes.

Note that all .zip files download from this website will have the password crackmes.one.

To reproduce this issue, try to open the crackme binary, and read through the checkPassword function.

Expected Behavior:

Binary Ninja should be able to represent instances where short strings are added to a C++ string object.

Screenshots:

Ghidra gets this correct. Lines 32 and 33 are what I would expect.

Ghidra - Important Section

Binary Ninja does not properly represent this, meaning that the logic is obscured and the challenge is harder to complete.

Binary Ninja

Additional Information:

I'm still learning about Binary Ninja, so it's totally possible I'm doing something wrong.

@xusheng6
Copy link
Member

It seems that our type library for function std::string::operator+= is wrong (that it does not contain the second parameter). Though I will need a second eye to confirm this

Image

@xusheng6 xusheng6 added Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround Component: Type Libraries labels Feb 11, 2025
@xusheng6 xusheng6 added this to the Gallifrey milestone Feb 11, 2025
@xusheng6 xusheng6 changed the title Issue decompiling += in C++ Type library for certain C++ fuctions have a wrong number of arguments Feb 11, 2025
@plafosse
Copy link
Member

Looks like its a problem with the libc type library:

>>> bv.type_libraries[2].get_named_object(current_symbol.raw_name)
<type: immutable:FunctionTypeClass 'class std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&(class std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* const this)'>

@plafosse plafosse changed the title Type library for certain C++ fuctions have a wrong number of arguments Type library for certain std::string::operator+=(char*) has wrong number of arguments Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Type Libraries Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround
Projects
None yet
Development

No branches or pull requests

3 participants