diff --git a/pwndbg/color/syntax_highlight.py b/pwndbg/color/syntax_highlight.py index 60eeb235..1c73090c 100644 --- a/pwndbg/color/syntax_highlight.py +++ b/pwndbg/color/syntax_highlight.py @@ -1,5 +1,7 @@ import os.path import re +from typing import Any +from typing import Dict import pygments import pygments.formatters @@ -20,7 +22,7 @@ style = theme.Parameter( formatter = pygments.formatters.Terminal256Formatter(style=str(style)) pwntools_lexer = PwntoolsLexer() -lexer_cache = {} +lexer_cache: Dict[str, Any] = {} @pwndbg.config.Trigger([style]) diff --git a/pwndbg/commands/reload.py b/pwndbg/commands/reload.py index bb25aae2..166b2769 100644 --- a/pwndbg/commands/reload.py +++ b/pwndbg/commands/reload.py @@ -1,15 +1,11 @@ import types +from imp import reload as _reload import pwndbg import pwndbg.commands import pwndbg.gdblib.events import pwndbg.lib.memoize -try: - from __builtins__ import reload as _reload -except Exception: - from imp import reload as _reload - def rreload(module, mdict=None): """Recursively reload modules.""" diff --git a/pwndbg/gdblib/events.py b/pwndbg/gdblib/events.py index b0dc6edf..1c4d50d8 100644 --- a/pwndbg/gdblib/events.py +++ b/pwndbg/gdblib/events.py @@ -7,6 +7,11 @@ by using a decorator. import sys from functools import partial from functools import wraps +from typing import Any +from typing import Callable +from typing import Dict +from typing import List +from typing import Set import gdb @@ -101,7 +106,7 @@ gdb.events.before_prompt = before_prompt_event # In order to support reloading, we must be able to re-fire # all 'objfile' and 'stop' events. -registered = { +registered: Dict[Any, List[Callable]] = { gdb.events.exited: [], gdb.events.cont: [], gdb.events.new_objfile: [], @@ -122,7 +127,7 @@ except (NameError, AttributeError): # objects are loaded. This greatly slows down the debugging session. # In order to combat this, we keep track of which objfiles have been loaded # this session, and only emit objfile events for each *new* file. -objfile_cache = dict() +objfile_cache: Dict[str, Set[str]] = {} def connect(func, event_handler, name=""): diff --git a/pwndbg/gdblib/regs.py b/pwndbg/gdblib/regs.py index feccd98e..78b4df3d 100644 --- a/pwndbg/gdblib/regs.py +++ b/pwndbg/gdblib/regs.py @@ -6,6 +6,7 @@ import ctypes import re import sys from types import ModuleType +from typing import Dict import gdb @@ -41,7 +42,7 @@ ARCH_GET_GS = 0x1004 class module(ModuleType): - last = {} + last: Dict[str, int] = {} @pwndbg.lib.memoize.reset_on_stop @pwndbg.lib.memoize.reset_on_prompt diff --git a/pwndbg/gdblib/stack.py b/pwndbg/gdblib/stack.py index 7e78f1af..bf8f6d2b 100644 --- a/pwndbg/gdblib/stack.py +++ b/pwndbg/gdblib/stack.py @@ -6,6 +6,8 @@ Generally not needed, except under qemu-user and for when binaries do things to remap the stack (e.g. pwnies' postit). """ +from typing import Dict + import gdb import pwndbg.gdblib.abi @@ -17,7 +19,7 @@ import pwndbg.lib.memoize # Dictionary of stack ranges. # Key is the gdb thread ptid # Value is a pwndbg.lib.memory.Page object -stacks = {} +stacks: Dict[int, pwndbg.lib.memory.Page] = {} # Whether the stack is protected by NX. # This is updated automatically by is_executable. diff --git a/pwndbg/gdblib/symbol.py b/pwndbg/gdblib/symbol.py index 352ef152..aea0999e 100644 --- a/pwndbg/gdblib/symbol.py +++ b/pwndbg/gdblib/symbol.py @@ -224,6 +224,8 @@ def address(symbol: str) -> int: except Exception: pass + return None + @pwndbg.lib.memoize.reset_on_objfile def static_linkage_symbol_address(symbol): diff --git a/pwndbg/gdblib/tls.py b/pwndbg/gdblib/tls.py index aa37828b..327c78ab 100644 --- a/pwndbg/gdblib/tls.py +++ b/pwndbg/gdblib/tls.py @@ -21,7 +21,9 @@ class module(ModuleType): def get_tls_base_via_errno_location(self) -> int: """Heuristically determine the base address of the TLS.""" - if pwndbg.symbol.address("__errno_location") is None or pwndbg.gdblib.arch.current not in ( + if pwndbg.gdblib.symbol.address( + "__errno_location" + ) is None or pwndbg.gdblib.arch.current not in ( "x86-64", "i386", "arm", diff --git a/pwndbg/lib/net.py b/pwndbg/lib/net.py index 826a2d18..401e5097 100644 --- a/pwndbg/lib/net.py +++ b/pwndbg/lib/net.py @@ -189,6 +189,7 @@ NETLINK_TYPES = { class Netlink(inode): eth = 0 + pid = None def __str__(self): return NETLINK_TYPES.get(self.eth, "(unknown netlink)")