Originally Posted by
CrazyNorman
I'm not looking to execute arbitrary code in someone else's program. Instead, I'm trying to create a runtime compiler, that generates code, and then transfers execution to it. I'll probably look at various assemblers to figure out what instructions to generate, etc.,
but once I have everything in memory, is there a way I can transfer execution to the location of a pointer in C or C++?
Cast the address to an appropriate function type and call through the pointer. The machine code will have to comprehend C calling conventions in order to handle the stack properly.
Code:
typedef void (*machine_func)();
machine_func f = (machine_func)some_address;
f();