Skip to content

Commit

Permalink
added __str__ to Section
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Dec 16, 2021
1 parent a98dcb9 commit 321e104
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gef.py
Expand Up @@ -675,6 +675,9 @@ def realpath(self):
# when in a `gef-remote` session, realpath returns the path to the binary on the local disk, not remote
return self.path if __gef_remote__ is None else "/tmp/gef/{:d}/{:s}".format(__gef_remote__, self.path)

def __str__(self):
return f"Section({self.page_start:#x}, {self.page_end:#x}, {str(self.permission)})"


Zone = collections.namedtuple("Zone", ["name", "zone_start", "zone_end", "filename"])

Expand Down Expand Up @@ -2091,7 +2094,6 @@ def __get_register(self, regname):
key = curframe.pc() ^ int(curframe.read_register('sp')) # todo: check when/if gdb.Frame implements `level()`
return self.__get_register_for_selected_frame(regname, key)

@lru_cache()
def __get_register_for_selected_frame(self, regname, hash_key):
# 1st chance
try:
Expand Down Expand Up @@ -4122,7 +4124,7 @@ def stop(self):
if not addr.valid:
return False

if addr.section.permission.value & Permission.WRITE:
if addr.section.is_writable():
content = gef.memory.read_cstring(addr.value)
name = addr.info.name if addr.info else addr.section.path
msg.append(Color.colorify("Format string helper", "yellow bold"))
Expand Down Expand Up @@ -10166,7 +10168,8 @@ def do_invoke(self, argv):

nb_installed_breaks = 0

with RedirectOutputContext("/dev/null") as ctx:
# with RedirectOutputContext("/dev/null") as ctx:
if True:
for function_name in dangerous_functions:
argument_number = dangerous_functions[function_name]
FormatStringBreakpoint(function_name, argument_number)
Expand Down Expand Up @@ -11416,7 +11419,9 @@ def pid(self):
@property
def file(self):
"""Return a Path object of the target process."""
return pathlib.Path(gdb.current_progspace().filename)
if not self.__file:
self.__file = pathlib.Path(gdb.current_progspace().filename)
return self.__file

@property
def pagesize(self):
Expand All @@ -11439,6 +11444,7 @@ def canary(self):
self.__canary = (canary, canary_location)
return self.__canary

@lru_cache()
class Gef:
"""The GEF root class"""
def __init__(self):
Expand All @@ -11454,9 +11460,7 @@ def initialize_managers(self):
return

def setup(self):
"""
Setup initialize the runtime setup, which may require for the `gef` to be not None
"""
"""Setup initialize the runtime setup, which may require for the `gef` to be not None."""
self.initialize_managers()
self.gdb = GefCommand()
self.gdb.setup()
Expand Down

0 comments on commit 321e104

Please sign in to comment.