prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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)
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pwndbg/wrappers/checksec.py`
  Content:
  ```
  1 from __future__ import annotations
  2 
  3 from subprocess import CalledProcessError
  4 
  5 import pwndbg.commands
  6 import pwndbg.lib.cache
  7 import pwndbg.wrappers
  8 
  9 cmd_name = "checksec"
  10 cmd_pwntools = ["pwn", "checksec"]
  11 
  12 
  13 @pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
  14 @pwndbg.lib.cache.cache_until("objfile")
  15 def get_raw_out(local_path: str) -> str:
  16     try:
  17         return pwndbg.wrappers.call_cmd(get_raw_out.cmd + ["--file=" + local_path])
  18     except CalledProcessError:
  19         pass
  20     try:
  21         return pwndbg.wrappers.call_cmd(get_raw_out.cmd + ["--file", local_path])
  22     except CalledProcessError:
  23         pass
  24     return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [local_path])
  25 
  26 
  27 @pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
  28 def relro_status(local_path: str) -> str:
  29     relro = "No RELRO"
  30     out = get_raw_out(local_path)
  31 
  32     if "Full RELRO" in out:
  33         relro = "Full RELRO"
  34     elif "Partial RELRO" in out:
  35         relro = "Partial RELRO"
  36 
  37     return relro
  38 
  39 
  40 @pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
  41 def pie_status(local_path: str) -> str:
  42     pie = "No PIE"
  43     out = get_raw_out(local_path)
  44 
  45     if "PIE enabled" in out:
  46         pie = "PIE enabled"
  47 
  48     return pie
  49
  ```
  
  Path: `pwndbg/commands/checksec.py`
  Content:
  ```
  1 from __future__ import annotations
  2 
  3 import pwndbg.color
  4 import pwndbg.commands
  5 import pwndbg.gdblib.file
  6 import pwndbg.wrappers.checksec
  7 
  8 
  9 def color_line(line: str) -> str:
  10     return pwndbg.color.normal(
  11         line.replace("*", pwndbg.color.green("*"))
  12         .replace(":", f":{pwndbg.color.GREEN}")
  13         .replace("No", f"{pwndbg.color.RED}No")
  14     )
  15 
  16 
  17 def color_lines(output: str) -> str:
  18     return "\n".join(map(color_line, output.split("\n")))
  19 
  20 
  21 @pwndbg.commands.ArgparsedCommand("Prints out the binary security settings using `checksec`.")
  22 @pwndbg.commands.OnlyWithFile
  23 def checksec() -> None:
  24     output = pwndbg.wrappers.checksec.get_raw_out(pwndbg.gdblib.file.get_proc_exe_file())
  25     print(color_lines(output))
  26
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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 @@
       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 @@
       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)
  
