You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pwndbg/pwndbg/commands/reload.py

50 lines
1.0 KiB
Python

from __future__ import print_function
try:
from __builtins__ import reload as _reload
except:
from imp import reload as _reload
import imp
import os
import sys
import types
import gdb
import pwndbg
import pwndbg.commands
import pwndbg.events
import pwndbg.memoize
def rreload(module, mdict=None):
"""Recursively reload modules."""
name = module.__name__
if mdict is None:
mdict = []
for attribute_name in getattr(module, '__all__', []) or []:
attribute = getattr(module, attribute_name, None)
if isinstance(attribute, types.ModuleType) and attribute not in mdict:
mdict.append(attribute)
rreload(attribute, mdict)
try:
_reload(module)
except Exception as e:
pass
@pwndbg.commands.Command
def reload(*a):
pwndbg.events.on_reload()
rreload(pwndbg)
pwndbg.events.after_reload()
@pwndbg.commands.Command
def reinit_pwndbg():
"""
Makes pwndbg reinitialize all state.
"""
pwndbg.memoize.reset()
pwndbg.events.after_reload()