|
|
|
|
@ -22,6 +22,9 @@ parser.add_argument("ins", type=str, help="instruction[s]")
|
|
|
|
|
@pwndbg.commands.ArgparsedCommand(parser)
|
|
|
|
|
@pwndbg.commands.OnlyWhenRunning
|
|
|
|
|
def patch(address, ins) -> None:
|
|
|
|
|
# Make sure that any gdb.Value object is converted to int
|
|
|
|
|
address = int(address)
|
|
|
|
|
|
|
|
|
|
new_mem = asm(ins)
|
|
|
|
|
|
|
|
|
|
old_mem = pwndbg.gdblib.memory.read(address, len(new_mem))
|
|
|
|
|
@ -40,6 +43,9 @@ parser2.add_argument("address", type=int, help="Address to revert patch on")
|
|
|
|
|
@pwndbg.commands.ArgparsedCommand(parser2)
|
|
|
|
|
@pwndbg.commands.OnlyWhenRunning
|
|
|
|
|
def patch_revert(address) -> None:
|
|
|
|
|
# Make sure that any gdb.Value object is converted to int
|
|
|
|
|
address = int(address)
|
|
|
|
|
|
|
|
|
|
if not patches:
|
|
|
|
|
print(message.notice("No patches to revert"))
|
|
|
|
|
return
|
|
|
|
|
@ -49,9 +55,12 @@ def patch_revert(address) -> None:
|
|
|
|
|
pwndbg.gdblib.memory.write(addr, old)
|
|
|
|
|
print(message.notice("Reverted patch at %#x" % addr))
|
|
|
|
|
patches.clear()
|
|
|
|
|
else:
|
|
|
|
|
old, _new = patches[address]
|
|
|
|
|
elif address in patches:
|
|
|
|
|
old, _new = patches.pop(address)
|
|
|
|
|
pwndbg.gdblib.memory.write(address, old)
|
|
|
|
|
print(message.notice("Reverted patch at %#x" % address))
|
|
|
|
|
else:
|
|
|
|
|
print(message.error("Address %#x not found in patch list" % address))
|
|
|
|
|
|
|
|
|
|
pwndbg.lib.cache.clear_caches()
|
|
|
|
|
|
|
|
|
|
@ -73,9 +82,9 @@ def patch_list() -> None:
|
|
|
|
|
|
|
|
|
|
print(
|
|
|
|
|
message.hint("Patch at"),
|
|
|
|
|
message.warning("%#x:" % addr),
|
|
|
|
|
message.hint("from"),
|
|
|
|
|
message.warning(old_insns.replace("\n", "; ")),
|
|
|
|
|
message.hint("to"),
|
|
|
|
|
message.warning(new_insns.replace("\n", "; ")),
|
|
|
|
|
message.warn("%#x:" % addr),
|
|
|
|
|
message.hint("\n from:"),
|
|
|
|
|
message.warn(old_insns.replace("\n", "; ")),
|
|
|
|
|
message.hint("\n to :"),
|
|
|
|
|
message.warn(new_insns.replace("\n", "; ")),
|
|
|
|
|
)
|
|
|
|
|
|