【例子】堆栈中运行程序

#include<stdio.h> #include<string.h> typedef int (*PFunc0)(const char*,...); void test() { PFunc0 pf = printf; pf("test/n"); // printf("1"); //栈上直接调用函数会出错,用函数指针正常。应该是相对偏移和绝对偏移的原因。 } typedef void (*PFunc1)(); int main() { char buf[1024] = {0}; memcpy( buf, (void*)test, 1024 ); //将代码拷贝到堆栈 ((PFunc1)(int)buf)(); //执行堆栈中的代码 return 0; }

你可能感兴趣的:(【例子】堆栈中运行程序)