Encode `bytes`-typed strings passed to the `search` command (#2458)

pull/2459/head
Matt. 1 year ago committed by GitHub
parent 0883e28969
commit 10d01abbc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -255,6 +255,26 @@ def search(
bits_for_arch = pwnlib.context.context.architectures.get(arch, {}).get("bits")
value = pwnlib.asm.asm(value, arch=arch, bits=bits_for_arch)
# `pwndbg.search.search` expects a `bytes` object for its pattern. Convert the string pattern we
# were given to a bytes object by encoding it as an UTF-8 byte sequence. This matches the behavior
# we previously got by calling `gdb.Inferior.search_memory` with an `str`, since right about GDB
# version 7.x or 8.x[1], as it uses a `Py_buffer` object populated with an `'s*'` pattern, which
# has been encoding `str` object as a UTF-8 byte sequence since Python 3.1[2].
#
# [1]: https://sourceware.org/git/?p=binutils-gdb.git;a=blame;f=gdb/python/py-inferior.c;h=a1042ee72ac733091f7572bc04b072546d3c1519;hb=23c84db5b3cb4e8a0d555c76e1a0ab56dc8355f3
# [2]: https://docs.python.org/3.1/c-api/arg.html#strings-and-buffers
elif type == "bytes":
try:
value = value.encode("utf-8")
except UnicodeError as what:
print(
message.error(
f"Invalid pattern '{value}'. Patterns of type `bytes` must be encodable in UTF-8: {what}"
)
)
return
# Find the mappings that we're looking for
mappings = pwndbg.aglib.vmmap.get()

Loading…
Cancel
Save