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 <dominik.b.czarnota@gmail.com>
pull/2113/head
Aryaman Sharma 2 years ago committed by GitHub
parent eb3ed7c41b
commit 6b521b2e08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,10 +6,12 @@ import codecs
import os import os
import struct import struct
import gdb
import pwnlib import pwnlib
import pwndbg.color.memory as M import pwndbg.color.memory as M
import pwndbg.commands import pwndbg.commands
import pwndbg.disasm
import pwndbg.enhance import pwndbg.enhance
import pwndbg.gdblib.arch import pwndbg.gdblib.arch
import pwndbg.gdblib.config import pwndbg.gdblib.config
@ -117,6 +119,9 @@ parser.add_argument(
type=str, type=str,
help="Target architecture", help="Target architecture",
) )
parser.add_argument(
"--asmbp", action="store_true", help="Set breakpoint for found assembly instruction"
)
parser.add_argument( parser.add_argument(
"-x", "--hex", action="store_true", help="Target is a hex-encoded (for bytes/strings)" "-x", "--hex", action="store_true", help="Target is a hex-encoded (for bytes/strings)"
) )
@ -174,6 +179,7 @@ parser.add_argument(
def search( def search(
type, type,
arch, arch,
asmbp,
hex, hex,
executable, executable,
writable, writable,
@ -242,7 +248,7 @@ def search(
value = value.encode() value = value.encode()
value += b"\x00" value += b"\x00"
elif type == "asm": elif type == "asm" or asmbp:
bits_for_arch = pwnlib.context.context.architectures.get(arch, {}).get("bits") bits_for_arch = pwnlib.context.context.architectures.get(arch, {}).get("bits")
value = pwnlib.asm.asm(value, arch=arch, bits=bits_for_arch) value = pwnlib.asm.asm(value, arch=arch, bits=bits_for_arch)
@ -257,7 +263,7 @@ def search(
return return
# If next is passed, only perform a manual search over previously saved addresses # 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)) print("Searching for instruction (assembled value): " + repr(value))
else: else:
print("Searching for value: " + repr(value)) print("Searching for value: " + repr(value))
@ -299,6 +305,9 @@ def search(
): ):
if save: if save:
saved.add(address) saved.add(address)
if asmbp:
# set breakpoint on the instruction
gdb.Breakpoint("*%#x" % address, temporary=False)
if not trunc_out or i < 20: if not trunc_out or i < 20:
print_search_hit(address) print_search_hit(address)

Loading…
Cancel
Save