verification_info: {"golden_diff": "diff --git a/pwndbg/commands/checksec.py b/pwndbg/commands/checksec.py\n--- a/pwndbg/commands/checksec.py\n+++ b/pwndbg/commands/checksec.py\n@@ -1,10 +1,18 @@\n from __future__ import annotations\n \n+import argparse\n+\n import pwndbg.color\n import pwndbg.commands\n import pwndbg.gdblib.file\n import pwndbg.wrappers.checksec\n \n+parser = argparse.ArgumentParser(\n+    description=\"Prints out the binary security settings using `checksec`.\"\n+)\n+\n+parser.add_argument(\"-f\", \"--file\", type=str, help=\"Specify the file to run `checksec` on.\")\n+\n \n def color_line(line: str) -> str:\n     return pwndbg.color.normal(\n@@ -18,8 +26,9 @@\n     return \"\\n\".join(map(color_line, output.split(\"\\n\")))\n \n \n-@pwndbg.commands.ArgparsedCommand(\"Prints out the binary security settings using `checksec`.\")\n+@pwndbg.commands.ArgparsedCommand(parser, command_name=\"checksec\")\n @pwndbg.commands.OnlyWithFile\n-def checksec() -> None:\n-    output = pwndbg.wrappers.checksec.get_raw_out(pwndbg.gdblib.file.get_proc_exe_file())\n+def checksec(file: str) -> None:\n+    local_path = file or pwndbg.gdblib.file.get_proc_exe_file()\n+    output = pwndbg.wrappers.checksec.get_raw_out(local_path)\n     print(color_lines(output))\ndiff --git a/pwndbg/wrappers/checksec.py b/pwndbg/wrappers/checksec.py\n--- a/pwndbg/wrappers/checksec.py\n+++ b/pwndbg/wrappers/checksec.py\n@@ -1,30 +1,16 @@\n from __future__ import annotations\n \n-from subprocess import CalledProcessError\n+from pwnlib.elf import ELF\n \n-import pwndbg.commands\n-import pwndbg.lib.cache\n-import pwndbg.wrappers\n \n-cmd_name = \"checksec\"\n-cmd_pwntools = [\"pwn\", \"checksec\"]\n+def get_raw_out(local_path: str) -> str:\n+    elf = ELF(local_path)\n+    output = f\"File: {elf.path}\\n\"\n+    output += f\"Arch: {elf.arch}\\n\"\n+    output += elf.checksec()\n+    return output\n \n \n-@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)\n-@pwndbg.lib.cache.cache_until(\"objfile\")\n-def get_raw_out(local_path: str) -> str:\n-    try:\n-        return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [\"--file=\" + local_path])\n-    except CalledProcessError:\n-        pass\n-    try:\n-        return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [\"--file\", local_path])\n-    except CalledProcessError:\n-        pass\n-    return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [local_path])\n-\n-\n-@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)\n def relro_status(local_path: str) -> str:\n     relro = \"No RELRO\"\n     out = get_raw_out(local_path)\n@@ -37,7 +23,6 @@\n     return relro\n \n \n-@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)\n def pie_status(local_path: str) -> str:\n     pie = \"No PIE\"\n     out = get_raw_out(local_path)\n", "issue": "Port checksec command to native command and add colors\nThis is annoying IMHO. I want colors and no pwntools update checks here!\r\n![image](https://github.com/pwndbg/pwndbg/assets/10009354/9d1affbb-413c-43d7-872d-5b33e22cfad9)\r\n\r\n\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom subprocess import CalledProcessError\n\nimport pwndbg.commands\nimport pwndbg.lib.cache\nimport pwndbg.wrappers\n\ncmd_name = \"checksec\"\ncmd_pwntools = [\"pwn\", \"checksec\"]\n\n\n@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)\n@pwndbg.lib.cache.cache_until(\"objfile\")\ndef get_raw_out(local_path: str) -> str:\n    try:\n        return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [\"--file=\" + local_path])\n    except CalledProcessError:\n        pass\n    try:\n        return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [\"--file\", local_path])\n    except CalledProcessError:\n        pass\n    return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [local_path])\n\n\n@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)\ndef relro_status(local_path: str) -> str:\n    relro = \"No RELRO\"\n    out = get_raw_out(local_path)\n\n    if \"Full RELRO\" in out:\n        relro = \"Full RELRO\"\n    elif \"Partial RELRO\" in out:\n        relro = \"Partial RELRO\"\n\n    return relro\n\n\n@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)\ndef pie_status(local_path: str) -> str:\n    pie = \"No PIE\"\n    out = get_raw_out(local_path)\n\n    if \"PIE enabled\" in out:\n        pie = \"PIE enabled\"\n\n    return pie\n", "path": "pwndbg/wrappers/checksec.py"}, {"content": "from __future__ import annotations\n\nimport pwndbg.color\nimport pwndbg.commands\nimport pwndbg.gdblib.file\nimport pwndbg.wrappers.checksec\n\n\ndef color_line(line: str) -> str:\n    return pwndbg.color.normal(\n        line.replace(\"*\", pwndbg.color.green(\"*\"))\n        .replace(\":\", f\":{pwndbg.color.GREEN}\")\n        .replace(\"No\", f\"{pwndbg.color.RED}No\")\n    )\n\n\ndef color_lines(output: str) -> str:\n    return \"\\n\".join(map(color_line, output.split(\"\\n\")))\n\n\n@pwndbg.commands.ArgparsedCommand(\"Prints out the binary security settings using `checksec`.\")\n@pwndbg.commands.OnlyWithFile\ndef checksec() -> None:\n    output = pwndbg.wrappers.checksec.get_raw_out(pwndbg.gdblib.file.get_proc_exe_file())\n    print(color_lines(output))\n", "path": "pwndbg/commands/checksec.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom pwnlib.elf import ELF\n\n\ndef get_raw_out(local_path: str) -> str:\n    elf = ELF(local_path)\n    output = f\"File: {elf.path}\\n\"\n    output += f\"Arch: {elf.arch}\\n\"\n    output += elf.checksec()\n    return output\n\n\ndef relro_status(local_path: str) -> str:\n    relro = \"No RELRO\"\n    out = get_raw_out(local_path)\n\n    if \"Full RELRO\" in out:\n        relro = \"Full RELRO\"\n    elif \"Partial RELRO\" in out:\n        relro = \"Partial RELRO\"\n\n    return relro\n\n\ndef pie_status(local_path: str) -> str:\n    pie = \"No PIE\"\n    out = get_raw_out(local_path)\n\n    if \"PIE enabled\" in out:\n        pie = \"PIE enabled\"\n\n    return pie\n", "path": "pwndbg/wrappers/checksec.py"}, {"content": "from __future__ import annotations\n\nimport argparse\n\nimport pwndbg.color\nimport pwndbg.commands\nimport pwndbg.gdblib.file\nimport pwndbg.wrappers.checksec\n\nparser = argparse.ArgumentParser(\n    description=\"Prints out the binary security settings using `checksec`.\"\n)\n\nparser.add_argument(\"-f\", \"--file\", type=str, help=\"Specify the file to run `checksec` on.\")\n\n\ndef color_line(line: str) -> str:\n    return pwndbg.color.normal(\n        line.replace(\"*\", pwndbg.color.green(\"*\"))\n        .replace(\":\", f\":{pwndbg.color.GREEN}\")\n        .replace(\"No\", f\"{pwndbg.color.RED}No\")\n    )\n\n\ndef color_lines(output: str) -> str:\n    return \"\\n\".join(map(color_line, output.split(\"\\n\")))\n\n\n@pwndbg.commands.ArgparsedCommand(parser, command_name=\"checksec\")\n@pwndbg.commands.OnlyWithFile\ndef checksec(file: str) -> None:\n    local_path = file or pwndbg.gdblib.file.get_proc_exe_file()\n    output = pwndbg.wrappers.checksec.get_raw_out(local_path)\n    print(color_lines(output))\n", "path": "pwndbg/commands/checksec.py"}]}