c - run code stored in memory -
problem:
run non-trivial c program stored on heap or data section of c program asm instructions.
my progress:
ran set of simple instructions print stdout. instructions stored on heap , allowed page containing instructions executed , calling raw data though function. worked fine.
next up, want given statically linked c program, read it's binary , able run it's main function while in memory c program.
i believe issues are: * jumping main function code * changing binary file's addresses created when linking relative code lies in memory
please let me know if approach or whether missed important , best way go it.
thank you
modern oses try not let execute code in data because it's security nightmare. http://en.wikipedia.org/wiki/no-execute_bit
even if past that, there lots more 'gotchas' because both programs think 'own' stack/heap/etc. once new program executes, it's various bits of ram old program stomped on. (exec
exists reason, cleanly go 1 program another.)
if need load code, should make first 1 library, use dlopen
run it. (you can use objcopy
extract subroutine want , turn library.)
alternately, can start program (in process) , use strace
inject little bit of code process control it.
(if you're trying shell code, should have said so. that's whole 'nother can of worms.)
Comments
Post a Comment