2

I'm working on an assignment for a systems programming class, and for extra credit we are asked to modify an executable to allow it to accept the reverse of our PIN (finding the PIN was the original assignment). I was able to use GDB to change the memory values being stored for the PIN to the reverse, and when I run the program it works as intended. The only issue is that I can't save these changes to the executable. Once I exit the debugger it reverts to normal. I've tried using "set write on" and "gdb -write " before making changes, but the changes still wouldn't stick. Does anyone know if what I'm tyring to do is even possible, or where I might be going wrong?

2

Did you remember to reload your program after set write on ?

And did you load your (writable) copy of the original program (as opposed to the professor's copy in a shared location that everyone has read access to, but noone can write) ?

Actually, i've never used gdb to patch files directly, i normally use a hex editor.

If you don't have a hex editor on your system, maybe you have xxd, which allows you to turn a binary into a hex dump and vice versa.

If all else fails, you can still do something like

echo 'X' | dd of=binary.file bs=1 seek=12345 count=1

to patch the byte at offset 12345 in your file to an X. This method has the advantage that it doesn't depend on any gnu utilities, so it works on most variants of unix.

  • I wasn't sure how to find the offset of the line in GDB, but I did find a solution to the problem. In Vim you can edit hex by typing ":%!xxd" followed by ":%!xxd -r" when finished. I guess I will stick with Vim for editing and GDB for debugging. Thanks for the help. – Steven Albertson Feb 11 '15 at 16:23
  • I distrust vim's ability to read and write binary files (for no real reason; maybe i'm just too old and remember too well how vi doesn't work with binary), so i typically xxd the original file to a hex dump, then edit that hex dump and xxd -r it back to a different binary file. This allows me to revert to the original easily if i mess something up. Of course, use the workflow that fits your need best :) – Guntram Blohm supports Monica Feb 11 '15 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.