예제 #1
0
파일: sefi_llvm.py 프로젝트: cantora/sefi
def new(arch):

	tm = None
	if arch == sefi.arch.x86:
		tm = TargetMachine.x86()
	elif arch == sefi.arch.x86_64:
		tm = TargetMachine.x86_64()
	elif arch == sefi.arch.arm:
		tm = TargetMachine.arm()
	elif arch == sefi.arch.thumb1:
		tm = TargetMachine.thumb()
	else:
		tm = TargetMachine.lookup(arch)

	if not tm:
		raise ArchNotSupported("llvm does not recognize " + \
								"architecture %s" % arch)
	
	try:
		llvmdasm = llvm.mc.Disassembler(tm)
	except llvm.LLVMException as e:
		raise ArchNotSupported("llvm does not have a " + \
								"disassembler for %s" % arch)

	return LLVMDasm(llvmdasm, arch)
예제 #2
0
def new(arch):

    tm = None
    if arch == sefi.arch.x86:
        tm = TargetMachine.x86()
    elif arch == sefi.arch.x86_64:
        tm = TargetMachine.x86_64()
    elif arch == sefi.arch.arm:
        tm = TargetMachine.arm()
    elif arch == sefi.arch.thumb1:
        tm = TargetMachine.thumb()
    else:
        tm = TargetMachine.lookup(arch)

    if not tm:
        raise ArchNotSupported("llvm does not recognize " + \
              "architecture %s" % arch)

    try:
        llvmdasm = llvm.mc.Disassembler(tm)
    except llvm.LLVMException as e:
        raise ArchNotSupported("llvm does not have a " + \
              "disassembler for %s" % arch)

    return LLVMDasm(llvmdasm, arch)
예제 #3
0
파일: ee.py 프로젝트: stjordanis/llvmpy
    def select_target(self, *args):
        '''get the corresponding target machine

        Accept no arguments or (triple, march, mcpu, mattrs)
        '''
        if args:
            triple, march, mcpu, mattrs = args
            ptr = self._ptr.selectTarget(triple, march, mcpu,
                                         mattrs.split(','))
        else:
            ptr = self._ptr.selectTarget()
        return TargetMachine(ptr)
예제 #4
0
파일: ee.py 프로젝트: stjordanis/llvmpy
 def create(self, tm=None):
     '''
     tm --- Optional. Provide a TargetMachine.  Ownership is transfered
     to the returned execution engine.
     '''
     if tm is not None:
         engine = self._ptr.create(tm._ptr)
     elif (sys.platform.startswith('win32')
           and getattr(self, '_use_mcjit', False)):
         # force ELF generation on MCJIT on win32
         triple = get_default_triple()
         tm = TargetMachine.new('%s-elf' % triple)
         engine = self._ptr.create(tm._ptr)
     else:
         engine = self._ptr.create()
     ee = ExecutionEngine(engine)
     ee.finalize_object()  # no effect for legacy JIT
     return ee
예제 #5
0
파일: ee.py 프로젝트: cournape/llvmpy
 def create(self, tm=None):
     '''
     tm --- Optional. Provide a TargetMachine.  Ownership is transfered
     to the returned execution engine.
     '''
     if tm is not None:
         engine = self._ptr.create(tm._ptr)
     elif (sys.platform.startswith('win32') and
                 getattr(self, '_use_mcjit', False)):
         # force ELF generation on MCJIT on win32
         triple = get_default_triple()
         tm = TargetMachine.new('%s-elf' % triple)
         engine = self._ptr.create(tm._ptr)
     else:
         engine = self._ptr.create()
     ee = ExecutionEngine(engine)
     ee.finalize_object()                # no effect for legacy JIT
     return ee
예제 #6
0
            else:
                ops = ", ".join(map(lambda op: repr(op), inst.operands()))
                if isinstance(inst, mc.BadInstr):
                    print("\t0x%x (bad) ops = %s" % (addr, ops))
                else:
                    print("\t0x%x ops = %s" % (addr, ops))

                print("\t\topcode = 0x%x, flags = 0x%x, tsflags = 0x%x" % (inst.opcode, inst.flags, inst.ts_flags))
                for line in str(inst).split("\n"):
                    print("\t\t%-24s %s" % ("".join(map(lambda b: "%02x" % b, data))+":", line.strip()))

                for bp in branch_properties:
                    print("\t\t%-22s%r" % (bp+":", getattr(inst, bp)() ))


    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",
        "\xe2\x4d\xd0\x20",
        "\xe2\x8d\xb0\x04",
        "\xe5\x0b\x00\x20",