Skip to content

MSP430: Sub lifts operands in reverse order (inconsistent with Cmp) #8503

Description

@Astrael26e4

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions