Here you have the patches I did for gdb:
- To fix problem with gdbinit
- To display raw bytes in x/i and disassemble commands
- To warn about possible number of sections anti-debug trick
You can download a single patch for all changes or one for each individual change. A patched gdb binary for Intel only is available, if you trust my binaries (copy to /usr/libexec/gdb). PHP max upload size doesn’t let me add the patched source package (can’t change it due to it’s impact on others).
I have removed symbolic name printing from the x/i command because I couldn’t find an easy workaround to have all the output aligned. Gdb table system has problems and it doesn’t work well with large columns. Nevertheless the symbolic name (when available) is printed everytime breakpoint is hit and if you really need it, you can use the disassemble command to see where you are (not removed there).
The anti-debug patch just warns about the possible trick. Unless dyld bug is fixed there’s no much interest in automatically fixing the headers. If you want to test it, you can use HT Editor (hte.sourceforge.net) to easily modify the nsects. Keep in mind that HTE only supports non-fat binaries!
Have fun,
fG!
Files:
all_patches.patch
SHA1(all_patches.patch)= 74ee59cc213202d2d99c11ca8cde841890a7c7b6
number_sects_anti_debug.patch
SHA1(number_sects_anti_debug.patch)= 628498adc71b91447ba8860cec3829acf0eb7f46
gdbinit_problem.patch
SHA1(gdbinit_problem.patch)= efd8ab19d2675d601f02aa7f3b7ca21a9bee7704
show_raw_bytes.patch
SHA1(show_raw_bytes.patch)= 6ba57a401c1d3c0f6d7b31743da79ec63603752e
gdb-i386-apple-darwin.bz2
SHA1(gdb-i386-apple-darwin.bz2)= 4ce058eb26639bba0ab9974ace27adeeef446905
If you put the patch inside gdb-768 dir you might want to use -p2 option for patch (the diffs came out of my hg repository).
-
Hi
You’ve got a very interesting blog. Especially optimizing the Apple Dev Tools to be more reversing friendly is a kewl project. However I gave this a try and it doesn’t work:
gdb$ r
Unable to find Mach task port for process-id 70506: (os/kern) failure (0×5).
gdb$ quitEven if:
wishi@dawn ~/patched
% sudo chgrp procmod gdb-i386-apple-darwinwishi@dawn ~/patched
% sudo chmod 2755 gdb-i386-apple-darwinYou don’t get it working. Maybe I miss something crucial?
-
I guess I compile that stuff… because for testing reasons I used your binary. Debugging a Debugger: sounds like fun!
-
I got the same err on test using your binary:
“Unable to find Mach task port for process-id 70506: (os/kern) failure (0×5).”
whatever i will use your patch and compile it later…You have a very nice and informative blog!
i know you from the windows world for over 5 years ago.
i am a still reader, but i come twice time almost every day here.
please add the link to wishi’s blog in your “Links” collection. (very nice blog too, wishi!)Thank you and keep update!
-
I missed something… I didn’t copy the binary to /usr/libexec/gdb/ but just called it directly.
- Debugging as root was/is possible without problems: task_for_pid() by default is only accessible by root (or procmod) (http://developer.apple.com/legacy/mac/library/documentation/MacOSX/Conceptual/universal_binary/universal_binary_tips/universal_binary_tips.html).However I wonder why the binary has to be in a specific path… Anyhow.
Sorry
But I learned something. -
I backed up the original gdb-i386-apple-darwin to gdb-i386-apple-darwin.orig and copied your patched version to /usr/libexec/gdb/. I load a file in GDB using exec-file and upon executing the “run” command, I too receive the error: “Unable to find Mach task port for process-id 70506: (os/kern) failure (0×5).” The only way I’ve found to get rid of the error is to issue “sudo gdb” instead of just “gdb”. Is there a way to I could run GDB without having to issue the sudo command (to circumvent that error)? I’m running as an Admin account and the file permissions on gdb-i386-apple-darwin (patched version) are the same as the original I backed up.
-
Nope. That was it. It’s all working now. Thanks fG!
-
Did you file a radar about this? It’s possible that Apple would fix these bugs.
-
Also what about patches for Snow Leopard / 64-bit?
-
Is there anyways to modified .gdb_init to show the raw bytes instead patching and recompiling?
-
fG: your patches absolutely rock…
Just wanted to stop by and say thanks that you share your knowledge and your tools. I absolutely love your Softice derived UI
And now with IDA being QT based and available with GUI on Mac, I really feel like home.
Kudos…
-
Hi fG!
Thanks for your G-R-E-A-T blog!
When I download the file gdb-i386-apple-darwin.bz2 and decompress it a text document file appears, instead of your binary.
What should a I do?
Thanks!
Neo
-
Dear fG!
I start gdb using “sudo gdb”, then I issue “exec-file ./example” command and gdb gives me the output “unable to read unknown load command 0×80000022″.
Maybe we can try another approach. I’ve been able to compile gdb with darwin build following your instructions.
I can play around with your example file and with other programs as well, but I really want to apply your patches to display raw bytes in x/i and disassemble commands.
Inside /usr/libexec/gdb I issue:
sudo patch -p2 gdb-i386-apple-darwin all_patches.patch
But I receive this output:
patching file gdb-i386-apple-darwin
Hunk #1 FAILED at 1905.
Hunk #2 FAILED at 1955.
Hunk #3 FAILED at 1993.
Hunk #4 FAILED at 2017.
Hunk #5 FAILED at 2068.
Hunk #6 FAILED at 2096.
6 out of 6 hunks FAILED — saving rejects to file gdb-i386-apple-darwin.rej
can’t find file to patch at input line 177
Perhaps you used the wrong -p or –strip option?
The text leading up to this was:
————————–
|diff -r b4b157088bc8 gdb-768/src/gdb/disasm.c
|— a/gdb-768/src/gdb/disasm.c Wed Aug 12 10:58:48 2009 +0100
|+++ b/gdb-768/src/gdb/disasm.c Wed Aug 26 15:09:04 2009 +0100
————————–
File to patch:How can I properly apply your all_patches.patch?
Thanks again for your patience!
Neo
-
Dear fG!
After some googling I found out how to patch and compile gdb, using the Snow Leopard 10.6.6 (Build 10J567) darwinbuild.
I followed your instructions to build gdb from source, then I unpacked the “gdb-1344.tar.gz”, patched with your “all_patches.patch” file, and I packed it again as “gdb-1344.tar.”
So I issued a “darwinbuild -nochroot gdb” command and it compiled like a charm!
Now I’m able to take advantage of all your output improvements on gdb
By the way, I love how gdb now displays the raw bytes in x/i and disassemble commands!
Thanks a lot once more for all your attention and help. Now I’m already making some progresses in my reversing efforts.
I’ll keep you posted how it goes
Regards,
Neo
-

30 comments
Comments feed for this article
Trackback link: http://reverse.put.as/2009/08/26/gdb-patches/trackback/