Name: Anonymous 2014-05-17 2:44
#include <stdio.h>
void f() { printf("hello, world\n"); }
char prog[6];
typedef void (*callable)();
int main() {
prog[0] = 0xe8;
*(int *)(prog+1) = ((char *)f)-((char *)(prog+5));
prog[5] = 0xc3;
((callable)prog)();
}
I wrote this last night after finishing K&R. How is it?