implemented binding for MCDisassembler.getInstruction

also added new llvm.mc module to act as higher level
python access to the MC section of LLVM (added Instr
and Disassembler classes).
This commit is contained in:
anthony cantor 2013-08-14 00:53:37 -06:00 • committed by Siu Kwan Lam
commit 818c9289fc
5 changed files with 176 additions and 13 deletions

View file

@ -0,0 +1,31 @@
import llvm
from llvm import mc
from llvm.mc import Disassembler
from llvmpy import api
llvm.initialize_all_target_components()
def print_instructions(dasm, bs):
for (offset, inst) in dasm.decode(bs):
if inst is None:
print("\t%r=>(bad): 0, []" % (offset))
elif isinstance(inst, mc.BadInstr):
print("\t%r=>(bad)%r: %r, %r" % (offset, inst, len(inst), inst.operands()))
else:
print("\t%r=>%r: %r, %r" % (offset, inst, len(inst), inst.operands()))
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:")
#code = "\xe9\x2d\x40\x08\xe5\x9f\x00\x0c\xe5\x9f\x10\x0c" + \
# "\xe5\x9f\x20\x0c\xe5\x9f\x30\x0c\xeb\xff\xff\xf6"
#print_instructions(Disassembler.arm(), code)