add type for ./pwndbg/lib/

pull/1200/head
syheliel 3 years ago committed by Disconnect3d
parent d8a62f1120
commit fe0c279c70

@ -2,3 +2,5 @@
# while `pwndbg.gdblib.arch` will represent the `Arch` object # while `pwndbg.gdblib.arch` will represent the `Arch` object
from pwndbg.gdblib import arch as arch_mod from pwndbg.gdblib import arch as arch_mod
from pwndbg.gdblib.arch import arch from pwndbg.gdblib.arch import arch
from . import ctypes

@ -15,6 +15,7 @@ import pwndbg.gdblib.arch
import pwndbg.gdblib.events import pwndbg.gdblib.events
module = sys.modules[__name__] module = sys.modules[__name__]
Structure = ctypes.LittleEndianStructure # default Structure type
@pwndbg.gdblib.events.start @pwndbg.gdblib.events.start

@ -57,9 +57,7 @@ def happy(typename):
if "unsigned" in typename: if "unsigned" in typename:
prefix = "u" prefix = "u"
typename = typename.replace("unsigned ", "") typename = typename.replace("unsigned ", "")
return ( return prefix + {
prefix
+ {
"char": "char", "char": "char",
"short int": "short", "short int": "short",
"long int": "long", "long int": "long",
@ -68,7 +66,6 @@ def happy(typename):
"float": "float", "float": "float",
"double": "double", "double": "double",
}[typename] }[typename]
)
def dt(name="", addr=None, obj=None): def dt(name="", addr=None, obj=None):

@ -13,12 +13,9 @@ class Arch:
self.ptrmask = (1 << 8 * ptrsize) - 1 self.ptrmask = (1 << 8 * ptrsize) - 1
self.endian = endian self.endian = endian
self.fmt = { self.fmt = {(4, "little"): "<I", (4, "big"): ">I", (8, "little"): "<Q", (8, "big"): ">Q",}[
(4, "little"): "<I", (self.ptrsize, self.endian)
(4, "big"): ">I", ] # type: str
(8, "little"): "<Q",
(8, "big"): ">Q",
}.get((self.ptrsize, self.endian))
if self.name == "arm" and self.endian == "big": if self.name == "arm" and self.endian == "big":
self.qemu = "armeb" self.qemu = "armeb"
@ -39,4 +36,4 @@ class Arch:
return self.unpack(self.pack(integer), signed=True) # type: ignore return self.unpack(self.pack(integer), signed=True) # type: ignore
def unsigned(self, integer: int) -> int: def unsigned(self, integer: int) -> int:
return self.unpack(self.pack(integer)) return self.unpack(self.pack(integer)) # type: ignore

@ -8,6 +8,7 @@ import functools
import sys import sys
from typing import Any from typing import Any
from typing import Callable from typing import Callable
from typing import Dict
from typing import List from typing import List
try: try:
@ -15,7 +16,7 @@ try:
from collections.abc import Hashable from collections.abc import Hashable
except ImportError: except ImportError:
# Python < 3.10 # Python < 3.10
from collections import Hashable from collections import Hashable # type: ignore
debug = False debug = False
@ -29,7 +30,7 @@ class memoize:
def __init__(self, func: Callable) -> None: def __init__(self, func: Callable) -> None:
self.func = func self.func = func
self.cache = {} self.cache = {} # type: Dict[Any,Any]
self.caches.append(self) # must be provided by base class self.caches.append(self) # must be provided by base class
functools.update_wrapper(self, func) functools.update_wrapper(self, func)

Loading…
Cancel
Save