Skip to content

Commit

Permalink
chore: fix trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrewh committed Nov 10, 2024
1 parent 73d5a94 commit 44bf39b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion lib/pyda/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def process(**kwargs):
INIT = True
if "pwndbg" in sys.modules:
pwndbg_compat.patch_pwndbg(sys.modules["pwndbg"], proc)

return proc

def xinfo(addr):
Expand Down
26 changes: 13 additions & 13 deletions lib/pyda/hacks/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ def __init__(self, sz, signed, float=False):
self.sz = sz
self.signed = signed
self.float = float

def pointer(self):
return Pointer(self)

@property
def sizeof(self):
return self.sz

@property
def alignof(self):
return self.sz

def array(self, n):
return Array(self, n)

def __eq__(self, other):
if not isinstance(other, Type):
return False
Expand All @@ -90,7 +90,7 @@ class Pointer(Type):
def __init__(self, t):
super().__init__(8, False)
self._points_to = t

def __eq__(self, other):
if not isinstance(other, Pointer):
return False
Expand All @@ -102,26 +102,26 @@ def __init__(self, t, n):
super().__init__(t.sz * n, t.signed)
self._points_to = t
self._n = n

def __eq__(self, other):
if not isinstance(other, Array):
return False

return self._points_to == other._points_to and self._n == other._n

def target(self):
return self._points_to

class Value:
def __init__(self, v):
self.v = v
self.type = Type(0, False)

def cast(self, t):
v = Value(self.v)
v.type = t
return v

def __int__(self):
assert not isinstance(self.type, Array)
assert not self.type.float
Expand All @@ -131,7 +131,7 @@ def __int__(self):
return int.from_bytes(self.v, pyda.arch.endianness())
else:
raise NotImplementedError(f"Value: {self.v}")

def __getitem__(self, idx):
assert isinstance(self.type, Array), f"type: {self.type.__class__} {Array}"
assert type(self.v) is bytes
Expand All @@ -157,7 +157,7 @@ def __init__(self):
class error(BaseException):
def __init__(self, s):
self.s = s

def __str__(self):
return self.s

Expand Down Expand Up @@ -210,7 +210,7 @@ def lookup_type(s):
class Thread():
def __init__(self, tid):
self.tid = tid

@property
def global_num(self):
return self.tid
Expand Down
48 changes: 24 additions & 24 deletions lib/pyda/hacks/pwndbg_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ def sharedlibrary_paths(self):
class GDBLibFile():
def __init__(self):
pass

def get_file(self, path, **kwargs):
p = Path(path)
if p.is_file():
return str(p)

return None


class GDBLibSymbol():
def __init__(self):
pass

def static_linkage_symbol_address(self, name):
return None

def address(self, name):
return None

def get(self, addr):
res = pyda_core.get_module_for_addr(int(addr))
if res[0] != 'unknown':
Expand All @@ -56,25 +56,25 @@ def get_glibc_section_address(section):
addr = pyda_core.get_base(l) + off
print(f"glibc addr: {hex(addr)}")
return addr

return None

class GDBLibMemory():
def __init__(self, proc):
self._p = proc

def is_readable_address(self, addr):
try:
self._p.read(addr, 1)
return True
except:
return False

def poi(self, t, addr):
v = self._p.read(addr, t.sizeof)
# print(f"poi: {hex(addr)} => {v.hex()}")
return Value(v).cast(t)

def u32(self, addr):
return int.from_bytes(self._p.read(addr, 4), pyda.arch.endianness())

Expand All @@ -86,14 +86,14 @@ def u64(self, addr):

def s64(self, addr):
return int.from_bytes(self._p.read(addr, 8), pyda.arch.endianness(), signed=True)

def pvoid(self, addr):
assert pyda.arch.ptrsize() == 8
return self.u64(addr)

def peek(self, addr):
return chr(self._p.read(addr, 1)[0])

def read(self, addr, size):
return self._p.read(addr, size)

Expand All @@ -102,18 +102,18 @@ def read(self, addr, size):
class Page():
def __init__(self, map: pyda.Map) -> None:
self._map = map

@property
def end(self):
return self._map.end

@property
def start(self):
return self._map.start

def __contains__(self, addr):
return self._map.start <= addr < self._map.end

@property
def objfile(self):
return self._map.path
Expand All @@ -133,26 +133,26 @@ def rwx(self):
class GDBLibVMMap():
def __init__(self, proc):
pass

def find(self, addr):
info = pyda.xinfo(int(addr))
return Page(info)

def get(self):
return []

class GDBLibArch():
def __init__(self, proc):
pass

@property
def endian(self):
return pyda.arch.endianness()

@property
def ptrsize(self):
return pyda.arch.ptrsize()

def __getattr__(self, name):
print(f"Arch: {name}")
raise AttributeError(f"Arch: {name}")
Expand All @@ -172,15 +172,15 @@ def patch_pwndbg(pwndbg, proc):
class GDBLibConfig():
def __init__(self):
self._d = {}

def __getattr__(self, name):
if name == "_d":
return super().__getattr__(name)
elif name in self._d:
return self._d[name]
else:
return 0

def __setattr__(self, name, value):
if name == "_d":
super().__setattr__(name, value)
Expand All @@ -190,7 +190,7 @@ def __setattr__(self, name, value):
class GDBRegs():
def __init__(self, proc):
self._p = proc

def __getattr__(self, name):
return self._p.regs[name]

Expand All @@ -199,7 +199,7 @@ def patch_gdblib(gdblib, proc):
gdblib.file = GDBLibFile()
gdblib.symbol = GDBLibSymbol()
gdblib.config = GDBLibConfig()

old_mem = gdblib.memory
gdblib.memory = GDBLibMemory(proc)
gdblib.memory.string = old_mem.string
Expand Down
Loading

0 comments on commit 44bf39b

Please sign in to comment.