Skip to content

Instantly share code, notes, and snippets.

@meowmeowxw
Last active October 30, 2023 19:39
Show Gist options
  • Save meowmeowxw/f47070f5f9751a7a7214e23a5bf666e8 to your computer and use it in GitHub Desktop.
Save meowmeowxw/f47070f5f9751a7a7214e23a5bf666e8 to your computer and use it in GitHub Desktop.
gdb-vaddress-to-mapping
import gdb
import re
# usage:
# (gdb) vaddr-to-mapping 0x7ffff7e15100
class VaddressToMapping(gdb.Command):
def __init__ (self):
super(VaddressToMapping, self).__init__("vaddr-to-mapping", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
if arg.startswith("0x"):
addr = int(arg, 16)
else:
addr = int(arg)
lines = gdb.execute("info proc mappings", to_string=True)
found = False
for line in lines.split("\n"):
groups = re.findall(r"(0x[0-9a-f]+)", line)
if groups:
groups = list(map(lambda x: int(x, 16), groups))
base_addr = groups[0]
end_addr = groups[1]
size = groups[2]
offset = groups[3]
diff = end_addr - addr
if diff > 0 and diff <= size:
found = True
print(line)
break
if not found:
print("Not found")
# print("Hello, World!", address)
VaddressToMapping()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment