I am trying to inject code into a running process using GDB and am getting a SIGSEGV everytime I attempt to run my code. I am on ubuntu (Oneiric). I export the code to an environment variable using a python script to print them out, then from within gdb, find the desired code with something like x/50s *((char**)environ)
, and then pick a better address to examine instructions from.
So, when I do x/30i *(addressOfCode)
, the assembly instructions there are an EXACT match with the ones I want to run. So, if I insert a breakpoint at the starting point of my code, jump there, and stepi, I get a segfault. Moreover, if I choose a place in memory and insert some NOPs, break at one of them, jump to it, and stepi, I also get a segfault.
How can I avoid this? Am I segfaulting just because I am jumping out of the designated memory for the process? What options are there for me to get around this?
Thanks for your help!