blob: 13b902267ebec9def0709339e1e1baff4348fed1 [file] [log] [blame]
kratolp39a65292014-09-29 10:59:42 +02001#!/usr/bin/env python
2
3# Capstone by Nguyen Anh Quynnh <aquynh@gmail.com>
4# PPC Branch testing suite by kratolp
5from __future__ import print_function
6import sys
7from capstone import *
8
9CODE32 = b"\x48\x01\x05\x15" # bl .+0x10514
10CODE32 += b"\x4B\xff\xff\xfd" # bl .-0x4
11CODE32 += b"\x48\x00\x00\x0c" # b .+0xc
12CODE32 += b"\x41\x80\xff\xd8" # blt .-0x28
13CODE32 += b"\x40\x80\xff\xec" # bge .-0x14
14CODE32 += b"\x41\x84\x01\x6c" # blt cr1, .+0x16c
15CODE32 += b"\x41\x82\x00\x10" # beq .+0x10
16CODE32 += b"\x40\x82\x00\x08" # bne .+0x8
17CODE32 += b"\x40\x95\x00\x94" # ble cr5,.+0x94
18CODE32 += b"\x40\x9f\x10\x30" # bns cr5,.+0x94
19CODE32 += b"\x42\x00\xff\xd8" # bdnz .-0x28
20CODE32 += b"\x4d\x82\x00\x20" # beqlr
21CODE32 += b"\x4e\x80\x00\x20" # blr
kratolpa3f0aef2014-10-01 11:39:15 +020022CODE32 += b"\x4a\x00\x00\x02" # ba .0xfe000000
23CODE32 += b"\x41\x80\xff\xda" # blta .0xffffffd8
24CODE32 += b"\x41\x4f\xff\x17" # bdztla 4*cr3+so, .0xffffff14
25CODE32 += b"\x43\x20\x0c\x07" # bdnzla+ .0xc04
26CODE32 += b"\x4c\x00\x04\x20" # bdnzfctr lt
kratolp39a65292014-09-29 10:59:42 +020027
28_python3 = sys.version_info.major == 3
29
30all_tests = (
31 (CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, CODE32, "PPC branch instruction decoding", 0),
32)
33
34
35def to_hex(s):
36 if _python3:
37 return " ".join("0x{0:02x}".format(c) for c in s) # <-- Python 3 is OK
38 else:
39 return " ".join("0x{0:02x}".format(ord(c)) for c in s)
40
41# ## Test cs_disasm_quick()
42def test_cs_disasm_quick():
43 for (arch, mode, code, comment, syntax) in all_tests:
44 print("Platform: %s" % comment)
45 print("Code: %s" %(to_hex(code))),
46 print("Disasm:")
47 for (addr, size, mnemonic, op_str) in cs_disasm_lite(arch, mode, code, 0x1000):
48 print("0x%x:\t%s\t%s" % (addr, mnemonic, op_str))
49 print()
50
51
52if __name__ == '__main__':
53 test_cs_disasm_quick()