From fe0c279c70e39c18a25806f5cc5d8c659c786abf Mon Sep 17 00:00:00 2001 From: syheliel Date: Tue, 27 Sep 2022 04:04:10 +0000 Subject: [PATCH] add type for ./pwndbg/lib/ --- pwndbg/gdblib/__init__.py | 2 ++ pwndbg/gdblib/ctypes.py | 1 + pwndbg/gdblib/dt.py | 21 +++++++++------------ pwndbg/lib/arch.py | 11 ++++------- pwndbg/lib/memoize.py | 5 +++-- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/pwndbg/gdblib/__init__.py b/pwndbg/gdblib/__init__.py index a9f8a37e..91cc9348 100644 --- a/pwndbg/gdblib/__init__.py +++ b/pwndbg/gdblib/__init__.py @@ -2,3 +2,5 @@ # while `pwndbg.gdblib.arch` will represent the `Arch` object from pwndbg.gdblib import arch as arch_mod from pwndbg.gdblib.arch import arch + +from . import ctypes diff --git a/pwndbg/gdblib/ctypes.py b/pwndbg/gdblib/ctypes.py index 062c5546..0025a161 100644 --- a/pwndbg/gdblib/ctypes.py +++ b/pwndbg/gdblib/ctypes.py @@ -15,6 +15,7 @@ import pwndbg.gdblib.arch import pwndbg.gdblib.events module = sys.modules[__name__] +Structure = ctypes.LittleEndianStructure # default Structure type @pwndbg.gdblib.events.start diff --git a/pwndbg/gdblib/dt.py b/pwndbg/gdblib/dt.py index 2efd65cd..b4ea5f04 100644 --- a/pwndbg/gdblib/dt.py +++ b/pwndbg/gdblib/dt.py @@ -57,18 +57,15 @@ def happy(typename): if "unsigned" in typename: prefix = "u" typename = typename.replace("unsigned ", "") - return ( - prefix - + { - "char": "char", - "short int": "short", - "long int": "long", - "int": "int", - "long long": "longlong", - "float": "float", - "double": "double", - }[typename] - ) + return prefix + { + "char": "char", + "short int": "short", + "long int": "long", + "int": "int", + "long long": "longlong", + "float": "float", + "double": "double", + }[typename] def dt(name="", addr=None, obj=None): diff --git a/pwndbg/lib/arch.py b/pwndbg/lib/arch.py index 7adcc1b7..59eb60c1 100644 --- a/pwndbg/lib/arch.py +++ b/pwndbg/lib/arch.py @@ -13,12 +13,9 @@ class Arch: self.ptrmask = (1 << 8 * ptrsize) - 1 self.endian = endian - self.fmt = { - (4, "little"): "I", - (8, "little"): "Q", - }.get((self.ptrsize, self.endian)) + self.fmt = {(4, "little"): "I", (8, "little"): "Q",}[ + (self.ptrsize, self.endian) + ] # type: str if self.name == "arm" and self.endian == "big": self.qemu = "armeb" @@ -39,4 +36,4 @@ class Arch: return self.unpack(self.pack(integer), signed=True) # type: ignore def unsigned(self, integer: int) -> int: - return self.unpack(self.pack(integer)) + return self.unpack(self.pack(integer)) # type: ignore diff --git a/pwndbg/lib/memoize.py b/pwndbg/lib/memoize.py index da1b35d0..62777248 100644 --- a/pwndbg/lib/memoize.py +++ b/pwndbg/lib/memoize.py @@ -8,6 +8,7 @@ import functools import sys from typing import Any from typing import Callable +from typing import Dict from typing import List try: @@ -15,7 +16,7 @@ try: from collections.abc import Hashable except ImportError: # Python < 3.10 - from collections import Hashable + from collections import Hashable # type: ignore debug = False @@ -29,7 +30,7 @@ class memoize: def __init__(self, func: Callable) -> None: self.func = func - self.cache = {} + self.cache = {} # type: Dict[Any,Any] self.caches.append(self) # must be provided by base class functools.update_wrapper(self, func)