Page 1 of 1

varable code

Posted: Fri May 13, 2005 11:31 pm
by B.E
is it posible to excute a varable that contains machine code.

Re:varable code

Posted: Sat May 14, 2005 12:52 am
by AR
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]

Code: Select all

char *Buffer = malloc(512);
/* Fill Buffer */
__asm__ ("call %0" : : "r"(Buffer));
free(Buffer);
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).