add type for ./pwndbg/lib/

This commit is contained in:
syheliel 2022-09-27 04:04:10 +00:00 committed by Disconnect3d
parent d8a62f1120
commit fe0c279c70
5 changed files with 19 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -13,12 +13,9 @@ class Arch:
self.ptrmask = (1 << 8 * ptrsize) - 1
self.endian = endian
self.fmt = {
(4, "little"): "<I",
(4, "big"): ">I",
(8, "little"): "<Q",
(8, "big"): ">Q",
}.get((self.ptrsize, self.endian))
self.fmt = {(4, "little"): "<I", (4, "big"): ">I", (8, "little"): "<Q", (8, "big"): ">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

View File

@ -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)