Skip to content

Commit 8dbf9e1

Browse files
author
Josh Watson
committed
Some improvements
- Added dint and halting to lifter - Avoid setting the stack to a constant value for lifting - Make 'sr' a global_regs to fix calling conventions -
1 parent eeca7c7 commit 8dbf9e1

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

instructions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ def decode(cls, data, address):
352352
mnemonic = 'br'
353353
emulated = True
354354

355+
elif (
356+
mnemonic == 'bis' and
357+
dst.target == 'sr' and
358+
src.value == 0xf0
359+
):
360+
return cls('dint', length=length, emulated=True)
361+
355362
return cls(
356363
mnemonic,
357364
type_,

lifter.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from binaryninja import (LLIL_TEMP, Architecture, LowLevelILFlagCondition,
22
LowLevelILLabel, LowLevelILOperation)
33

4-
from .instructions import IMMEDIATE_MODE, INDIRECT_AUTOINCREMENT_MODE
4+
from .instructions import IMMEDIATE_MODE, INDIRECT_AUTOINCREMENT_MODE, REGISTER_MODE
55

66
SourceOperandsIL = [
77
# REGISTER_MODE
@@ -332,6 +332,14 @@ def lift_cmp(il, instr):
332332
def lift_dadd(il, instr):
333333
il.append(il.unimplemented())
334334

335+
@staticmethod
336+
def lift_dint(il, instr):
337+
pass
338+
339+
@staticmethod
340+
def lift_hlt(il, instr):
341+
il.append(il.no_ret())
342+
335343
@staticmethod
336344
def lift_jge(il, instr):
337345
cond_branch(
@@ -408,6 +416,12 @@ def lift_jz(il, instr):
408416

409417
@staticmethod
410418
def lift_mov(il, instr):
419+
# avoid setting stack pointer to a constant
420+
if (instr.src.mode == IMMEDIATE_MODE and
421+
instr.dst.target == 'sp' and
422+
instr.dst.mode == REGISTER_MODE):
423+
return
424+
411425
src = SourceOperandsIL[instr.src.mode](
412426
il, instr.src.width, instr.src.target, instr.src.value
413427
)

msp430.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import struct
2-
31
from binaryninja import (Architecture, FlagRole, LowLevelILFlagCondition,
42
RegisterInfo, log_error, InstructionInfo, BranchType, InstructionTextToken, InstructionTextTokenType)
53

@@ -10,6 +8,8 @@ class MSP430(Architecture):
108
name = 'msp430'
119
address_size = 2
1210
default_int_size = 2
11+
global_regs = ['sr']
12+
stack_pointer = 'sp'
1313

1414
regs = {r: RegisterInfo(r, 2) for r in Registers}
1515

@@ -42,8 +42,6 @@ class MSP430(Architecture):
4242
LowLevelILFlagCondition.LLFC_POS: ['n']
4343
}
4444

45-
stack_pointer = 'sp'
46-
4745
def perform_get_instruction_info(self, data, addr):
4846
instr = Instruction.decode(data, addr)
4947

@@ -81,6 +79,15 @@ def perform_get_instruction_low_level_il(self, data, addr, il):
8179

8280
if instr is None:
8381
return None
82+
83+
# Halting the system means turning off interrupts and just looping
84+
# indefinitely
85+
if instr.mnemonic == 'dint':
86+
next_instr = Instruction.decode(
87+
data[instr.length:], addr + instr.length
88+
)
89+
if next_instr.mnemonic == 'jmp' and next_instr.src.value == addr:
90+
instr.mnemonic = 'hlt'
8491

8592
Lifter.lift(il, instr)
8693

0 commit comments

Comments
 (0)