Skip to content

Commit

Permalink
Move some modules into gdb/ (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsingh93 committed Sep 5, 2022
1 parent eba90ee commit 6d57329
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docs/source/api/info.rst
@@ -1,5 +1,5 @@
:mod:`pwndbg.info` --- pwndbg.info
:mod:`pwndbg.gdblib.info` --- pwndbg.gdblib.info
=============================================

.. automodule:: pwndbg.info
.. automodule:: pwndbg.gdblib.info
:members:
4 changes: 2 additions & 2 deletions docs/source/api/next.rst
@@ -1,5 +1,5 @@
:mod:`pwndbg.next` --- pwndbg.next
:mod:`pwndbg.gdblib.next` --- pwndbg.gdblib.next
=============================================

.. automodule:: pwndbg.next
.. automodule:: pwndbg.gdblib.next
:members:
4 changes: 2 additions & 2 deletions docs/source/api/prompt.rst
@@ -1,5 +1,5 @@
:mod:`pwndbg.prompt` --- pwndbg.prompt
:mod:`pwndbg.gdblib.prompt` --- pwndbg.gdblib.prompt
=============================================

.. automodule:: pwndbg.prompt
.. automodule:: pwndbg.gdblib.prompt
:members:
4 changes: 2 additions & 2 deletions pwndbg/__init__.py
Expand Up @@ -68,6 +68,7 @@
import pwndbg.gdblib.arch
import pwndbg.gdblib.events
import pwndbg.gdblib.hooks
import pwndbg.gdblib.prompt
import pwndbg.gdblib.regs
import pwndbg.gdblib.typeinfo
import pwndbg.gdbutils.functions
Expand All @@ -76,7 +77,6 @@
import pwndbg.memory
import pwndbg.net
import pwndbg.proc
import pwndbg.prompt
import pwndbg.stack
import pwndbg.tls
import pwndbg.ui
Expand Down Expand Up @@ -129,7 +129,7 @@
"vmmap",
]

pwndbg.prompt.set_prompt()
pwndbg.gdblib.prompt.set_prompt()

pre_commands = """
set confirm off
Expand Down
4 changes: 2 additions & 2 deletions pwndbg/auxv.py
Expand Up @@ -7,9 +7,9 @@
import pwndbg.gdblib.abi
import pwndbg.gdblib.arch
import pwndbg.gdblib.events
import pwndbg.gdblib.info
import pwndbg.gdblib.regs
import pwndbg.gdblib.typeinfo
import pwndbg.info
import pwndbg.memory
import pwndbg.qemu
import pwndbg.stack
Expand Down Expand Up @@ -104,7 +104,7 @@ def get():


def use_info_auxv():
lines = pwndbg.info.auxv().splitlines()
lines = pwndbg.gdblib.info.auxv().splitlines()

if not lines:
return None
Expand Down
24 changes: 13 additions & 11 deletions pwndbg/commands/next.py
Expand Up @@ -7,14 +7,14 @@
import gdb

import pwndbg.commands
import pwndbg.next
import pwndbg.gdblib.next


@pwndbg.commands.ArgparsedCommand("Breaks at the next jump instruction.", aliases=["nextjump"])
@pwndbg.commands.OnlyWhenRunning
def nextjmp():
"""Breaks at the next jump instruction"""
if pwndbg.next.break_next_branch():
if pwndbg.gdblib.next.break_next_branch():
pwndbg.commands.context.context()


Expand All @@ -32,15 +32,15 @@ def nextjmp():
@pwndbg.commands.OnlyWhenRunning
def nextcall(symbol_regex=None):
"""Breaks at the next call instruction"""
if pwndbg.next.break_next_call(symbol_regex):
if pwndbg.gdblib.next.break_next_call(symbol_regex):
pwndbg.commands.context.context()


@pwndbg.commands.ArgparsedCommand("""Breaks at next return-like instruction""")
@pwndbg.commands.OnlyWhenRunning
def nextret():
"""Breaks at next return-like instruction"""
if pwndbg.next.break_next_ret():
if pwndbg.gdblib.next.break_next_ret():
pwndbg.commands.context.context()


Expand All @@ -49,7 +49,9 @@ def nextret():
def stepret():
"""Breaks at next return-like instruction by 'stepping' to it"""
while (
pwndbg.proc.alive and not pwndbg.next.break_next_ret() and pwndbg.next.break_next_branch()
pwndbg.proc.alive
and not pwndbg.gdblib.next.break_next_ret()
and pwndbg.gdblib.next.break_next_branch()
):
# Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)
# We need to step so that we take this branch instead of ignoring it
Expand All @@ -66,7 +68,7 @@ def stepret():
@pwndbg.commands.OnlyWhenRunning
def nextproginstr():
"""Breaks at the next instruction that belongs to the running program"""
if pwndbg.next.break_on_program_code():
if pwndbg.gdblib.next.break_on_program_code():
pwndbg.commands.context.context()


Expand All @@ -80,7 +82,7 @@ def nextproginstr():
@pwndbg.commands.OnlyWhenRunning
def stepover(addr=None):
"""Sets a breakpoint on the instruction after this one"""
pwndbg.next.break_on_next(addr)
pwndbg.gdblib.next.break_on_next(addr)


@pwndbg.commands.ArgparsedCommand(
Expand All @@ -93,8 +95,8 @@ def nextsyscall():
"""
while (
pwndbg.proc.alive
and not pwndbg.next.break_next_interrupt()
and pwndbg.next.break_next_branch()
and not pwndbg.gdblib.next.break_next_interrupt()
and pwndbg.gdblib.next.break_next_branch()
):
continue

