Introduce `pwndbg.aglib.arch` and port `pwndbg.lib.memory` to it (#2366)

pull/2373/head
Matt. 1 year ago committed by GitHub
parent 6d92fa9318
commit 0e83450f2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,15 @@
from __future__ import annotations
import pwndbg
# We will optimize this module in the future, by having it work in the same
# way the `gdblib` version of it works, and that will come at the same
# time this module gets expanded to have the full feature set of its `gdlib`
# coutnerpart. For now, though, this should be good enough.
def __getattr__(name):
if name == "endian":
return pwndbg.dbg.selected_inferior().arch().endian
elif name == "ptrsize":
return pwndbg.dbg.selected_inferior().arch().ptrsize

@ -6,6 +6,8 @@ from __future__ import annotations
import os
import pwndbg.aglib.arch
PAGE_SIZE = 0x1000
PAGE_MASK = ~(PAGE_SIZE - 1)
@ -132,12 +134,7 @@ class Page:
)
def __str__(self) -> str:
# This module requires GDB, so it causes import failures in unit tests.
# This will stop being a problem as soon as this module gets ported to
# aglib.arch, but, for now we have to add this as a quick stopgap.
import pwndbg.gdblib.arch
return f"{self.vaddr:#{2 + 2 * pwndbg.gdblib.arch.ptrsize}x} {self.vaddr + self.memsz:#{2 + 2 * pwndbg.gdblib.arch.ptrsize}x} {self.permstr} {self.memsz:8x} {self.offset:6x} {self.objfile or ''}"
return f"{self.vaddr:#{2 + 2 * pwndbg.aglib.arch.ptrsize}x} {self.vaddr + self.memsz:#{2 + 2 * pwndbg.aglib.arch.ptrsize}x} {self.permstr} {self.memsz:8x} {self.offset:6x} {self.objfile or ''}"
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.__str__()!r})"

Loading…
Cancel
Save