-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix HACK.TXT
- Loading branch information
Showing
7 changed files
with
129 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Capstone Python bindings, by billow <[email protected]> | ||
|
||
import ctypes, copy | ||
from .tricore_const import * | ||
|
||
class TriCoreOpMem(ctypes.Structure): | ||
_fields_ = ( | ||
('base', ctypes.c_uint8), | ||
('disp', ctypes.c_int32), | ||
) | ||
|
||
|
||
class TriCoreOpValue(ctypes.Union): | ||
_fields_ = ( | ||
('reg', ctypes.c_uint), | ||
('imm', ctypes.c_int32), | ||
('mem', TriCoreOpMem), | ||
) | ||
|
||
|
||
class TriCoreOp(ctypes.Structure): | ||
_fields_ = ( | ||
('type', ctypes.c_uint), | ||
('value', TriCoreOpValue), | ||
) | ||
|
||
@property | ||
def imm(self): | ||
return self.value.imm | ||
|
||
@property | ||
def reg(self): | ||
return self.value.reg | ||
|
||
@property | ||
def mem(self): | ||
return self.value.mem | ||
|
||
|
||
# Instruction structure | ||
class CsTriCore(ctypes.Structure): | ||
_fields_ = ( | ||
('op_count', ctypes.c_uint8), | ||
('operands', TriCoreOp * 8), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
|
||
# Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]> | ||
|
||
from __future__ import print_function | ||
from capstone import * | ||
from capstone.tricore import * | ||
from xprint import to_x, to_hex | ||
|
||
TRICORE_CODE = b"\x16\x01\x20\x01\x1d\x00\x02\x00\x8f\x70\x00\x11\x40\xae\x89\xee\x04\x09\x42\xf2\xe2\xf2\xc2\x11\x19" \ | ||
b"\xff\xc0\x70\x19\xff\x20\x10" | ||
|
||
all_tests = ( | ||
(CS_ARCH_TRICORE, CS_MODE_TRICORE_162, TRICORE_CODE, "TriCore"), | ||
) | ||
|
||
|
||
def print_insn_detail(insn): | ||
# print address, mnemonic and operands | ||
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str)) | ||
|
||
# "data" instruction generated by SKIPDATA option has no detail | ||
if insn.id == 0: | ||
return | ||
|
||
if len(insn.operands) > 0: | ||
print("\top_count: %u" % len(insn.operands)) | ||
c = 0 | ||
for i in insn.operands: | ||
if i.type == TRICORE_OP_REG: | ||
print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg))) | ||
if i.type == TRICORE_OP_IMM: | ||
print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x(i.imm))) | ||
if i.type == TRICORE_OP_MEM: | ||
print("\t\toperands[%u].type: MEM" % c) | ||
if i.mem.base != 0: | ||
print("\t\t\toperands[%u].mem.base: REG = %s" \ | ||
% (c, insn.reg_name(i.mem.base))) | ||
if i.mem.disp != 0: | ||
print("\t\t\toperands[%u].mem.disp: 0x%s" \ | ||
% (c, to_x(i.mem.disp))) | ||
c += 1 | ||
|
||
|
||
# ## Test class Cs | ||
def test_class(): | ||
for (arch, mode, code, comment) in all_tests: | ||
print("*" * 16) | ||
print("Platform: %s" % comment) | ||
print("Code: %s" % to_hex(code)) | ||
print("Disasm:") | ||
|
||
try: | ||
md = Cs(arch, mode) | ||
md.detail = True | ||
for insn in md.disasm(code, 0x1000): | ||
print_insn_detail(insn) | ||
print() | ||
print("0x%x:\n" % (insn.address + insn.size)) | ||
except CsError as e: | ||
print("ERROR: %s" % e) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_class() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters