Skip to content

Commit

Permalink
More type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
gsingh93 committed Dec 26, 2022
1 parent 9568859 commit ba20b32
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pwndbg/commands/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
parser.add_argument("comment", type=str, default=None, help="The text you want to comment")

file_lists = {} # type:Dict[str,str] #This saves all comments.
file_lists: Dict[str, Dict[str, str]] = {} # This saves all comments.


@pwndbg.commands.ArgparsedCommand(parser)
Expand Down
5 changes: 3 additions & 2 deletions pwndbg/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from collections import defaultdict
from io import open
from typing import DefaultDict
from typing import Dict

import gdb
Expand Down Expand Up @@ -308,7 +309,7 @@ def context_expressions(target=sys.stdout, with_banner=True, width=None):
except gdb.error as err:
value = str(err)
value = value.split("\n")
lines = []
lines: List[str] = []
for line in value:
if width and len(line) + len(exp) + 3 > width:
n = width - (len(exp) + 3) - 1 # 1 Padding...
Expand Down Expand Up @@ -388,7 +389,7 @@ def context(subcontext=None) -> None:
sections += [(arg, context_sections.get(arg[0], None)) for arg in args]

result = defaultdict(list)
result_settings = defaultdict(dict)
result_settings: DefaultDict[str, Dict] = defaultdict(dict)
for section, func in sections:
if func:
target = output(section)
Expand Down
2 changes: 1 addition & 1 deletion pwndbg/commands/heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def find_fake_fast(addr, size=None, align=False) -> None:
if size is None:
size = max_fast
elif size > addr:
print(message.warn("Size of 0x%x is greater than the target address 0x%x", (size, addr)))
print(message.warn("Size of 0x%x is greater than the target address 0x%x" % (size, addr)))
size = addr
elif size > max_fast:
print(
Expand Down
3 changes: 2 additions & 1 deletion pwndbg/commands/leakfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import queue
from typing import Dict

import gdb

Expand Down Expand Up @@ -162,7 +163,7 @@ def leakfind(
break

# A map of length->list of lines. Used to let us print in a somewhat nice manner.
output_map = {}
output_map: Dict[int, List[str]] = {}
arrow_right = C.arrow(" %s " % pwndbg.gdblib.config.chain_arrow_right)

for child in visited_map:
Expand Down
6 changes: 2 additions & 4 deletions pwndbg/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ def start(args=None) -> None:
""",
)
parser.add_argument(
"args", nargs="*", type=str, default=None, help="The arguments to run the binary with."
"args", nargs="*", type=str, default=[], help="The arguments to run the binary with."
)


@pwndbg.commands.ArgparsedCommand(parser)
@pwndbg.commands.OnlyWithFile
def entry(args=None) -> None:
if args is None:
arg = []
def entry(args=[]) -> None:
global break_on_first_instruction
break_on_first_instruction = True
run = "run " + " ".join(map(quote, args))
Expand Down
3 changes: 2 additions & 1 deletion pwndbg/commands/telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import collections
import math
from typing import List

import pwndbg.chain
import pwndbg.color.telescope as T
Expand Down Expand Up @@ -126,7 +127,7 @@ def telescope(address=None, count=telescope_lines, to_string=False, reverse=Fals
# Print everything out
result = []
last = None
collapse_buffer = []
collapse_buffer: List[str] = []
skipped_padding = (
2
+ len(offset_delimiter)
Expand Down
2 changes: 1 addition & 1 deletion pwndbg/gdblib/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def map_inner(ei_class, ehdr, objfile):
# Entries are processed in-order so that later entries
# which change page permissions (e.g. PT_GNU_RELRO) will
# override their small subset of address space.
pages = []
pages: List[pwndbg.lib.memory.Page] = []
for phdr in iter_phdrs(ehdr):
memsz = int(phdr.p_memsz)

Expand Down
2 changes: 1 addition & 1 deletion pwndbg/gdblib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# capture this so that we can fire off all of the 'start' events first.
class StartEvent:
def __init__(self) -> None:
self.registered = list()
self.registered: List[Callable] = []
self.running = False

def connect(self, function) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pwndbg/gdblib/regs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
from types import ModuleType
from typing import Dict
from typing import List

import gdb

Expand Down Expand Up @@ -134,7 +135,7 @@ def retval(self):
@property
def all(self):
regs = reg_sets[pwndbg.gdblib.arch.current]
retval = []
retval: List[str] = []
for regset in (
regs.pc,
regs.stack,
Expand Down
3 changes: 2 additions & 1 deletion pwndbg/lib/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
from functools import total_ordering
from typing import DefaultDict
from typing import List

import gdb
Expand Down Expand Up @@ -126,7 +127,7 @@ def __len__(self) -> int:
class Config:
def __init__(self) -> None:
self.params: Dict[str, Parameter] = {}
self.triggers = collections.defaultdict(lambda: [])
self.triggers: DefaultDict[str, Callable] = collections.defaultdict(lambda: [])

def add_param(
self,
Expand Down
2 changes: 1 addition & 1 deletion pwndbg/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_window_size(target=sys.stdin):
return fallback
try:
# get terminal size and force ret buffer len of 4 bytes for safe unpacking by passing equally long arg
rows, cols = struct.unpack("hh", fcntl.ioctl(target.fileno(), termios.TIOCGWINSZ, "1234"))
rows, cols = struct.unpack("hh", fcntl.ioctl(target.fileno(), termios.TIOCGWINSZ, b"1234"))
except Exception:
rows, cols = fallback
return rows, cols
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ disable_error_code = [
"name-defined",
"attr-defined",
# "var-annotated",
"index",
# "index",
# "arg-type",
"assignment",
# "operator",
"override",
"call-overload",
# "call-overload",
"union-attr",
# "str-format",
# "call-arg",
Expand Down

0 comments on commit ba20b32

Please sign in to comment.