Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
937 stars 213 forks source link

GetConstantsReferencedByInstructionIfAvailable returns incorrect value for some instructions #6102

Open SecondNewtonLaw opened 2 weeks ago

SecondNewtonLaw commented 2 weeks ago

Version and Platform (required):

Bug Description: While using the Binary Ninja C++ API, I noticed that in certain instructions the referenced constants are none, but in the dissassembly there are indeed constant references. This appears to happen for instructions that go as follows: cmp ... [rip + ...], ... or at least it did so on my light testing, however it also seems consistent with the fact that there is a relative pointer on the first operand of the instruction.

Steps To Reproduce:

  1. Obtain the instruction address that you want to get the referenced constants of.
  2. Get consts.size().
  3. The size of the referenced constants will be 0, while it uses one.

Expected Behavior: The constants provided by the API should resolve correctly.

Screenshots/Video Recording: image

Binary: The issue is not specific to the binary and can be replicated via the usage of static variables like in the following sample.

void test() {
    static bool x = false;
    if (x == false)
        x = true;
}

This code should generate the assembly that appears to show this issue.

plafosse commented 2 weeks ago

Which API specifically are you using?

SecondNewtonLaw commented 2 weeks ago

Which API specifically are you using?

The C++ API, my bad for not specifying

xusheng6 commented 1 week ago

Which API specifically are you using?

The C++ API, my bad for not specifying

We actually mean the name of the API function :)

SecondNewtonLaw commented 1 week ago

Which API specifically are you using?

The C++ API, my bad for not specifying

We actually mean the name of the API function :)

BinaryNinja::Function::GetConstantsReferencedByInstructionIfAvailable(Architecture *arch, uintptr_t addr) is the function in question