示例#1
0
def libnative_libfuncs_set_function_test():
    machine = Machine()
    mem = machine.get_mem()
    cpu = machine.get_cpu()
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    # new lib
    lib = Library.alloc(alloc, name="my.library", id_string="bla", neg_size=36)
    lib_addr = lib.get_addr()
    lib.new_lib()
    lib.fill_funcs(op_jmp, 0xCAFEBABE)
    assert lib.neg_size.val == 36
    # patch function
    lvo = -30
    addr = lib.get_addr() + lvo
    assert mem.r16(addr) == op_jmp
    assert mem.r32(addr + 2) == 0xCAFEBABE
    lf = LibFuncs(machine, alloc)
    old_addr = lf.set_function(lib_addr, lvo, 0xDEADBEEF)
    assert old_addr == 0xCAFEBABE
    assert mem.r16(addr) == op_jmp
    assert mem.r32(addr + 2) == 0xDEADBEEF
    assert lib.check_sum()
    # invalid function
    old_addr = lf.set_function(lib_addr, -36, 0)
    assert old_addr is None
    # cleanup
    lib.free()
    assert alloc.is_all_free()
示例#2
0
def libnative_libfuncs_set_function_test():
  machine = Machine()
  mem = machine.get_mem()
  cpu = machine.get_cpu()
  sp = machine.get_ram_begin() - 4
  alloc = MemoryAlloc.for_machine(machine)
  # new lib
  lib = Library.alloc(alloc, "my.library", "bla", 36)
  lib_addr = lib.get_addr()
  lib.setup()
  lib.fill_funcs(op_jmp, 0xcafebabe)
  assert lib.neg_size == 36
  # patch function
  lvo = -30
  addr = lib.get_addr() + lvo
  assert mem.r16(addr) == op_jmp
  assert mem.r32(addr+2) == 0xcafebabe
  lf = LibFuncs(machine, alloc)
  old_addr = lf.set_function(lib_addr, lvo, 0xdeadbeef)
  assert old_addr == 0xcafebabe
  assert mem.r16(addr) == op_jmp
  assert mem.r32(addr+2) == 0xdeadbeef
  assert lib.check_sum()
  # invalid function
  old_addr = lf.set_function(lib_addr, -36, 0)
  assert old_addr is None
  # cleanup
  lib.free()
  assert alloc.is_all_free()
示例#3
0
def libnative_libfuncs_set_function_test():
    machine = Machine()
    mem = machine.get_mem()
    cpu = machine.get_cpu()
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    # new lib
    lib = Library.alloc(alloc, "my.library", "bla", 36)
    lib_addr = lib.get_addr()
    lib.setup()
    lib.fill_funcs(op_jmp, 0xcafebabe)
    assert lib.neg_size == 36
    # patch function
    lvo = -30
    addr = lib.get_addr() + lvo
    assert mem.r16(addr) == op_jmp
    assert mem.r32(addr + 2) == 0xcafebabe
    lf = LibFuncs(machine, alloc)
    old_addr = lf.set_function(lib_addr, lvo, 0xdeadbeef)
    assert old_addr == 0xcafebabe
    assert mem.r16(addr) == op_jmp
    assert mem.r32(addr + 2) == 0xdeadbeef
    assert lib.check_sum()
    # invalid function
    old_addr = lf.set_function(lib_addr, -36, 0)
    assert old_addr is None
    # cleanup
    lib.free()
    assert alloc.is_all_free()
示例#4
0
 def SetFunction(self, ctx):
   lib_addr = ctx.cpu.r_reg(REG_A1)
   lvo = ctx.cpu.rs_reg(REG_A0)
   new_func = ctx.cpu.r_reg(REG_D0)
   lf = LibFuncs(ctx.machine, ctx.alloc)
   old_func = lf.set_function(lib_addr, lvo, new_func)
   log_exec.info("SetFunction: lib=%06x, lvo=%d, new_func=%06x -> old_func=%06x",
                 lib_addr, lvo, new_func, old_func)
   return old_func
示例#5
0
 def SetFunction(self, ctx):
     lib_addr = ctx.cpu.r_reg(REG_A1)
     lvo = ctx.cpu.rs_reg(REG_A0)
     new_func = ctx.cpu.r_reg(REG_D0)
     lf = LibFuncs(ctx.machine, ctx.alloc)
     old_func = lf.set_function(lib_addr, lvo, new_func)
     log_exec.info(
         "SetFunction: lib=%06x, lvo=%d, new_func=%06x -> old_func=%06x",
         lib_addr, lvo, new_func, old_func)
     return old_func