mirror of https://github.com/pwndbg/pwndbg
add type for `./pwndbg/lib` (#1135)
* add type for `./pwndbg/lib` * add more type hints Co-authored-by: syheliel <syheliel@gmail.com>
This commit is contained in:
parent
ffdff0f966
commit
2296999ed9
|
@ -1,3 +1,5 @@
|
|||
from typing import List
|
||||
|
||||
import pwndbg.gdblib.arch
|
||||
|
||||
|
||||
|
@ -8,7 +10,7 @@ class ABI:
|
|||
|
||||
#: List or registers which should be filled with arguments before
|
||||
#: spilling onto the stack.
|
||||
register_arguments = []
|
||||
register_arguments: List[str] = []
|
||||
|
||||
#: Minimum alignment of the stack.
|
||||
#: The value used is min(context.bytes, stack_alignment)
|
||||
|
@ -29,7 +31,7 @@ class ABI:
|
|||
self.stack_minimum = minimum
|
||||
|
||||
@staticmethod
|
||||
def default():
|
||||
def default(): # type: () -> ABI
|
||||
return {
|
||||
(32, "i386", "linux"): linux_i386,
|
||||
(64, "x86-64", "linux"): linux_amd64,
|
||||
|
@ -42,7 +44,7 @@ class ABI:
|
|||
}[(8 * pwndbg.gdblib.arch.ptrsize, pwndbg.gdblib.arch.current, "linux")]
|
||||
|
||||
@staticmethod
|
||||
def syscall():
|
||||
def syscall(): # type: () -> ABI
|
||||
return {
|
||||
(32, "i386", "linux"): linux_i386_syscall,
|
||||
(64, "x86-64", "linux"): linux_amd64_syscall,
|
||||
|
@ -55,7 +57,7 @@ class ABI:
|
|||
}[(8 * pwndbg.gdblib.arch.ptrsize, pwndbg.gdblib.arch.current, "linux")]
|
||||
|
||||
@staticmethod
|
||||
def sigreturn():
|
||||
def sigreturn(): # type: () -> SigreturnABI
|
||||
return {
|
||||
(32, "i386", "linux"): linux_i386_sigreturn,
|
||||
(64, "x86-64", "linux"): linux_amd64_sigreturn,
|
||||
|
|
|
@ -79,7 +79,7 @@ KNOWN_AIDS = {
|
|||
}
|
||||
|
||||
|
||||
def aid_name(uid):
|
||||
def aid_name(uid): # types: (int) -> str
|
||||
if uid in KNOWN_AIDS:
|
||||
return KNOWN_AIDS[uid]
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ class Arch:
|
|||
def unpack(self, data: bytearray) -> int:
|
||||
return struct.unpack(self.fmt, data)[0]
|
||||
|
||||
def signed(self, integer):
|
||||
return self.unpack(self.pack(integer), signed=True)
|
||||
def signed(self, integer: int) -> int:
|
||||
return self.unpack(self.pack(integer), signed=True) # type: ignore
|
||||
|
||||
def unsigned(integer):
|
||||
def unsigned(self, integer: int) -> int:
|
||||
return self.unpack(self.pack(integer))
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
import ctypes
|
||||
from typing import Dict
|
||||
|
||||
import pwndbg.gdblib.ctypes
|
||||
|
||||
|
@ -81,7 +82,7 @@ AT_CONSTANTS = {
|
|||
35: "AT_L1D_CACHESHAPE",
|
||||
36: "AT_L2_CACHESHAPE",
|
||||
37: "AT_L3_CACHESHAPE",
|
||||
}
|
||||
} # type: Dict[int,str]
|
||||
|
||||
|
||||
class constants:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import collections
|
||||
|
||||
from pycparser import CParser
|
||||
from pycparser import CParser # type: ignore
|
||||
from pycparser import c_ast
|
||||
|
||||
|
||||
|
|
|
@ -6,13 +6,14 @@ GCC and any flags it should be executed with.
|
|||
import glob
|
||||
import os
|
||||
import platform
|
||||
from typing import List
|
||||
|
||||
from pwndbg.lib.arch import Arch
|
||||
|
||||
printed_message = False
|
||||
|
||||
|
||||
def which(arch: Arch):
|
||||
def which(arch): # type: (Arch) -> List[str]
|
||||
gcc = _which_binutils("g++", arch)
|
||||
|
||||
if not gcc:
|
||||
|
@ -21,9 +22,9 @@ def which(arch: Arch):
|
|||
printed_message = True
|
||||
print("Can't find appropriate GCC, using default version")
|
||||
|
||||
if ptrsize == 32:
|
||||
if arch.ptrsize == 32:
|
||||
return ["g++", "-m32"]
|
||||
elif ptrsize == 64:
|
||||
elif arch.ptrsize == 64:
|
||||
return ["g++", "-m32"]
|
||||
|
||||
return [gcc] + _flags(arch.name)
|
||||
|
@ -72,7 +73,7 @@ def _which_binutils(util, arch, **kwargs):
|
|||
return res[0]
|
||||
|
||||
|
||||
def _flags(arch_name):
|
||||
def _flags(arch_name): # type: (str) -> List[str]
|
||||
if arch_name == "i386":
|
||||
return ["-m32"]
|
||||
if arch_name.endswith("x86-64"):
|
||||
|
|
|
@ -8,6 +8,7 @@ import functools
|
|||
import sys
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import List
|
||||
|
||||
try:
|
||||
# Python >= 3.10
|
||||
|
@ -75,7 +76,7 @@ class forever(memoize):
|
|||
Memoizes forever - for a pwndbg session or until `_reset` is called explicitly.
|
||||
"""
|
||||
|
||||
caches = []
|
||||
caches = [] # type: List[forever]
|
||||
|
||||
@staticmethod
|
||||
def _reset():
|
||||
|
@ -84,7 +85,7 @@ class forever(memoize):
|
|||
|
||||
|
||||
class reset_on_stop(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[reset_on_stop]
|
||||
kind = "stop"
|
||||
|
||||
@staticmethod
|
||||
|
@ -96,7 +97,7 @@ class reset_on_stop(memoize):
|
|||
|
||||
|
||||
class reset_on_prompt(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[reset_on_prompt]
|
||||
kind = "prompt"
|
||||
|
||||
@staticmethod
|
||||
|
@ -108,7 +109,7 @@ class reset_on_prompt(memoize):
|
|||
|
||||
|
||||
class reset_on_exit(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[reset_on_exit]
|
||||
kind = "exit"
|
||||
|
||||
@staticmethod
|
||||
|
@ -120,7 +121,7 @@ class reset_on_exit(memoize):
|
|||
|
||||
|
||||
class reset_on_objfile(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[reset_on_objfile]
|
||||
kind = "objfile"
|
||||
|
||||
@staticmethod
|
||||
|
@ -132,7 +133,7 @@ class reset_on_objfile(memoize):
|
|||
|
||||
|
||||
class reset_on_start(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[reset_on_start]
|
||||
kind = "start"
|
||||
|
||||
@staticmethod
|
||||
|
@ -144,7 +145,7 @@ class reset_on_start(memoize):
|
|||
|
||||
|
||||
class reset_on_cont(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[reset_on_cont]
|
||||
kind = "cont"
|
||||
|
||||
@staticmethod
|
||||
|
@ -156,7 +157,7 @@ class reset_on_cont(memoize):
|
|||
|
||||
|
||||
class while_running(memoize):
|
||||
caches = []
|
||||
caches = [] # type: List[while_running]
|
||||
kind = "running"
|
||||
caching = False
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ def page_size_align(address: int) -> int:
|
|||
return round_up(address, PAGE_SIZE)
|
||||
|
||||
|
||||
def page_offset(address):
|
||||
def page_offset(address: int) -> int:
|
||||
return address & (PAGE_SIZE - 1)
|
||||
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@ which prevent output from appearing on-screen inside of certain event handlers.
|
|||
"""
|
||||
|
||||
import sys
|
||||
from typing import * # noqa note: TextIO is not abaliable in low python version
|
||||
|
||||
|
||||
class Stdio:
|
||||
queue = []
|
||||
queue = [] # type: List[Tuple[TextIO, TextIO, TextIO]]
|
||||
|
||||
def __enter__(self, *a, **kw):
|
||||
self.queue.append((sys.stdin, sys.stdout, sys.stderr))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from random import choice
|
||||
from typing import List
|
||||
|
||||
TIPS = [
|
||||
# GDB hints
|
||||
|
@ -22,7 +23,7 @@ TIPS = [
|
|||
"Want to display each context panel in a separate tmux window? See https://github.com/pwndbg/pwndbg/blob/dev/FEATURES.md#splitting--layouting-context",
|
||||
"The $heap_base GDB variable can be used to refer to the starting address of the heap after running the `heap` command",
|
||||
"Use the `errno` (or `errno <number>`) command to see the name of the last or provided (libc) error",
|
||||
]
|
||||
] # type: List[str]
|
||||
|
||||
|
||||
def get_tip_of_the_day() -> str:
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
import subprocess
|
||||
|
||||
|
||||
def build_id():
|
||||
def build_id(): # type: () -> str
|
||||
"""
|
||||
Returns pwndbg commit id if git is available.
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue