From 295fe29b22a56c789764bc0a595ba3d63421a35b Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Tue, 18 Oct 2022 03:21:58 -0700 Subject: [PATCH] Cleanup before unit-tests (#1293) --- pwndbg/__init__.py | 35 +++++++++++++++++++++++------------ pwndbg/color/theme.py | 4 ++-- pwndbg/commands/__init__.py | 8 -------- pwndbg/exception.py | 8 ++++---- pwndbg/gdblib/argv.py | 2 +- pwndbg/ui.py | 2 +- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 80dbeadb..477ac650 100755 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -5,19 +5,26 @@ import gdb import pwndbg.color import pwndbg.commands import pwndbg.gdblib +from pwndbg.commands import load_commands +from pwndbg.gdblib import load_gdblib -pwndbg.commands.load_commands() -pwndbg.gdblib.load_gdblib() +load_commands() +load_gdblib() + +# TODO: Convert these to gdblib modules and remove this +try: + import pwndbg.disasm + import pwndbg.disasm.arm + import pwndbg.disasm.jump + import pwndbg.disasm.mips + import pwndbg.disasm.ppc + import pwndbg.disasm.sparc + import pwndbg.disasm.x86 + import pwndbg.heap +except ModuleNotFoundError: + pass -import pwndbg.disasm -import pwndbg.disasm.arm -import pwndbg.disasm.jump -import pwndbg.disasm.mips -import pwndbg.disasm.ppc -import pwndbg.disasm.sparc -import pwndbg.disasm.x86 import pwndbg.exception -import pwndbg.heap import pwndbg.lib.version import pwndbg.ui @@ -58,7 +65,9 @@ __all__ = [ "vmmap", ] -pwndbg.gdblib.prompt.set_prompt() +from pwndbg.gdblib import prompt + +prompt.set_prompt() pre_commands = """ set confirm off @@ -95,7 +104,9 @@ signal.signal( ) # Reading Comment file -pwndbg.commands.comments.init() +from pwndbg.commands import comments + +comments.init() from pwndbg.gdblib import config_mod diff --git a/pwndbg/color/theme.py b/pwndbg/color/theme.py index 6a4c18ab..4d69934d 100644 --- a/pwndbg/color/theme.py +++ b/pwndbg/color/theme.py @@ -1,8 +1,8 @@ -import pwndbg.gdblib.config +from pwndbg.gdblib import config def add_param(name, default, docstring): - return pwndbg.gdblib.config.add_param(name, default, docstring, "theme") + return config.add_param(name, default, docstring, "theme") def add_color_param(name, default, docstring): diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index a4de6601..ee1cdfa2 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -6,18 +6,10 @@ from typing import List import gdb -import pwndbg.chain -import pwndbg.color import pwndbg.color.message as message -import pwndbg.enhance import pwndbg.exception -import pwndbg.gdblib.config -import pwndbg.gdblib.memory import pwndbg.gdblib.regs -import pwndbg.gdblib.symbol import pwndbg.heap -import pwndbg.hexdump -import pwndbg.ui from pwndbg.heap.ptmalloc import SymbolUnresolvableError commands = [] # type: List[Command] diff --git a/pwndbg/exception.py b/pwndbg/exception.py index 113e6e49..3e4a7dfa 100644 --- a/pwndbg/exception.py +++ b/pwndbg/exception.py @@ -5,9 +5,9 @@ import traceback import gdb import pwndbg.color.message as message -import pwndbg.gdblib.config import pwndbg.lib.memoize import pwndbg.lib.stdio +from pwndbg.gdblib import config with pwndbg.lib.stdio.stdio: try: @@ -15,12 +15,12 @@ with pwndbg.lib.stdio.stdio: except ImportError: import pdb -verbose = pwndbg.gdblib.config.add_param( +verbose = config.add_param( "exception-verbose", False, "whether to print a full stacktrace for exceptions raised in Pwndbg commands", ) -debug = pwndbg.gdblib.config.add_param( +debug = config.add_param( "exception-debugger", False, "whether to debug exceptions raised in Pwndbg commands" ) @@ -95,7 +95,7 @@ def set_trace(): pdb.set_trace = set_trace -@pwndbg.gdblib.config.trigger(verbose, debug) +@config.trigger(verbose, debug) def update(): if verbose or debug: command = "set python print-stack full" diff --git a/pwndbg/gdblib/argv.py b/pwndbg/gdblib/argv.py index 841442aa..6ab4faa7 100644 --- a/pwndbg/gdblib/argv.py +++ b/pwndbg/gdblib/argv.py @@ -1,10 +1,10 @@ import gdb +import pwndbg.gdblib.abi import pwndbg.gdblib.arch import pwndbg.gdblib.events import pwndbg.gdblib.memory import pwndbg.gdblib.regs -import pwndbg.lib.abi #: Total number of arguments argc = None diff --git a/pwndbg/ui.py b/pwndbg/ui.py index 5d703768..4698f9ca 100644 --- a/pwndbg/ui.py +++ b/pwndbg/ui.py @@ -25,7 +25,7 @@ theme.add_param( title_position = theme.add_param("banner-title-position", "center", "banner title position") -@pwndbg.gdblib.config.trigger(title_position) +@config.trigger(title_position) def check_title_position(): valid_values = ["center", "left", "right"] if title_position not in valid_values: