moved the MC data type access to TargetMachine
Disassembler now simply needs a TargetMachine object and it will be able to access all the descriptor objects it needs for disassembly through the target machine.
This commit is contained in:
parent
0e265a2cc5
commit
cbf4a61a17
5 changed files with 103 additions and 88 deletions
|
|
@ -2,11 +2,11 @@ import llvm
|
|||
|
||||
if llvm.version >= (3, 4):
|
||||
|
||||
from llvm.target import TargetMachine
|
||||
from llvm import mc
|
||||
from llvm.mc import Disassembler
|
||||
from llvmpy import api
|
||||
|
||||
llvm.initialize_all_target_components()
|
||||
llvm.target.initialize_all()
|
||||
|
||||
def op_str(op):
|
||||
s = []
|
||||
|
|
@ -37,7 +37,7 @@ if llvm.version >= (3, 4):
|
|||
if inst is None:
|
||||
print("\t%r=>(bad): 0, []" % (offset))
|
||||
else:
|
||||
if isinstance(inst, mc.BadInstr):
|
||||
if isinstance(inst, mc.BadInstr):
|
||||
print("\t%r=>(bad)%r: %r" % (offset, inst, len(inst)))
|
||||
else:
|
||||
print("\t%r=>%r: %r" % (offset, inst, len(inst)))
|
||||
|
|
@ -46,11 +46,16 @@ if llvm.version >= (3, 4):
|
|||
print("\t\t%s" % op_str(op))
|
||||
|
||||
|
||||
print("x86:")
|
||||
print_instructions(Disassembler.x86(), "\x01\xc3\xc3\xcc\x90")
|
||||
print("x86-64:")
|
||||
print_instructions(Disassembler.x86_64(), "\x55\x48\x89\xe8")
|
||||
print("arm:")
|
||||
x86 = TargetMachine.x86()
|
||||
print("x86: LE=%s" % x86.is_little_endian())
|
||||
print_instructions(Disassembler(x86), "\x01\xc3\xc3\xcc\x90")
|
||||
|
||||
x86_64 = TargetMachine.x86_64()
|
||||
print("x86-64: LE=%s" % x86_64.is_little_endian())
|
||||
print_instructions(Disassembler(x86_64), "\x55\x48\x89\xe8")
|
||||
|
||||
arm = TargetMachine.arm()
|
||||
print("arm: LE=%s" % arm.is_little_endian())
|
||||
code = [
|
||||
"\xe9\x2d\x48\x00",
|
||||
"\xea\x00\x00\x06",
|
||||
|
|
@ -58,4 +63,4 @@ if llvm.version >= (3, 4):
|
|||
"\xe2\x8d\xb0\x04",
|
||||
"\xe5\x0b\x00\x20"
|
||||
]
|
||||
print_instructions(Disassembler.arm(), "".join(map(lambda s: s[::-1], code)))
|
||||
print_instructions(Disassembler(arm), "".join(map(lambda s: s[::-1], code)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue