Fix patch_list and patch_revert commands (#1750)

pull/1751/head
Disconnect3d 3 years ago committed by GitHub
parent addf96f9bc
commit 9c64c0e6c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save