Angelo942 / gdb_plus

Python library to automate gdb debugging
GNU General Public License v3.0
10 stars 1 forks source link

Question: using `gdb-multiarch` on windows connected to a remote GDB stub #6

Open axel7083 opened 3 months ago

axel7083 commented 3 months ago

I am not sure to have fully understood how your project is working, so I may be asking an irrelevant question.

In the MelonDS emulator it is possible painfully to enable a GDB stub, allowing us to use gdb-multiarch to connect to it, and debug it with very basic capabilities.

For example, once the game started, if properly configured, it will break on startup. And I can connect using the following commands

C:/mingw64/bin > ./gdb-multiarch.exe
(gdb) set arch armv5t
The target architecture is set to "armv5t".
(gdb) target remote 127.0.0.1:3333
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
(gdb) b
Breakpoint 1 at 0x2004800

I would be very interested in being able to use python to play with it, and specifically being able to automate some mechanism. This is why when I saw the following in the readme

https://github.com/Angelo942/gdb_plus/blob/6fd1a153dcf1928b42ab632f6c52de8c3aa98395/README.md?plain=1#L79-L88

I was very interested by this library.

Thanks you :) !

Angelo942 commented 2 months ago

Hi @axel7083, Just to make sure I understand your question, you would like to run a python script on windows that connects to a remote gdbserver to debug a process running on an ARM architecture ?

Right now the connection to gdb is handled by pwntools, which from what I remember doesn't support windows, but it may work with WSL.

For the direct connection to a gdbserver I hadn't though yet about supporting it, but it should just be a matter of adding three lines since it's already supported by pwntools. The code for your case would then look something like:

from gdb_plus import *
binary = ELF("<path to your game>")
context.binary = binary
dbg = Debugger(("127.0.0.1", 3333))
dbg.b(<desired address or symbol>)
...

I'm just worried about the set arch armv5t because the support for arm is still work in progress and I haven't had many opportunities to test it. It can work, but it may not recognize the architecture and require some slights adjustments.