Repository: pwndbg/pwndbg

Issue:
Port checksec command to native command and add colors
This is annoying IMHO. I want colors and no pwntools update checks here!
![image](https://github.com/pwndbg/pwndbg/assets/10009354/9d1affbb-413c-43d7-872d-5b33e22cfad9)




Discussion:
Fwiw:
![image](https://github.com/pwndbg/pwndbg/assets/10009354/cd32dc8a-460d-44a0-ae81-1e23143f6133)

e.g. partial RELRO should be yellow etc.
Hello there! I think I could give a hand to this issue. Let me give it a try.
The coloring was added in #1923.

I will still keep this open: we should use pwntools dependency to call checksec instead of a wrapper binary
> The coloring was added in #1923.
> 
> I will still keep this open: we should use pwntools dependency to call checksec instead of a wrapper binary

what exactly does this mean?

that we should use ELF directly like pwn checksec does? 

https://github.com/Gallopsled/pwntools/blob/dev/pwnlib/commandline/checksec.py#L38

Resolving patch:
diff --git a/pwndbg/commands/checksec.py b/pwndbg/commands/checksec.py
--- a/pwndbg/commands/checksec.py
+++ b/pwndbg/commands/checksec.py
@@ -1,10 +1,18 @@
 from __future__ import annotations
 
+import argparse
+
 import pwndbg.color
 import pwndbg.commands
 import pwndbg.gdblib.file
 import pwndbg.wrappers.checksec
 
+parser = argparse.ArgumentParser(
+    description="Prints out the binary security settings using `checksec`."
+)
+
+parser.add_argument("-f", "--file", type=str, help="Specify the file to run `checksec` on.")
+
 
 def color_line(line: str) -> str:
     return pwndbg.color.normal(
@@ -18,8 +26,9 @@ def color_lines(output: str) -> str:
     return "\n".join(map(color_line, output.split("\n")))
 
 
-@pwndbg.commands.ArgparsedCommand("Prints out the binary security settings using `checksec`.")
+@pwndbg.commands.ArgparsedCommand(parser, command_name="checksec")
 @pwndbg.commands.OnlyWithFile
-def checksec() -> None:
-    output = pwndbg.wrappers.checksec.get_raw_out(pwndbg.gdblib.file.get_proc_exe_file())
+def checksec(file: str) -> None:
+    local_path = file or pwndbg.gdblib.file.get_proc_exe_file()
+    output = pwndbg.wrappers.checksec.get_raw_out(local_path)
     print(color_lines(output))
diff --git a/pwndbg/wrappers/checksec.py b/pwndbg/wrappers/checksec.py
--- a/pwndbg/wrappers/checksec.py
+++ b/pwndbg/wrappers/checksec.py
@@ -1,30 +1,16 @@
 from __future__ import annotations
 
-from subprocess import CalledProcessError
+from pwnlib.elf import ELF
 
-import pwndbg.commands
-import pwndbg.lib.cache
-import pwndbg.wrappers
 
-cmd_name = "checksec"
-cmd_pwntools = ["pwn", "checksec"]
+def get_raw_out(local_path: str) -> str:
+    elf = ELF(local_path)
+    output = f"File: {elf.path}\n"
+    output += f"Arch: {elf.arch}\n"
+    output += elf.checksec()
+    return output
 
 
-@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
-@pwndbg.lib.cache.cache_until("objfile")
-def get_raw_out(local_path: str) -> str:
-    try:
-        return pwndbg.wrappers.call_cmd(get_raw_out.cmd + ["--file=" + local_path])
-    except CalledProcessError:
-        pass
-    try:
-        return pwndbg.wrappers.call_cmd(get_raw_out.cmd + ["--file", local_path])
-    except CalledProcessError:
-        pass
-    return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [local_path])
-
-
-@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
 def relro_status(local_path: str) -> str:
     relro = "No RELRO"
     out = get_raw_out(local_path)
@@ -37,7 +23,6 @@ def relro_status(local_path: str) -> str:
     return relro
 
 
-@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
 def pie_status(local_path: str) -> str:
     pie = "No PIE"
     out = get_raw_out(local_path)


Test patch: