|
| 1 | +## Debugging |
| 2 | + |
| 3 | +Debugging GEF has a trick, let's see some examples |
| 4 | + |
| 5 | +## Debugging a command execution with pdb |
| 6 | + |
| 7 | +Open gef.py |
| 8 | + |
| 9 | +Search for **class NopCommand(GenericCommand)**, go to do_invoke method and insert: |
| 10 | + |
| 11 | +```python |
| 12 | +import pdb; pdb.set_trace() |
| 13 | +``` |
| 14 | + |
| 15 | +Open a gdb session -> start -> nop |
| 16 | + |
| 17 | +Done! |
| 18 | + |
| 19 | +```bash |
| 20 | +gef➤ nop |
| 21 | +> /home/dreg/.gef-7c170cf6be3d84b2672a22e43b9128a23fe53c3b.py(6075)do_invoke() |
| 22 | +-> args : argparse.Namespace = kwargs["arguments"] |
| 23 | +(Pdb) ll |
| 24 | +6070 @only_if_gdb_running |
| 25 | +6071 @parse_arguments({"address": "$pc"}, {"--i": 1, "--b": True, "--f": True, "--n": True}) |
| 26 | +6072 def do_invoke(self, _: List[str], **kwargs: Any) -> None: |
| 27 | +6073 import pdb; pdb.set_trace() |
| 28 | +6074 |
| 29 | +6075 -> args : argparse.Namespace = kwargs["arguments"] |
| 30 | +6076 address = parse_address(args.address) |
| 31 | +``` |
| 32 | + |
| 33 | +Learn more about [pdb](https://docs.python.org/3/library/pdb.html) |
| 34 | + |
| 35 | +## Debugging a command execution with pycharm |
| 36 | + |
| 37 | +Install [pycharm](https://www.jetbrains.com/help/pycharm/installation-guide.html) |
| 38 | + |
| 39 | +Create a new project: |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +Go to menu -> Run -> Edit configurations...: |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Create a Python Debug Server: |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +Debug your new Unnamed: |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +Copy the info from output Window to gef.py: |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +First, add to gef.py: |
| 66 | + |
| 67 | +```python |
| 68 | +import pydevd_pycharm |
| 69 | +``` |
| 70 | + |
| 71 | +Second, search for **class NopCommand(GenericCommand)**, go to do_invoke method and insert: |
| 72 | + |
| 73 | +```python |
| 74 | +pydevd_pycharm.settrace('localhost', port=35747, stdoutToServer=True, stderrToServer=True) |
| 75 | +``` |
| 76 | + |
| 77 | +Open a gdb session -> start -> nop |
| 78 | + |
| 79 | +Done! |
| 80 | + |
| 81 | + |
0 commit comments