Expand All @@ -112,8 +114,8 @@ def stepsyscall():
"""
while (
pwndbg.proc.alive
and not pwndbg.next.break_next_interrupt()
and pwndbg.next.break_next_branch()
and not pwndbg.gdblib.next.break_next_interrupt()
and pwndbg.gdblib.next.break_next_branch()
):
# Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)
# We need to step so that we take this branch instead of ignoring it
Expand Down
4 changes: 2 additions & 2 deletions pwndbg/elf.py
Expand Up @@ -20,7 +20,7 @@
import pwndbg.gdblib.abi
import pwndbg.gdblib.arch
import pwndbg.gdblib.events
import pwndbg.info
import pwndbg.gdblib.info
import pwndbg.lib.memoize
import pwndbg.memory
import pwndbg.proc
Expand Down Expand Up @@ -195,7 +195,7 @@ def entry():

# Looking for this line:
# Entry point: 0x400090
for line in pwndbg.info.files().splitlines():
for line in pwndbg.gdblib.info.files().splitlines():
if "Entry point" in line:
entry_point = int(line.split()[-1], 16)

Expand Down
10 changes: 5 additions & 5 deletions pwndbg/elftypes.py
Expand Up @@ -29,8 +29,8 @@
#
import ctypes

import pwndbg.ctypes
import pwndbg.gdblib.arch
import pwndbg.gdblib.ctypes
import pwndbg.gdblib.events

Elf32_Addr = ctypes.c_uint32
Expand Down Expand Up @@ -255,7 +255,7 @@ class constants:
AT_L3_CACHESHAPE = 37


class Elf32_Ehdr(pwndbg.ctypes.Structure):
class Elf32_Ehdr(pwndbg.gdblib.ctypes.Structure):
_fields_ = [
("e_ident", (ctypes.c_ubyte * 16)),
("e_type", Elf32_Half),
Expand All @@ -274,7 +274,7 @@ class Elf32_Ehdr(pwndbg.ctypes.Structure):
]


class Elf64_Ehdr(pwndbg.ctypes.Structure):
class Elf64_Ehdr(pwndbg.gdblib.ctypes.Structure):
_fields_ = [
("e_ident", (ctypes.c_ubyte * 16)),
("e_type", Elf64_Half),
Expand All @@ -293,7 +293,7 @@ class Elf64_Ehdr(pwndbg.ctypes.Structure):
]


class Elf32_Phdr(pwndbg.ctypes.Structure):
class Elf32_Phdr(pwndbg.gdblib.ctypes.Structure):
_fields_ = [
("p_type", Elf32_Word),
("p_offset", Elf32_Off),
Expand All @@ -306,7 +306,7 @@ class Elf32_Phdr(pwndbg.ctypes.Structure):
]


class Elf64_Phdr(pwndbg.ctypes.Structure):
class Elf64_Phdr(pwndbg.gdblib.ctypes.Structure):
_fields_ = [
("p_type", Elf64_Word),
("p_flags", Elf64_Word),
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions pwndbg/info.py → pwndbg/gdblib/info.py
Expand Up @@ -8,6 +8,8 @@

import pwndbg.lib.memoize

# TODO: Add sharedlibrary, address, breakpoints, symbol, target, threads


@pwndbg.lib.memoize.reset_on_exit
def proc_mapping():
Expand All @@ -21,9 +23,6 @@ def proc_mapping():
def auxv():
try:
return gdb.execute("info auxv", to_string=True)
# The gdb.error may be one of:
# - "The program has no auxiliary information now."
# - "No auxiliary vector found, or failed reading it."
except gdb.error:
return ""

Expand Down
2 changes: 2 additions & 0 deletions pwndbg/next.py → pwndbg/gdblib/next.py
Expand Up @@ -9,7 +9,9 @@
import gdb

import pwndbg.disasm
import pwndbg.gdblib.events
import pwndbg.gdblib.regs
import pwndbg.proc
from pwndbg.color import message

jumps = set((capstone.CS_GRP_CALL, capstone.CS_GRP_JUMP, capstone.CS_GRP_RET, capstone.CS_GRP_IRET))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pwndbg/vmmap.py
Expand Up @@ -249,7 +249,7 @@ def coredump_maps():
stack_addr = None

# TODO/FIXME: Can we uxe `pwndbg.auxv.get()` for this somehow?
auxv = pwndbg.info.auxv().splitlines()
auxv = pwndbg.gdblib.info.auxv().splitlines()
for line in auxv:
if "AT_EXECFN" in line:
try:
Expand Down

0 comments on commit 6d57329

Please sign in to comment.