//arrayExec.cpp //complie with: g++ arrayExec.cpp -o arrayExec.exe //or cl arrayExec.cpp #include <stdio.h> #define SIZE 1024 //等效的代码 //void call(int* n) //{ // n=990; //} typedef void (*F)(int*);
int main() { char inst[SIZE]; int op=0;
inst[op++]=0x55;//push %ebp inst[op++]=0x8b;//mov %esp %ebp inst[op++]=0xec; inst[op++]=0x8b;//mov 8(%ebp),%eax inst[op++]=0x45; inst[op++]=0x08; inst[op++]=0xc7;//move $16,(%eax) inst[op++]=0x00; inst[op++]=0x10; inst[op++]=0x00; inst[op++]=0x00; inst[op++]=0x00; inst[op++]=0x5d;//pop %ebp inst[op++]=0xc3;//ret
int n=9; //vc7.1的编译器,好像对F function = (F)array;不认帐 F funcion = (F)(void*)inst; funcion(&n); //结果等价于call(&n) printf("%i\n",n); }

|