def apply_hooks(emuHelper, addr, debug=False): """ Apply hook if needed """ # n_addr = get_next_execution_addr(addr) bRes = None addr_int = libAFL.addr2int(addr) if addr_int in D_HOOKS.keys(): if debug: print(" * * * apply_hook: %s - %s" % (str(addr), D_HOOKS[addr_int]["name"])) bRes = D_HOOKS[addr_int]["callback"](emuHelper, addr) return bRes
def write_memory(addr, data, sz=None): if type(addr) == GenericAddress: addr = libAFL.addr2int(addr) data_str = data if sz: if data < 0: raise ValueError("data must be positive") data_str = "" while data != 0: b = data & 0xff data_str += struct.pack("B", b) data = data >> 8 i = 0 while i < len(data_str): c = struct.unpack("B", data_str[i])[0] ghidra_addr = toAddr(addr + i) emuHelper.writeMemoryValue(ghidra_addr, 1, c) i += 1 return