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

PCode: fix bug in pcode's SequenceNumber.java #6410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noobone123
Copy link

@noobone123 noobone123 commented Apr 11, 2024

Hello.
This PR is related to a Potential Comparison Logic Issue in pcode's SequenceNumber.java.

When I try to analyze High PCode (PcodeOpAST) from decompiler using following code

Iterator<PcodeOpAST> opiter = high.getPcodeOps();

I Found PcodeOpAST's order is wrong.
For Example, *(int *)(param_1 + 0x24) has following PcodeOpAST order get from getPcodeOps()

(ram, 0x116e40, 80, 0) => (unique, 0x10000148, 8), INT_ADD, (register, 0x38, 8)[param_1], (const, 0x24, 8)
(ram, 0x116e40, 81, 2) => (unique, 0xc200, 4), LOAD, (const, 0x1b1, 4), (unique, 0x3100, 8)
(ram, 0x116e40, 714, 1) => (unique, 0x3100, 8), CAST, (unique, 0x10000148, 8)

But what we expected is

(ram, 0x116e40, 80, 0) => (unique, 0x10000148, 8), INT_ADD, (register, 0x38, 8)[param_1], (const, 0x24, 8)
(ram, 0x116e40, 714, 1) => (unique, 0x3100, 8), CAST, (unique, 0x10000148, 8)
(ram, 0x116e40, 81, 2) => (unique, 0xc200, 4), LOAD, (const, 0x1b1, 4), (unique, 0x3100, 8)

So finally I found there maybe a issue in SequenceNumber's compareTo method, which can affect the result of
method getPcodeOps().

In the compareTo method, sequence numbers are first compared based on their instruction address pc. If the addresses differ, the comparison result is determined by the outcome of comparing these addresses. If the addresses are the same, then the comparison is based on the values of the uniq field.
However, I think the correct logic is to compare the order field after comparing address pc, so as to ensure the correct order of PCodeAST and not affect the results of subsequent program analysis.

@noobone123 noobone123 changed the title fix bug in pcode's SequenceNumber.java PCode: fix bug in pcode's SequenceNumber.java Apr 11, 2024
@ryanmkurtz ryanmkurtz added the Status: Triage Information is being gathered label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Information is being gathered
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants