1 from __future__
import print_function
3 from .base
import TestBase
5 from ..disassembler
import Disassembler
, Option_UseMarkup
7 class TestDisassembler(TestBase
):
8 def test_instantiate(self
):
9 Disassembler('i686-apple-darwin9')
12 sequence
= '\x67\xe3\x81' # jcxz -127
13 triple
= 'i686-apple-darwin9'
15 disassembler
= Disassembler(triple
)
17 count
, s
= disassembler
.get_instruction(sequence
)
18 self
.assertEqual(count
, 3)
19 self
.assertEqual(s
, '\tjcxz\t-127')
21 def test_nonexistent_triple(self
):
22 with self
.assertRaisesRegex(Exception, "Could not obtain disassembler for triple"):
23 Disassembler("nonexistent-triple-raises")
25 def test_get_instructions(self
):
26 sequence
= '\x67\xe3\x81\x01\xc7' # jcxz -127; addl %eax, %edi
28 disassembler
= Disassembler('i686-apple-darwin9')
30 instructions
= list(disassembler
.get_instructions(sequence
))
31 self
.assertEqual(len(instructions
), 2)
33 self
.assertEqual(instructions
[0], (0, 3, '\tjcxz\t-127'))
34 self
.assertEqual(instructions
[1], (3, 2, '\taddl\t%eax, %edi'))
36 def test_set_options(self
):
37 sequence
= '\x10\x40\x2d\xe9'
38 triple
= 'arm-linux-android'
40 disassembler
= Disassembler(triple
)
41 disassembler
.set_options(Option_UseMarkup
)
42 count
, s
= disassembler
.get_instruction(sequence
)
44 self
.assertEqual(count
, 4)
45 self
.assertEqual(s
, '\tpush\t{<reg:r4>, <reg:lr>}')