mirror of https://github.com/pwndbg/pwndbg
fix: lint
This commit is contained in:
parent
9e84c18c44
commit
30cd4c7372
|
@ -1,5 +1,9 @@
|
|||
import argparse
|
||||
|
||||
import gdb
|
||||
import pwnlib
|
||||
from pwnlib import asm
|
||||
|
||||
import pwndbg.chain
|
||||
import pwndbg.commands
|
||||
import pwndbg.enhance
|
||||
|
@ -7,8 +11,6 @@ import pwndbg.file
|
|||
import pwndbg.lib.which
|
||||
import pwndbg.wrappers.checksec
|
||||
import pwndbg.wrappers.readelf
|
||||
import pwnlib
|
||||
from pwnlib import asm
|
||||
|
||||
parser = argparse.ArgumentParser(description="Calls mprotect. x86_64 only.")
|
||||
parser.add_argument("addr", help="Page-aligned address to all mprotect on.", type=int)
|
||||
|
@ -51,7 +53,6 @@ def mprotect(addr, length, prot):
|
|||
saved_rdx = pwndbg.gdblib.regs.rdx
|
||||
saved_rip = pwndbg.gdblib.regs.rip
|
||||
|
||||
|
||||
prot_int = prot_str_to_val(prot)
|
||||
|
||||
shellcode_asm = pwnlib.shellcraft.syscall("SYS_mprotect", int(addr), int(length), int(prot_int))
|
||||
|
@ -60,7 +61,7 @@ def mprotect(addr, length, prot):
|
|||
saved_instruction_bytes = pwndbg.gdblib.memory.read(pwndbg.gdblib.regs.rip, len(shellcode))
|
||||
|
||||
pwndbg.gdblib.memory.write(pwndbg.gdblib.regs.rip, shellcode)
|
||||
|
||||
|
||||
# execute syscall
|
||||
gdb.execute("nextsyscall")
|
||||
gdb.execute("stepi")
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import gdb
|
||||
import pwnlib
|
||||
|
||||
import pwndbg.proc
|
||||
from pwndbg.gdblib import typeinfo
|
||||
from pwndbg.lib.arch import Arch
|
||||
import pwnlib
|
||||
|
||||
# TODO: x86-64 needs to come before i386 in the current implementation, make
|
||||
# this order-independent
|
||||
ARCHS = ("x86-64", "i386", "aarch64", "mips", "powerpc", "sparc", "arm")
|
||||
|
|
|
@ -5,6 +5,7 @@ import tests
|
|||
|
||||
MPROTECT_BINARY = tests.binaries.get("mprotect.out")
|
||||
|
||||
|
||||
def test_mprotect(start_binary):
|
||||
"""
|
||||
Tests mprotect command
|
||||
|
@ -16,16 +17,20 @@ def test_mprotect(start_binary):
|
|||
# get addr of func
|
||||
addr = int(gdb.parse_and_eval("&func"))
|
||||
addr_aligned = pwndbg.lib.memory.page_align(addr)
|
||||
|
||||
|
||||
# sizeof
|
||||
size = int(gdb.parse_and_eval("sizeof(func)"))
|
||||
size_aligned = pwndbg.lib.memory.page_align(size)
|
||||
|
||||
vmmaps_before = gdb.execute("vmmap -x", to_string=True).splitlines()
|
||||
|
||||
|
||||
# mark memory as executable
|
||||
gdb.execute("mprotect {} {} PROT_EXEC|PROT_READ|PROT_WRITE".format(hex(addr_aligned), pwndbg.lib.memory.PAGE_SIZE))
|
||||
|
||||
gdb.execute(
|
||||
"mprotect {} {} PROT_EXEC|PROT_READ|PROT_WRITE".format(
|
||||
hex(addr_aligned), pwndbg.lib.memory.PAGE_SIZE
|
||||
)
|
||||
)
|
||||
|
||||
vmmaps_after = gdb.execute("vmmap -x", to_string=True).splitlines()
|
||||
|
||||
# expect vmmaps_after to be one element longer than vmmaps_before
|
||||
|
@ -35,14 +40,14 @@ def test_mprotect(start_binary):
|
|||
vmmap_entry = [x for x in vmmaps_after if x not in vmmaps_before][0]
|
||||
|
||||
assert vmmap_entry.split()[2] == "rwxp"
|
||||
|
||||
|
||||
# continue execution
|
||||
gdb.execute("continue")
|
||||
|
||||
|
||||
|
||||
def test_cannot_run_mprotect_when_not_running(start_binary):
|
||||
|
||||
|
||||
# expect error message
|
||||
assert "mprotect: The program is not being run.\n" == gdb.execute("mprotect 0x0 0x1000 PROT_EXEC|PROT_READ|PROT_WRITE", to_string=True)
|
||||
assert "mprotect: The program is not being run.\n" == gdb.execute(
|
||||
"mprotect 0x0 0x1000 PROT_EXEC|PROT_READ|PROT_WRITE", to_string=True
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue