I\'ll explain:
Let\'s say I\'m interested in replacing the rand()
function used by a certain application.
So I attach gdb to this process and ma
I have a new solution, based on the new original constraints. (I am not deleting my first answer, as others may find it useful.)
I have been doing a bunch of research, and I think it would work with a bit more fiddling.
info functions
to find the address of rand
in the symbol tableUse dlopen then dlsym to load the function into memory and get its address
call (int) dlopen("my_rand.so", 1)
-> -val-
call (unsigned int) dlsym(-val-, "my_rand")
-> my_rand_addr
jumpq 0x*my_rand_addr*
instructionset {int}*rand_addr* = *my_rand_addr*
to change symbol table instructionContinue
execution: now whenever rand
is called, it will jump to my_rand
insteadThis is a bit complicated, and very round-about, but I'm pretty sure it would work. The only thing I haven't accomplished yet is creating the jumpq
instruction code. Everything up until that point works fine.