binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Remove dead partial stores of return registers when possible

Open qwerty01 opened this issue 1 year ago • 0 comments

Version and Platform (required):

  • Binary Ninja Version: 4.2.6188-dev (ab61b8dc)
  • OS: Windows 11
  • OS Version: 23H2
  • CPU Architecture: x86-64

Bug Description: In function sub_180001160 of the attached binary, result is defined as a single variable, stored in rax, but before each return, the variable should be split and merged with the return value. Binary ninja correctly shows just return 0 and return 1, but the stores into RAX for the return values are still shown when they should be hidden.

Steps To Reproduce: Open the attached binary and let analysis finish.

Expected Behavior: the stores into result before each of the returns should be hidden.

Screenshots/Video Recording: Initial with return value changed to bool and reanalyzed: image Split into new variables (which binja warns could be incorrect): image Each new variable set to bool, which finally removes the store: image

Binary:

Source code of the function:

  • https://github.com/Lachee/unity-named-pipes/blob/master/UnityNamedPipe.Native/connection_win.cpp#L17

Additional Information:

  • The source code is also just one line instead of split with an if statement: return handle != NULL && isOpened && handle != INVALID_HANDLE_VALUE;
  • The fully reversed function looks like this: image

qwerty01 avatar Oct 12 '24 16:10 qwerty01