Port `mmap` and `mprotect` to the Debugger-agnostic API

pull/2492/head
Matheus Branco Borella 1 year ago committed by Disconnect3d
parent 7e530115b7
commit 74a38b219a

@ -716,8 +716,6 @@ def load_commands() -> None:
import pwndbg.commands.linkmap
import pwndbg.commands.memoize
import pwndbg.commands.misc
import pwndbg.commands.mmap
import pwndbg.commands.mprotect
import pwndbg.commands.onegadget
import pwndbg.commands.pcplist
import pwndbg.commands.peda
@ -751,6 +749,8 @@ def load_commands() -> None:
import pwndbg.commands.heap
import pwndbg.commands.hexdump
import pwndbg.commands.leakfind
import pwndbg.commands.mmap
import pwndbg.commands.mprotect
import pwndbg.commands.nearpc
import pwndbg.commands.next
import pwndbg.commands.p2p

@ -3,12 +3,12 @@ from __future__ import annotations
import argparse
from typing import Union
import pwndbg.aglib.file
import pwndbg.aglib.shellcode
import pwndbg.chain
import pwndbg.color.message as message
import pwndbg.commands
import pwndbg.enhance
import pwndbg.gdblib.file
import pwndbg.gdblib.shellcode
import pwndbg.lib.memory
import pwndbg.wrappers.checksec
import pwndbg.wrappers.readelf
@ -183,7 +183,7 @@ instead.\
if not force:
page = pwndbg.lib.memory.Page(addr, int(length), 0, 0)
collisions = []
vm = pwndbg.gdblib.vmmap.get()
vm = pwndbg.aglib.vmmap.get()
# FIXME: The ends of the maps are sorted. We could bisect the array
# in order to quickly reject all of the items we could never hit
@ -241,14 +241,18 @@ using the address {aligned_addr:#x} instead.\
)
)
pointer = pwndbg.gdblib.shellcode.exec_syscall(
"SYS_mmap",
int(pwndbg.lib.memory.page_align(addr)),
int(length),
prot_int,
flag_int,
int(fd),
int(offset),
)
print(f"mmap syscall returned {pointer:#x}")
async def ctrl(ec: pwndbg.dbg_mod.ExecutionController):
pointer = await pwndbg.aglib.shellcode.exec_syscall(
ec,
"SYS_mmap",
int(pwndbg.lib.memory.page_align(addr)),
int(length),
prot_int,
flag_int,
int(fd),
int(offset),
)
print(f"mmap syscall returned {pointer:#x}")
pwndbg.dbg.selected_inferior().dispatch_execution_controller(ctrl)

@ -2,11 +2,11 @@ from __future__ import annotations
import argparse
import pwndbg.aglib.file
import pwndbg.aglib.shellcode
import pwndbg.chain
import pwndbg.commands
import pwndbg.enhance
import pwndbg.gdblib.file
import pwndbg.gdblib.shellcode
import pwndbg.lib.memory
import pwndbg.wrappers.checksec
import pwndbg.wrappers.readelf
@ -98,11 +98,14 @@ def mprotect(addr, length, prot) -> None:
orig_addr = int(addr)
aligned = pwndbg.lib.memory.page_align(orig_addr)
print(
f"calling mprotect on address {aligned:#x} with protection {prot_int} ({prot_val_to_str(prot_int)})"
)
async def ctrl(ec: pwndbg.dbg_mod.ExecutionController):
print(
f"calling mprotect on address {aligned:#x} with protection {prot_int} ({prot_val_to_str(prot_int)})"
)
ret = pwndbg.gdblib.shellcode.exec_syscall(
"SYS_mprotect", aligned, int(length) + orig_addr - aligned, int(prot_int)
)
print(f"mprotect returned {ret}")
ret = await pwndbg.aglib.shellcode.exec_syscall(
ec, "SYS_mprotect", aligned, int(length) + orig_addr - aligned, int(prot_int)
)
print(f"mprotect returned {ret}")
pwndbg.dbg.selected_inferior().dispatch_execution_controller(ctrl)

Loading…
Cancel
Save