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

Scanner breaks ARM Thumb IT blocks incorrectly #1135

Open
uxmal opened this issue Jan 16, 2022 · 1 comment
Open

Scanner breaks ARM Thumb IT blocks incorrectly #1135

uxmal opened this issue Jan 16, 2022 · 1 comment
Assignees
Labels
bug This issue describes a defect in Reko

Comments

@uxmal
Copy link
Owner

uxmal commented Jan 16, 2022

The following sequence of ARM Thumb instructions model setting r7 to 1 or 0 depending on the value of the Z processor flag.

                "14BF" +    // ite ne
                "0127" +    // movne r7,#1
                "0027");    // mov r7,#0

If given those six bytes, the Reko ThumbRewriter class handles this correctly and generates the following RTL clusters:

l0000:
    nop
l0002:
    if (Test(EQ,Z)) branch l0004
    r7 = 1<32>
l0004:
    if (TEST(NE,Z)) branch l0006
    r7 = 0<32>

This relies on the ThumbDisassembler maintaining the state of the current IT block to perform the appropriate conditional jumps. However, the Reko Scanner create a new disassembler instance after every basic block it completes, and the new disassembler instance doesn't have the IT state set correctly. Therefore we get the following RTL:

l0000:
    nop
l0002:
    if (Test(EQ,Z)) branch l0004
    r7 = 1<32>
l0004:    <-- new basic block, so blank IT state 
    r7 = 0<32>

which generates the wrong result.

What Reko should do here is try to hang on to the ThumbRewriter (with its ThumbDisassembler inside) across the fall-through of a basic block. That way the IT` state will preserved and correct output will be obtained.

@uxmal uxmal self-assigned this Jan 16, 2022
@uxmal uxmal added the bug This issue describes a defect in Reko label Jan 16, 2022
@uxmal
Copy link
Owner Author

uxmal commented Jan 16, 2022

An example of this code in the wild is the subject binary subjects/Elf/ARM/angr-685/RTOSDemo at address 0000925C, corresponding to the procedure GPIOPadConfigGet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes a defect in Reko
Projects
None yet
Development

No branches or pull requests

1 participant