mirror of https://github.com/pwndbg/pwndbg
More type hints (#1746)
* More safe typehints from autotyping * More aggressive type hints from autotyping
This commit is contained in:
parent
772eddc51e
commit
addf96f9bc
|
@ -132,7 +132,7 @@ disable_colors = theme.add_param(
|
|||
|
||||
|
||||
def generateColorFunctionInner(old, new):
|
||||
def wrapper(text):
|
||||
def wrapper(text: str):
|
||||
return new(old(text))
|
||||
|
||||
return wrapper
|
||||
|
|
|
@ -6,9 +6,9 @@ class ColorParameter(pwndbg.lib.config.Parameter):
|
|||
pass
|
||||
|
||||
|
||||
def add_param(name, default, set_show_doc, color_param=False):
|
||||
def add_param(name: str, default, set_show_doc, color_param: bool = False):
|
||||
return config.add_param(name, default, set_show_doc, scope="theme")
|
||||
|
||||
|
||||
def add_color_param(name, default, set_show_doc):
|
||||
def add_color_param(name: str, default, set_show_doc):
|
||||
return config.add_param_obj(ColorParameter(name, default, set_show_doc, scope="theme"))
|
||||
|
|
|
@ -68,7 +68,7 @@ dummy = False
|
|||
verbosity = 0
|
||||
|
||||
|
||||
def set_dummy_mode(d=True):
|
||||
def set_dummy_mode(d=True) -> None:
|
||||
global dummy
|
||||
dummy = d
|
||||
return
|
||||
|
|
|
@ -55,7 +55,7 @@ input_group.add_argument("-i", "--infile", default=None, type=str, help="Specify
|
|||
|
||||
|
||||
@pwndbg.commands.ArgparsedCommand(parser, command_name="asm")
|
||||
def asm(shellcode, format, arch, avoid, infile):
|
||||
def asm(shellcode, format, arch, avoid, infile) -> None:
|
||||
if infile:
|
||||
print(message.warn("Going to read from file: " + infile))
|
||||
with open(infile) as file:
|
||||
|
|
|
@ -115,7 +115,7 @@ def format_bin(bins: Bins, verbose=False, offset=None):
|
|||
return result
|
||||
|
||||
|
||||
def print_no_arena_found_error(tid=None):
|
||||
def print_no_arena_found_error(tid=None) -> None:
|
||||
if tid is None:
|
||||
tid = pwndbg.gdblib.proc.thread_id
|
||||
print(
|
||||
|
@ -125,7 +125,7 @@ def print_no_arena_found_error(tid=None):
|
|||
)
|
||||
|
||||
|
||||
def print_no_tcache_bins_found_error(tid=None):
|
||||
def print_no_tcache_bins_found_error(tid=None) -> None:
|
||||
if tid is None:
|
||||
tid = pwndbg.gdblib.proc.thread_id
|
||||
print(
|
||||
|
|
|
@ -19,7 +19,7 @@ arches = {
|
|||
}
|
||||
|
||||
|
||||
def syscall(number, arch):
|
||||
def syscall(number: int, arch):
|
||||
"""
|
||||
Given a syscall number and architecture, returns the name of the syscall.
|
||||
E.g. execve == 59 on x86-64
|
||||
|
|
|
@ -62,7 +62,7 @@ backward_cache: DefaultDict = collections.defaultdict(lambda: None)
|
|||
|
||||
|
||||
@pwndbg.lib.cache.cache_until("objfile")
|
||||
def get_disassembler_cached(arch, ptrsize, endian, extra=None):
|
||||
def get_disassembler_cached(arch, ptrsize: int, endian, extra=None):
|
||||
arch = CapstoneArch[arch]
|
||||
|
||||
if extra is None:
|
||||
|
@ -209,7 +209,7 @@ DO_NOT_EMULATE = {
|
|||
}
|
||||
|
||||
|
||||
def can_run_first_emulate():
|
||||
def can_run_first_emulate() -> bool:
|
||||
"""
|
||||
Disable the emulate config variable if we don't have enough memory to use it
|
||||
See https://github.com/pwndbg/pwndbg/issues/1534
|
||||
|
|
|
@ -168,7 +168,7 @@ class Emulator:
|
|||
if DEBUG:
|
||||
self.hook_add(U.UC_HOOK_CODE, self.trace_hook)
|
||||
|
||||
def __getattr__(self, name):
|
||||
def __getattr__(self, name: str):
|
||||
reg = self.get_reg_enum(name)
|
||||
|
||||
if reg:
|
||||
|
@ -237,7 +237,7 @@ class Emulator:
|
|||
|
||||
return True
|
||||
|
||||
def hook_mem_invalid(self, uc, access, address, size, value, user_data) -> bool:
|
||||
def hook_mem_invalid(self, uc, access, address, size: int, value, user_data) -> bool:
|
||||
debug("# Invalid access at %#x", address)
|
||||
|
||||
# Page-align the start address
|
||||
|
@ -367,7 +367,7 @@ class Emulator:
|
|||
# We're done emulating
|
||||
return self._prev, self._curr
|
||||
|
||||
def until_jump_hook_code(self, _uc, address, instruction_size, _user_data) -> None:
|
||||
def until_jump_hook_code(self, _uc, address, instruction_size: int, _user_data) -> None:
|
||||
# We have not emulated any instructions yet.
|
||||
if self._prev is None:
|
||||
pass
|
||||
|
@ -405,7 +405,7 @@ class Emulator:
|
|||
self.emulate_with_hook(self.until_syscall_hook_code)
|
||||
return (self.until_syscall_address, None)
|
||||
|
||||
def until_syscall_hook_code(self, uc, address, size, user_data) -> None:
|
||||
def until_syscall_hook_code(self, uc, address, size: int, user_data) -> None:
|
||||
data = binascii.hexlify(self.mem_read(address, size))
|
||||
debug("# Executing instruction at %(address)#x with bytes %(data)s", locals())
|
||||
self.until_syscall_address = address
|
||||
|
@ -446,7 +446,7 @@ class Emulator:
|
|||
yield a
|
||||
a = self.single_step(pc)
|
||||
|
||||
def single_step_hook_code(self, _uc, address, instruction_size, _user_data) -> None:
|
||||
def single_step_hook_code(self, _uc, address, instruction_size: int, _user_data) -> None:
|
||||
# For whatever reason, the hook will hit twice on
|
||||
# unicorn >= 1.0.2rc4, but not on unicorn-1.0.2rc1~unicorn-1.0.2rc3,
|
||||
# So we use a counter to ensure the code run only once
|
||||
|
@ -472,6 +472,6 @@ class Emulator:
|
|||
value = self.uc.reg_read(enum)
|
||||
debug("uc.reg_read(%(name)s) ==> %(value)x", locals())
|
||||
|
||||
def trace_hook(self, _uc, address, instruction_size, _user_data) -> None:
|
||||
def trace_hook(self, _uc, address, instruction_size: int, _user_data) -> None:
|
||||
data = binascii.hexlify(self.mem_read(address, instruction_size))
|
||||
debug("# trace_hook: %#-8x %r", (address, data))
|
||||
|
|
|
@ -1020,7 +1020,7 @@ class GlibcMemoryAllocator(pwndbg.heap.heap.MemoryAllocator):
|
|||
return self.minsize
|
||||
return (req + self.size_sz + self.malloc_align_mask) & ~self.malloc_align_mask
|
||||
|
||||
def chunk_flags(self, size):
|
||||
def chunk_flags(self, size: int):
|
||||
return (
|
||||
size & ptmalloc.PREV_INUSE,
|
||||
size & ptmalloc.IS_MMAPPED,
|
||||
|
@ -1080,7 +1080,7 @@ class GlibcMemoryAllocator(pwndbg.heap.heap.MemoryAllocator):
|
|||
else:
|
||||
return None
|
||||
|
||||
def fastbin_index(self, size):
|
||||
def fastbin_index(self, size: int):
|
||||
if pwndbg.gdblib.arch.ptrsize == 8:
|
||||
return (size >> 4) - 2
|
||||
else:
|
||||
|
@ -1128,7 +1128,7 @@ class GlibcMemoryAllocator(pwndbg.heap.heap.MemoryAllocator):
|
|||
num_tcachebins = entries.type.sizeof // entries.type.target().sizeof
|
||||
safe_lnk = pwndbg.glibc.check_safe_linking()
|
||||
|
||||
def tidx2usize(idx):
|
||||
def tidx2usize(idx: int):
|
||||
"""Tcache bin index to chunk size, following tidx2usize macro in glibc malloc.c"""
|
||||
return idx * self.malloc_alignment + self.minsize - self.size_sz
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class FakeGDBField:
|
|||
def __init__(
|
||||
self,
|
||||
bitpos,
|
||||
name,
|
||||
name: str,
|
||||
type,
|
||||
parent_type,
|
||||
enumval=None,
|
||||
|
|
|
@ -18,7 +18,7 @@ color_scheme = None
|
|||
printable = None
|
||||
|
||||
|
||||
def groupby(width, array, fill=None):
|
||||
def groupby(width: int, array, fill=None):
|
||||
return pwnlib.util.lists.group(width, array, underfull_action="fill", fill_value=fill)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue