Skip to content

Commit eeca7c7

Browse files
author
Josh Watson
committed
Bug fixes
1 parent 5c20f74 commit eeca7c7

File tree

4 files changed

+13
-69
lines changed

4 files changed

+13
-69
lines changed

__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import binaryninja.binaryview
33
import binaryninja.enums
44

5-
from .calling_convention import DefaultCallingConvention
5+
from .calling_convention import DefaultCallingConvention, StackBasedCallingConvention
66
from .msp430 import MSP430
77

88
MSP430.register()
99
arch = binaryninja.architecture.Architecture['msp430']
1010
arch.register_calling_convention(DefaultCallingConvention(arch, 'default'))
11-
standalone = arch.standalone_platform
12-
standalone.default_calling_convention = arch.calling_conventions['default']
11+
arch.register_calling_convention(StackBasedCallingConvention(arch, 'stack_based'))
12+
arch.standalone_platform.default_calling_convention = arch.calling_conventions['default']
1313
binaryninja.binaryview.BinaryViewType['ELF'].register_arch(
1414
105,
1515
binaryninja.enums.Endianness.LittleEndian,

calling_convention.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from binaryninja import CallingConvention
22

33
class DefaultCallingConvention(CallingConvention):
4+
name = "Default"
45
int_arg_regs = ['r15', 'r14', 'r13', 'r12']
56
int_return_reg = 'r15'
67
high_int_return_reg = 'r14'
8+
9+
class StackBasedCallingConvention(CallingConvention):
10+
name = "StackBased"
11+
int_arg_regs = []
12+
int_return_reg = 'r15'
13+
high_int_return_reg = 'r14'

instructions.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -126,57 +126,6 @@
126126
'r15'
127127
]
128128

129-
130-
def GetOperands(instr, instruction):
131-
if instr in TYPE3_INSTRUCTIONS:
132-
return None, OFFSET, None, None
133-
134-
width = 1 if (instruction & 0x40) >> 6 else 2
135-
136-
# As is in the same place for Type 1 and 2 instructions
137-
As = (instruction & 0x30) >> 4
138-
139-
if instr in TYPE2_INSTRUCTIONS:
140-
src = Registers[instruction & 0xf]
141-
dst = None
142-
Ad = None
143-
144-
elif instr in TYPE1_INSTRUCTIONS:
145-
src = Registers[(instruction & 0xf00) >> 8]
146-
dst = Registers[instruction & 0xf]
147-
Ad = (instruction & 0x80) >> 7
148-
149-
if src == 'pc':
150-
if As == INDEXED_MODE:
151-
As = SYMBOLIC_MODE
152-
elif As == INDIRECT_AUTOINCREMENT_MODE:
153-
As = IMMEDIATE_MODE
154-
155-
elif src == 'cg':
156-
if As == REGISTER_MODE:
157-
As = CONSTANT_MODE0
158-
elif As == INDEXED_MODE:
159-
As = CONSTANT_MODE1
160-
elif As == INDIRECT_REGISTER_MODE:
161-
As = CONSTANT_MODE2
162-
else:
163-
As = CONSTANT_MODE_NEG1
164-
165-
elif src == 'sr':
166-
if As == INDEXED_MODE:
167-
As = ABSOLUTE_MODE
168-
elif As == INDIRECT_REGISTER_MODE:
169-
As = CONSTANT_MODE4
170-
elif As == INDIRECT_AUTOINCREMENT_MODE:
171-
As = CONSTANT_MODE8
172-
173-
if dst and dst == 'sr':
174-
if Ad == INDEXED_MODE:
175-
Ad = ABSOLUTE_MODE
176-
177-
return src, As, dst, Ad, width
178-
179-
180129
OperandTokens = [
181130
lambda reg, value: [ # REGISTER_MODE
182131
InstructionTextToken(InstructionTextTokenType.RegisterToken, reg)
@@ -236,19 +185,6 @@ def GetOperands(instr, instruction):
236185
]
237186

238187

239-
def GetRegisterValues(instr, instruction):
240-
if instr in TYPE1_INSTRUCTIONS:
241-
src = (instruction & 0xf00) >> 8
242-
dst = (instruction & 0xf)
243-
elif instr in TYPE2_INSTRUCTIONS:
244-
src = instruction & 0xf
245-
dst = None
246-
else:
247-
src = None
248-
dst = None
249-
250-
return src, dst
251-
252188
class Operand:
253189
def __init__(
254190
self,

lifter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def lift_and(il, instr):
213213
@staticmethod
214214
def lift_bic(il, instr):
215215
left = SourceOperandsIL[instr.dst.mode](
216-
il, instr.dst
216+
il, instr.dst.width, instr.dst.target, instr.dst.value
217217
)
218218

219219
right = il.not_expr(
@@ -484,6 +484,7 @@ def lift_rrc(il, instr):
484484
2,
485485
left,
486486
right,
487+
il.flag('c'),
487488
flags='*'
488489
)
489490

@@ -497,7 +498,7 @@ def lift_rrc(il, instr):
497498

498499
@staticmethod
499500
def lift_sub(il, instr):
500-
sub = Lifter.lift_type1(il, il.sub, instr.src, instr.dst, flags='*')
501+
sub = Lifter.lift_type1(il, il.sub, instr.dst, instr.src, flags='*')
501502

502503
il.append(
503504
DestOperandsIL[instr.dst.mode](

0 commit comments

Comments
 (0)