|
|
|
@ -153,6 +153,42 @@ def add_custom_structure(custom_structure_name: str) -> None:
|
|
|
|
load_custom_structure.__wrapped__(custom_structure_name, pwndbg_custom_structure_path)
|
|
|
|
load_custom_structure.__wrapped__(custom_structure_name, pwndbg_custom_structure_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_structure_from_header(header_file: str, custom_structure_name: str = None) -> None:
|
|
|
|
|
|
|
|
# Properly handle the provided or default name for the custom structure
|
|
|
|
|
|
|
|
custom_structure_name = (
|
|
|
|
|
|
|
|
custom_structure_name.strip()
|
|
|
|
|
|
|
|
if custom_structure_name
|
|
|
|
|
|
|
|
else os.path.splitext(os.path.basename(header_file))[0]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not custom_structure_name:
|
|
|
|
|
|
|
|
print(message.error("Invalid structure name provided or generated."))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pwndbg_custom_structure_path = os.path.join(pwndbg_cachedir, custom_structure_name) + ".c"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(pwndbg_custom_structure_path):
|
|
|
|
|
|
|
|
option = input(
|
|
|
|
|
|
|
|
message.notice(f"Structure '{custom_structure_name}' already exists. Overwrite? [y/n] ")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if option != "y":
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with open(header_file, "r") as src, open(pwndbg_custom_structure_path, "w") as f:
|
|
|
|
|
|
|
|
content = src.read().strip()
|
|
|
|
|
|
|
|
if not content:
|
|
|
|
|
|
|
|
print(message.notice("Header file is empty, skipping..."))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
f.write(content)
|
|
|
|
|
|
|
|
except (IOError, OSError) as e:
|
|
|
|
|
|
|
|
print(message.error(f"Failed to process header file: {e}"))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Avoid checking for file existance. Call the decorator wrapper directly.
|
|
|
|
|
|
|
|
load_custom_structure.__wrapped__(custom_structure_name, pwndbg_custom_structure_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OnlyWhenStructFileExists
|
|
|
|
@OnlyWhenStructFileExists
|
|
|
|
def edit_custom_structure(custom_structure_name: str, custom_structure_path: str = "") -> None:
|
|
|
|
def edit_custom_structure(custom_structure_name: str, custom_structure_path: str = "") -> None:
|
|
|
|
# Lookup an editor to use for editing the custom structure.
|
|
|
|
# Lookup an editor to use for editing the custom structure.
|
|
|
|
@ -224,6 +260,14 @@ parser.add_argument(
|
|
|
|
default=None,
|
|
|
|
default=None,
|
|
|
|
type=str,
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
|
|
"-f",
|
|
|
|
|
|
|
|
"--file",
|
|
|
|
|
|
|
|
metavar="filepath",
|
|
|
|
|
|
|
|
help="Add a new custom structure from header file",
|
|
|
|
|
|
|
|
default=None,
|
|
|
|
|
|
|
|
type=str,
|
|
|
|
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument(
|
|
|
|
"-r",
|
|
|
|
"-r",
|
|
|
|
"--remove",
|
|
|
|
"--remove",
|
|
|
|
@ -259,9 +303,11 @@ parser.add_argument(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pwndbg.commands.ArgparsedCommand(parser)
|
|
|
|
@pwndbg.commands.ArgparsedCommand(parser)
|
|
|
|
def cymbol(add: str, remove: str, edit: str, load: str, show: str) -> None:
|
|
|
|
def cymbol(add: str, file: str, remove: str, edit: str, load: str, show: str) -> None:
|
|
|
|
if add:
|
|
|
|
if add:
|
|
|
|
add_custom_structure(add)
|
|
|
|
add_custom_structure(add)
|
|
|
|
|
|
|
|
elif file:
|
|
|
|
|
|
|
|
add_structure_from_header(file)
|
|
|
|
elif remove:
|
|
|
|
elif remove:
|
|
|
|
remove_custom_structure(remove)
|
|
|
|
remove_custom_structure(remove)
|
|
|
|
elif edit:
|
|
|
|
elif edit:
|
|
|
|
|