Modifying global variables with ptrace programmatically
I've been playing with ptrace
to see if I can modify the value of simple global integers in a C program. I know that I can use PEEKDATA
and POKEDATA
to accomplish this. However, these need information about where the variable is stored in memory in order to function. All the tutorials I've googled for seem to suggest the most popular way to do this is by using nm
or objdump
manually to obtain this address. Is there a way to do this more programmatically without knowing anything about the variable address or even the variable name beforehand (as below):
int i=0; //Assume i is defined globally and is the first integer defined in the code
//Code to modify i (this is what I'm looking for)
//More code here
//Print modified value of i
//Restore value of i later on
I also thought about intercepting system calls that could take integers as arguments, and while this would work, I was wondering if there was a more robust way of accomplishing this.
链接地址: http://www.djcxy.com/p/66380.html上一篇: DETATCH,pid,NULL,NULL)在死pid上被调用?
下一篇: 以编程方式用ptrace修改全局变量