Vector35 / Vector35/binaryninja-api
MSP430: Sub lifts operands in reverse order (inconsistent with Cmp)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 298
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 19
Description
Version and Platform (required):
- Binary Ninja Version: 5.0.7648
- Edition: Non-Commercial
- OS: Ubuntu Linux
- OS Version: 24.04
- CPU Architecture: x64
Bug Description:
The MSP430 lifter emits sub with its operands reversed. MSP430 defines sub src, dst as computing dst - src, but the lifter produces src - dst.
Cmp in the same file (arch/msp430/src/lift.rs) is correct, and the two are inconsistent:
// Instruction::Sub
il.sub(size, src, dest)
// Instruction::Cmp
il.sub(size, dest, src)
Steps To Reproduce:
Load 3b 80 02 24 as msp430 (sub #0x2402, r11).
Expected LLIL: r11 = r11 - 0x2402
Actual LLIL: r11 = 0x2402 - r11
Binary:
printf '\x3b\x80\x02\x24' > sub_repro.bin in a terminal.
Possible solution:
Switch src and dest in il.sub(size, src, dest), in the case Instruction::Sub(inst) of the file arch/msp430/src/lift.rs.
Notes:
Constant-generator forms (dec, decd) are unaffected -- they take a different code path, which lifts correctly.
Impact:
Produces plausible but incorrect decompilation for any length or offset computation using sub
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open arch/msp430/src/lift.rs and inspect the Instruction::Sub case alongside Instruction::Cmp. Reproduce with printf '\x3b\x80\x02\x24' > sub_repro.bin and load it as MSP430. Done means sub #0x2402, r11 produces LLIL r11 = r11 - 0x2402 while constant-generator forms remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- reverse-engineering
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100