From 6b521b2e089a3a37509dbf89f35c59281cfb9e1b Mon Sep 17 00:00:00 2001 From: Aryaman Sharma <72215253+TheLazron@users.noreply.github.com> Date: Tue, 9 Apr 2024 23:17:39 +0530 Subject: [PATCH] search --asm: set breakpoint on found instructions (#2103) * feat:breakpoint on asm search results * formatted changes * --asmbp as an independent flag * Update pwndbg/commands/search.py --------- Co-authored-by: Disconnect3d --- pwndbg/commands/search.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pwndbg/commands/search.py b/pwndbg/commands/search.py index ab2eabd90..cb334406c 100644 --- a/pwndbg/commands/search.py +++ b/pwndbg/commands/search.py @@ -6,10 +6,12 @@ import codecs import os import struct +import gdb import pwnlib import pwndbg.color.memory as M import pwndbg.commands +import pwndbg.disasm import pwndbg.enhance import pwndbg.gdblib.arch import pwndbg.gdblib.config @@ -117,6 +119,9 @@ parser.add_argument( type=str, help="Target architecture", ) +parser.add_argument( + "--asmbp", action="store_true", help="Set breakpoint for found assembly instruction" +) parser.add_argument( "-x", "--hex", action="store_true", help="Target is a hex-encoded (for bytes/strings)" ) @@ -174,6 +179,7 @@ parser.add_argument( def search( type, arch, + asmbp, hex, executable, writable, @@ -242,7 +248,7 @@ def search( value = value.encode() value += b"\x00" - elif type == "asm": + elif type == "asm" or asmbp: bits_for_arch = pwnlib.context.context.architectures.get(arch, {}).get("bits") value = pwnlib.asm.asm(value, arch=arch, bits=bits_for_arch) @@ -257,7 +263,7 @@ def search( return # If next is passed, only perform a manual search over previously saved addresses - if type == "asm": + if type == "asm" or asmbp: print("Searching for instruction (assembled value): " + repr(value)) else: print("Searching for value: " + repr(value)) @@ -299,6 +305,9 @@ def search( ): if save: saved.add(address) + if asmbp: + # set breakpoint on the instruction + gdb.Breakpoint("*%#x" % address, temporary=False) if not trunc_out or i < 20: print_search_hit(address)