Skip to content

Missing flag lifting for Thumb2 MOVS and MVNS instructions using 32-bit encoding with optional set flags #6698

@galenbwill

Description

@galenbwill

Version and Platform (required):

  • Binary Ninja Version: 5.0

Bug Description:
When lifting instructions with an optional s suffix (set flags), such as movs, orrs, etc., they are not treated as setting flags. This can result in invalid conditionals:

Steps To Reproduce:

  1. Open a new binary, select Assemble... from the Edit menu
  2. Set the architecture to thumb2 in the dialog and enter this assembly, press Assemble:
movs r5, #0
movs r8, r0
beq 0
add r0, r0
sub r0, r8
bx lr
  1. Right click, and select Make Function at this Address... > thumb2 > thumb2. (Do not use Default (thumb2) or the hotkey P as this will create an armv7 function.)
  2. Set the view to MLIL and observe if (true)... at offset 0x00000006
  3. Set the view to HLIL and observe return arg1 * 0 as the only line of the decompiled function.

Expected Behavior:

  • MLIL at offset 6 should be if (r8 == 0)...
  • HLIL at offset 4 should be if (r8 != 0)...

Screenshots/Video Recording:
Incorrect/current behavior:

Image

Correct behavior:

Image

Additional Information:
The issue is that the disassembler returns the enumeration value for the mnemonic without the trailing s in these cases, so the lifter handles them as the non-flag setting variants.

The quick fix is to have the lifter recognize these situations and handle them accordingly. (I have this working on a local branch for now, as illustrated in the above screenshots, but it needs further testing.)

The (arguably) correct fix is to have the disassembler return the s variant of the mnemonic, but this will require fixing the disassembler generator script and regenerating the disassembler, which would be considerably more effort to execute correctly.

Metadata

Metadata

Assignees

Labels

Arch: ARM/ThumbIssues with the ARM/Thumb architecture pluginComponent: ArchitectureIssue needs changes to an architecture pluginEffort: LowIssues require < 1 week of workEffort: TrivialIssues require < 1 day of workImpact: MediumIssue is impactful with a bad, or no, workaroundLiftingissues related to LLIL lifting

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions