def test(self): code = ('pop ecx', 'pop eax', 'jmp ecx') addr, arg, ret = 0x41414141, 0x42424242, 0x43434343 # create reader and translator from pyopenreil.utils import asm tr = CodeStorageTranslator(asm.Reader(self.arch, code, addr=addr)) cpu = Cpu(self.arch) from pyopenreil.arch import x86 stack = Stack(cpu.mem, x86.ptr_len) # set up stack arg and return address stack.push(arg) stack.push(ret) cpu.reg(x86.Registers.sp, stack.top) try: # run untill ret cpu.run(tr, addr) except CpuReadError as e: # exception on accessing to the stack if e.addr != ret: raise # check for correct return value cpu.reg('eax').val == arg
def test_code_read(self): addr, stack = 0x41414141, 0x42424242 # test code that reads itself code = ('nop', 'nop', 'nop', 'nop', 'mov eax, dword ptr [0x%X]' % addr, 'ret') # create reader and translator from pyopenreil.utils import asm tr = CodeStorageTranslator(asm.Reader(self.arch, code, addr=addr)) cpu = Cpu(ARCH_X86) # set up stack pointer cpu.reg('esp', stack) # run untill ret try: cpu.run(tr, addr) except MemReadError as e: # exception on accessing to the stack if e.addr != stack: raise # check for correct return value assert cpu.reg('eax').val == 0x90909090
def test(self): code = ('mov eax, edx', 'add eax, ecx', 'ret') addr, stack = 0x41414141, 0x42424242 # create reader and translator from pyopenreil.utils import asm tr = CodeStorageTranslator(asm.Reader(self.arch, code, addr=addr)) cpu = Cpu(self.arch) # set up stack pointer and input args cpu.reg('esp', stack) cpu.reg('ecx', 1) cpu.reg('edx', 2) # run untill ret try: cpu.run(tr, addr) except MemReadError as e: # exception on accessing to the stack if e.addr != stack: raise # check for correct return value assert cpu.reg('eax').val == 3
def test(self): code = ('pop ecx', 'pop eax', 'jmp ecx') addr, arg = 0x41414141, 0x42424242 # create reader and translator from pyopenreil.utils import asm tr = CodeStorageTranslator(asm.Reader(self.arch, code, addr=addr)) cpu = Cpu(self.arch) abi = Abi(cpu, tr) # check for correct return value assert abi.stdcall(addr, arg) == arg
def entry(self): self.widget.Symrwidget.editor.clear() self.widget.commandWidget.stopButton.setDisabled(False) code = self.widget.codeWidget.getCleanCodeAsByte(as_string=True, parse_string=True) code = tuple(synt for synt in code.split('\n') if synt) if reiluse: try: viasyntax = asm.Reader(ARCH_X86,(code),addr = 0) store = CodeStorageTranslator(viasyntax) irl = store.get_func(0) for func in irl.bb_list: self.symprint(str(func).replace(" "*4," ")) except (ReadError,OSError): self.symprint("An error occured when converting instructions into the symbolic form") return else: self.symprint("pyopenREIL does not exists")
from pyopenreil.REIL import * from pyopenreil.utils import asm # create assembly instruction reader reader = asm.Reader( ARCH_X86, ('push ebp', 'mov ebp, esp', 'xor eax, eax', 'test ecx, ecx', 'jz _quit', 'inc eax', '_quit: leave', 'ret'), addr=0) # create translator instance tr = CodeStorageTranslator(reader) # print first instruction if True: i = tr.get_insn(0) for il in i: print il.to_str() # translate first basic block # bb = tr.get_bb(0) # Get symbolic representation of basic block. # False value of temp_regs argument indicates that # we don't need expressions for REIL temp registers. # sym = bb.to_symbolic(temp_regs = False) # print SymState object # print sym