From 9a0094b5644166484490ecd4c9e212483e81f8cf Mon Sep 17 00:00:00 2001 From: Alan Li <61896187+lebr0nli@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:46:02 +0800 Subject: [PATCH] Retrieve RELRO and PIE status directly from ELF object (#2202) Retrieving these attributes directly is more reliable and efficient than parsing the checksec output. --- pwndbg/wrappers/checksec.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pwndbg/wrappers/checksec.py b/pwndbg/wrappers/checksec.py index 66e978871..641118d32 100644 --- a/pwndbg/wrappers/checksec.py +++ b/pwndbg/wrappers/checksec.py @@ -37,22 +37,10 @@ def get_raw_out(local_path: str) -> str: def relro_status(local_path: str) -> str: - relro = "No RELRO" - out = get_raw_out(local_path) - - if "Full RELRO" in out: - relro = "Full RELRO" - elif "Partial RELRO" in out: - relro = "Partial RELRO" - - return relro + return {"Full": "Full RELRO", "Partial": "Partial RELRO", None: "No RELRO"}[ + ELF(local_path).relro + ] def pie_status(local_path: str) -> str: - pie = "No PIE" - out = get_raw_out(local_path) - - if "PIE enabled" in out: - pie = "PIE enabled" - - return pie + return "PIE enabled" if ELF(local_path).pie else "No PIE"