diff --git a/pwndbg/color/__init__.py b/pwndbg/color/__init__.py index b710b1693..258a1d539 100644 --- a/pwndbg/color/__init__.py +++ b/pwndbg/color/__init__.py @@ -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 diff --git a/pwndbg/color/theme.py b/pwndbg/color/theme.py index f2d302259..11f677dc3 100644 --- a/pwndbg/color/theme.py +++ b/pwndbg/color/theme.py @@ -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")) diff --git a/pwndbg/commands/ai.py b/pwndbg/commands/ai.py index 062d62fac..99d497494 100644 --- a/pwndbg/commands/ai.py +++ b/pwndbg/commands/ai.py @@ -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 diff --git a/pwndbg/commands/asm.py b/pwndbg/commands/asm.py index 617b273dd..4c5ba1eb6 100644 --- a/pwndbg/commands/asm.py +++ b/pwndbg/commands/asm.py @@ -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: diff --git a/pwndbg/commands/heap.py b/pwndbg/commands/heap.py index 58cee73f1..83fd7fc48 100644 --- a/pwndbg/commands/heap.py +++ b/pwndbg/commands/heap.py @@ -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( diff --git a/pwndbg/constants/__init__.py b/pwndbg/constants/__init__.py index 0d7fd8d14..a03f18afa 100644 --- a/pwndbg/constants/__init__.py +++ b/pwndbg/constants/__init__.py @@ -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 diff --git a/pwndbg/disasm/__init__.py b/pwndbg/disasm/__init__.py index 84c5592b4..a30f52eee 100644 --- a/pwndbg/disasm/__init__.py +++ b/pwndbg/disasm/__init__.py @@ -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 diff --git a/pwndbg/emu/emulator.py b/pwndbg/emu/emulator.py index dbd40c51e..1ee0f1536 100644 --- a/pwndbg/emu/emulator.py +++ b/pwndbg/emu/emulator.py @@ -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)) diff --git a/pwndbg/heap/ptmalloc.py b/pwndbg/heap/ptmalloc.py index a06537c69..1e0abd254 100644 --- a/pwndbg/heap/ptmalloc.py +++ b/pwndbg/heap/ptmalloc.py @@ -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 diff --git a/pwndbg/heap/structs.py b/pwndbg/heap/structs.py index 828e03105..fdea1c98b 100644 --- a/pwndbg/heap/structs.py +++ b/pwndbg/heap/structs.py @@ -99,7 +99,7 @@ class FakeGDBField: def __init__( self, bitpos, - name, + name: str, type, parent_type, enumval=None, diff --git a/pwndbg/hexdump.py b/pwndbg/hexdump.py index 312138f45..2942b7022 100644 --- a/pwndbg/hexdump.py +++ b/pwndbg/hexdump.py @@ -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)