def main(): buf = assemble_text(test_code, [("L_MAIN", 0)]) mdis = dis_engine(buf) disasm = mdis.dis_multibloc(0) ir = ir_a_x86_64(mdis.symbol_pool) for bbl in disasm: ir.add_bloc(bbl) symbols_init = {} for i, r in enumerate(all_regs_ids): symbols_init[r] = all_regs_ids_init[i] conds = find_goal(ir, 0, symbols_init, rax_is_one) if conds == None: print "Goal was not found" sys.exit(-1) solver = z3.Solver() for lval, rval in conds: z3_cond = Translator.to_language("z3").from_expr(lval) solver.add(z3_cond == int(rval.arg)) rslt = solver.check() if rslt == z3.sat: m = solver.model() for var in m: print "%s: %d" % (var.name(), m[var].as_long()) else: print "No solution" sys.exit(-1)
def main(): native_code = assemble_text(asm_helloworld, [("L_MAIN", 0)]) mach = Machine("x86_64") jitter = mach.jitter(jit_type="tcc") run_addr =0x40000000 jitter.init_stack() jitter.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, native_code) jitter.push_uint64_t(0xdeadbeef) jitter.add_breakpoint(0xdeadbeef, on_exit) jitter.jit.log_mn = True jitter.init_run(run_addr) jitter.continue_run()
def main(): sc = assemble_text(asm_helloworld, [("L_MAIN", 0)]) mach = Machine("x86_64") jitter = mach.jitter(jit_type="tcc") run_addr = 0x40000000 jitter.init_stack() jitter.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, sc) jitter.push_uint64_t(0xdeadbeef) jitter.add_breakpoint(0xdeadbeef, on_exit) #jitter.jit.log_regs = True jitter.jit.log_mn = True init_syscall(jitter) jitter.vm.add_memory_page(ADDR_COUNTER, PAGE_READ | PAGE_WRITE, "\x00" * 8) jitter.init_run(run_addr) jitter.continue_run() print "MOV: %d" % unpack("I", jitter.vm.get_mem(ADDR_COUNTER, 4))[0]
def main(): sc = assemble_text(asm_helloworld, [("L_MAIN", 0)]) mach = Machine("x86_64") jitter = mach.jitter(jit_type="tcc") run_addr =0x40000000 jitter.init_stack() jitter.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, sc) jitter.push_uint64_t(0xdeadbeef) jitter.add_breakpoint(0xdeadbeef, on_exit) #jitter.jit.log_regs = True jitter.jit.log_mn = True init_syscall(jitter) jitter.vm.add_memory_page(ADDR_COUNTER, PAGE_READ | PAGE_WRITE, "\x00" * 8) jitter.init_run(run_addr) jitter.continue_run() print "MOV: %d" % unpack("I", jitter.vm.get_mem(ADDR_COUNTER, 4))[0]