Move qemu.py and remote.py to gdblib (#1130)

pull/1132/head
Gulshan Singh 3 years ago committed by GitHub
parent 8e212b46ef
commit 2ea32b089a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
:mod:`pwndbg.qemu` --- pwndbg.qemu :mod:`pwndbg.gdblib.qemu` --- pwndbg.gdblib.qemu
============================================= =============================================
.. automodule:: pwndbg.qemu .. automodule:: pwndbg.gdblib.qemu
:members: :members:

@ -1,5 +1,5 @@
:mod:`pwndbg.remote` --- pwndbg.remote :mod:`pwndbg.gdblib.remote` --- pwndbg.gdblib.remote
============================================= =============================================
.. automodule:: pwndbg.remote .. automodule:: pwndbg.gdblib.remote
:members: :members:

@ -9,9 +9,9 @@ import pwndbg.gdblib.arch
import pwndbg.gdblib.events import pwndbg.gdblib.events
import pwndbg.gdblib.info import pwndbg.gdblib.info
import pwndbg.gdblib.memory import pwndbg.gdblib.memory
import pwndbg.gdblib.qemu
import pwndbg.gdblib.regs import pwndbg.gdblib.regs
import pwndbg.gdblib.typeinfo import pwndbg.gdblib.typeinfo
import pwndbg.qemu
import pwndbg.stack import pwndbg.stack
example_info_auxv_linux = """ example_info_auxv_linux = """
@ -148,7 +148,7 @@ def find_stack_boundary(addr):
def walk_stack(): def walk_stack():
if not pwndbg.gdblib.abi.linux: if not pwndbg.gdblib.abi.linux:
return None return None
if pwndbg.qemu.is_qemu_kernel(): if pwndbg.gdblib.qemu.is_qemu_kernel():
return None return None
auxv = walk_stack2(0) auxv = walk_stack2(0)

@ -224,7 +224,7 @@ def OnlyWithFile(function):
if pwndbg.proc.exe: if pwndbg.proc.exe:
return function(*a, **kw) return function(*a, **kw)
else: else:
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
print(message.error("Could not determine the target binary on QEMU.")) print(message.error("Could not determine the target binary on QEMU."))
else: else:
print(message.error("%s: There is no file loaded." % function.__name__)) print(message.error("%s: There is no file loaded." % function.__name__))

@ -184,5 +184,5 @@ def leakfind(
for line in output_map[chain_length]: for line in output_map[chain_length]:
print(line) print(line)
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
print("\n[QEMU target detected - leakfind result might not be accurate; see `help vmmap`]") print("\n[QEMU target detected - leakfind result might not be accurate; see `help vmmap`]")

@ -74,7 +74,7 @@ def vmmap(gdbval_or_str=None, writable=False, executable=False):
continue continue
print(M.get(page.vaddr, text=str(page))) print(M.get(page.vaddr, text=str(page)))
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
print("\n[QEMU target detected - vmmap result might not be accurate; see `help vmmap`]") print("\n[QEMU target detected - vmmap result might not be accurate; see `help vmmap`]")

@ -238,7 +238,7 @@ def get_ehdr(pointer):
""" """
# This just does not work :( # This just does not work :(
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
return None, None return None, None
vmmap = pwndbg.vmmap.find(pointer) vmmap = pwndbg.vmmap.find(pointer)

@ -11,8 +11,8 @@ import tempfile
import gdb import gdb
import pwndbg.color.message as message import pwndbg.color.message as message
import pwndbg.qemu import pwndbg.gdblib.qemu
import pwndbg.remote import pwndbg.gdblib.remote
import pwndbg.symbol import pwndbg.symbol
@ -33,13 +33,13 @@ def get_file(path):
path = path[7:] # len('target:') == 7 path = path[7:] # len('target:') == 7
local_path = path local_path = path
qemu_root = pwndbg.qemu.root() qemu_root = pwndbg.gdblib.qemu.root()
if qemu_root: if qemu_root:
return os.path.join(qemu_root, path) return os.path.join(qemu_root, path)
elif pwndbg.remote.is_remote(): elif pwndbg.gdblib.remote.is_remote():
if not pwndbg.qemu.is_qemu(): if not pwndbg.gdblib.qemu.is_qemu():
local_path = tempfile.mktemp(dir=pwndbg.symbol.remote_files_dir) local_path = tempfile.mktemp(dir=pwndbg.symbol.remote_files_dir)
error = None error = None
try: try:
@ -84,13 +84,13 @@ def readlink(path):
Handles local, qemu-usermode, and remote debugging cases. Handles local, qemu-usermode, and remote debugging cases.
""" """
is_qemu = pwndbg.qemu.is_qemu_usermode() is_qemu = pwndbg.gdblib.qemu.is_qemu_usermode()
if is_qemu: if is_qemu:
if not os.path.exists(path): if not os.path.exists(path):
path = os.path.join(pwndbg.qemu.root(), path) path = os.path.join(pwndbg.gdblib.qemu.root(), path)
if is_qemu or not pwndbg.remote.is_remote(): if is_qemu or not pwndbg.gdblib.remote.is_remote():
try: try:
return os.readlink(path) return os.readlink(path)
except Exception: except Exception:

@ -3,14 +3,14 @@ import gdb
import pwndbg.color.message as message import pwndbg.color.message as message
import pwndbg.file import pwndbg.file
import pwndbg.gdblib.events import pwndbg.gdblib.events
import pwndbg.gdblib.qemu
import pwndbg.lib.memoize import pwndbg.lib.memoize
import pwndbg.qemu
@pwndbg.lib.memoize.reset_on_start @pwndbg.lib.memoize.reset_on_start
@pwndbg.lib.memoize.reset_on_exit @pwndbg.lib.memoize.reset_on_exit
def is_android(): def is_android():
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
return False return False
try: try:

@ -8,8 +8,8 @@ import gdb
import pwndbg.gdblib.arch import pwndbg.gdblib.arch
import pwndbg.gdblib.events import pwndbg.gdblib.events
import pwndbg.gdblib.qemu
import pwndbg.gdblib.typeinfo import pwndbg.gdblib.typeinfo
import pwndbg.qemu
from pwndbg.lib.memory import PAGE_MASK from pwndbg.lib.memory import PAGE_MASK
from pwndbg.lib.memory import PAGE_SIZE from pwndbg.lib.memory import PAGE_SIZE
@ -334,5 +334,5 @@ def find_lower_boundary(addr, max_pages=1024):
@pwndbg.gdblib.events.start @pwndbg.gdblib.events.start
def update_min_addr(): def update_min_addr():
global MMAP_MIN_ADDR global MMAP_MIN_ADDR
if pwndbg.qemu.is_qemu_kernel(): if pwndbg.gdblib.qemu.is_qemu_kernel():
MMAP_MIN_ADDR = 0 MMAP_MIN_ADDR = 0

@ -7,13 +7,15 @@ import os
import gdb import gdb
import psutil import psutil
import pwndbg.gdblib.events import pwndbg.gdblib.remote
import pwndbg.remote
# TODO: `import pwndbg.gdblib.events` leads to a circular import
from pwndbg.gdblib.events import start
@pwndbg.lib.memoize.reset_on_stop @pwndbg.lib.memoize.reset_on_stop
def is_qemu(): def is_qemu():
if not pwndbg.remote.is_remote(): if not pwndbg.gdblib.remote.is_remote():
return False return False
# Example: # Example:
@ -27,7 +29,7 @@ def is_qemu():
@pwndbg.lib.memoize.reset_on_stop @pwndbg.lib.memoize.reset_on_stop
def is_usermode(): def is_usermode():
if not pwndbg.remote.is_remote(): if not pwndbg.gdblib.remote.is_remote():
return False return False
# There is also 'qAttached' - maybe we can use it too? # There is also 'qAttached' - maybe we can use it too?
@ -53,7 +55,7 @@ def is_qemu_kernel():
return is_qemu() and not is_usermode() return is_qemu() and not is_usermode()
# @pwndbg.gdblib.events.start @start
@pwndbg.lib.memoize.reset_on_stop @pwndbg.lib.memoize.reset_on_stop
def root(): def root():
global binfmt_root global binfmt_root

@ -12,9 +12,9 @@ import gdb
import pwndbg.gdblib.arch import pwndbg.gdblib.arch
import pwndbg.gdblib.events import pwndbg.gdblib.events
import pwndbg.gdblib.remote
import pwndbg.lib.memoize import pwndbg.lib.memoize
import pwndbg.proc import pwndbg.proc
import pwndbg.remote
from pwndbg.lib.regs import reg_sets from pwndbg.lib.regs import reg_sets
@ -191,7 +191,7 @@ class module(ModuleType):
return get_register(regname) return get_register(regname)
# We can't really do anything if the process is remote. # We can't really do anything if the process is remote.
if pwndbg.remote.is_remote(): if pwndbg.gdblib.remote.is_remote():
return 0 return 0
# Use the lightweight process ID # Use the lightweight process ID

@ -10,8 +10,8 @@ from types import ModuleType
import gdb import gdb
import pwndbg.gdblib.qemu
import pwndbg.lib.memoize import pwndbg.lib.memoize
import pwndbg.qemu
class module(ModuleType): class module(ModuleType):
@ -19,8 +19,8 @@ class module(ModuleType):
def pid(self): def pid(self):
# QEMU usermode emualtion always returns 42000 for some reason. # QEMU usermode emualtion always returns 42000 for some reason.
# In any case, we can't use the info. # In any case, we can't use the info.
if pwndbg.qemu.is_qemu_usermode(): if pwndbg.gdblib.qemu.is_qemu_usermode():
return pwndbg.qemu.pid() return pwndbg.gdblib.qemu.pid()
i = gdb.selected_inferior() i = gdb.selected_inferior()
if i is not None: if i is not None:
@ -29,8 +29,8 @@ class module(ModuleType):
@property @property
def tid(self): def tid(self):
if pwndbg.qemu.is_qemu_usermode(): if pwndbg.gdblib.qemu.is_qemu_usermode():
return pwndbg.qemu.pid() return pwndbg.gdblib.qemu.pid()
i = gdb.selected_thread() i = gdb.selected_thread()
if i is not None: if i is not None:

@ -22,10 +22,10 @@ import pwndbg.gdblib.android
import pwndbg.gdblib.arch import pwndbg.gdblib.arch
import pwndbg.gdblib.events import pwndbg.gdblib.events
import pwndbg.gdblib.memory import pwndbg.gdblib.memory
import pwndbg.gdblib.qemu
import pwndbg.gdblib.remote
import pwndbg.ida import pwndbg.ida
import pwndbg.lib.memoize import pwndbg.lib.memoize
import pwndbg.qemu
import pwndbg.remote
import pwndbg.stack import pwndbg.stack
import pwndbg.vmmap import pwndbg.vmmap
@ -78,10 +78,10 @@ def reset_remote_files():
def autofetch(): def autofetch():
""" """ """ """
global remote_files_dir global remote_files_dir
if not pwndbg.remote.is_remote(): if not pwndbg.gdblib.remote.is_remote():
return return
if pwndbg.qemu.is_qemu_usermode(): if pwndbg.gdblib.qemu.is_qemu_usermode():
return return
if pwndbg.gdblib.android.is_android(): if pwndbg.gdblib.android.is_android():
@ -238,7 +238,7 @@ def address(symbol, allow_unmapped=False):
@pwndbg.gdblib.events.stop @pwndbg.gdblib.events.stop
@pwndbg.lib.memoize.reset_on_start @pwndbg.lib.memoize.reset_on_start
def add_main_exe_to_symbols(): def add_main_exe_to_symbols():
if not pwndbg.remote.is_remote(): if not pwndbg.gdblib.remote.is_remote():
return return
if pwndbg.gdblib.android.is_android(): if pwndbg.gdblib.android.is_android():

@ -16,12 +16,12 @@ import pwndbg.file
import pwndbg.gdblib.abi import pwndbg.gdblib.abi
import pwndbg.gdblib.events import pwndbg.gdblib.events
import pwndbg.gdblib.memory import pwndbg.gdblib.memory
import pwndbg.gdblib.qemu
import pwndbg.gdblib.regs import pwndbg.gdblib.regs
import pwndbg.gdblib.remote
import pwndbg.gdblib.typeinfo import pwndbg.gdblib.typeinfo
import pwndbg.lib.memoize import pwndbg.lib.memoize
import pwndbg.proc import pwndbg.proc
import pwndbg.qemu
import pwndbg.remote
import pwndbg.stack import pwndbg.stack
# List of manually-explored pages which were discovered # List of manually-explored pages which were discovered
@ -56,7 +56,7 @@ def get():
if ( if (
not pages not pages
and pwndbg.qemu.is_qemu_kernel() and pwndbg.gdblib.qemu.is_qemu_kernel()
and pwndbg.gdblib.arch.current in ("i386", "x86-64", "aarch64", "riscv:rv64") and pwndbg.gdblib.arch.current in ("i386", "x86-64", "aarch64", "riscv:rv64")
): ):
if kernel_vmmap_via_pt: if kernel_vmmap_via_pt:
@ -81,7 +81,7 @@ def get():
if pages: if pages:
pages.extend(info_sharedlibrary()) pages.extend(info_sharedlibrary())
else: else:
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
return (pwndbg.lib.memory.Page(0, pwndbg.gdblib.arch.ptrmask, 7, 0, "[qemu]"),) return (pwndbg.lib.memory.Page(0, pwndbg.gdblib.arch.ptrmask, 7, 0, "[qemu]"),)
pages.extend(info_files()) pages.extend(info_files())
@ -280,7 +280,7 @@ def proc_pid_maps():
# If we debug remotely a qemu-user or qemu-system target, # If we debug remotely a qemu-user or qemu-system target,
# there is no point of hitting things further # there is no point of hitting things further
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
return tuple() return tuple()
# Example /proc/$pid/maps # Example /proc/$pid/maps
@ -594,7 +594,7 @@ def check_aslr():
None is returned when we can't detect ASLR. None is returned when we can't detect ASLR.
""" """
# QEMU does not support this concept. # QEMU does not support this concept.
if pwndbg.qemu.is_qemu(): if pwndbg.gdblib.qemu.is_qemu():
return None, "Could not detect ASLR on QEMU targets" return None, "Could not detect ASLR on QEMU targets"
# Systemwide ASLR is disabled # Systemwide ASLR is disabled

Loading…
Cancel
Save