varable code
Re:varable code
Yes, hackers do it all the time, it's called Buffer Overrun. JIT compilers also appear to do this.
All you need is a bit of assembly to jump to an arbitrary location (say somewhere in the heap) and just put code there. [Provided the OS doesn't use the NX CPU Feature]I don't know how exactly you would find this useful though. If you want to make a program extensible you would be better off with scripting then allowing the loading of arbitrary code (whether as a library or not).
All you need is a bit of assembly to jump to an arbitrary location (say somewhere in the heap) and just put code there. [Provided the OS doesn't use the NX CPU Feature]
Code: Select all
char *Buffer = malloc(512);
/* Fill Buffer */
__asm__ ("call %0" : : "r"(Buffer));
free(Buffer);