varable code

Programming, for all ages and all languages.
Post Reply
B.E

varable code

Post by B.E »

is it posible to excute a varable that contains machine code.
AR

Re:varable code

Post 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).
Post Reply