mirror of https://github.com/pwndbg/pwndbg.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Tuple
|
|
|
|
import pwndbg
|
|
import pwndbg.aglib.vmmap_custom
|
|
import pwndbg.lib.cache
|
|
import pwndbg.lib.memory
|
|
from pwndbg.dbg import MemoryMap
|
|
|
|
pwndbg.config.add_param(
|
|
"vmmap-prefer-relpaths",
|
|
True,
|
|
"show relative paths by default in vmmap",
|
|
param_class=pwndbg.lib.config.PARAM_BOOLEAN,
|
|
)
|
|
|
|
|
|
@pwndbg.lib.cache.cache_until("start", "stop")
|
|
def get_memory_map() -> MemoryMap:
|
|
return pwndbg.dbg.selected_inferior().vmmap()
|
|
|
|
|
|
@pwndbg.lib.cache.cache_until("start", "stop")
|
|
def get() -> Tuple[pwndbg.lib.memory.Page, ...]:
|
|
return tuple(get_memory_map().ranges())
|
|
|
|
|
|
@pwndbg.lib.cache.cache_until("start", "stop")
|
|
def find(address: int | pwndbg.dbg_mod.Value | None) -> pwndbg.lib.memory.Page | None:
|
|
if address is None:
|
|
return None
|
|
|
|
address = int(address)
|
|
if address < 0:
|
|
return None
|
|
|
|
page = get_memory_map().lookup_page(address)
|
|
|
|
if page is not None:
|
|
return page
|
|
|
|
return pwndbg.aglib.vmmap_custom.explore(address)
|
|
|
|
|
|
def guess_physmap_base() -> int | None:
|
|
# this is mostly true
|
|
# https://www.kernel.org/doc/Documentation/x86/x86_64/mm.txt
|
|
for page in get():
|
|
if page.start & (1 << 63) > 0:
|
|
return page.start
|
|
return None
|