こんな風に・・・
wrapperはこんな風に使うと・・・#include<stdio.h>#include<stdlib.h>#include<string.h>int wrapper();void *WrapperCreateMethod(void *wrapper, int size, unsigned int offset1, unsigned int value, unsigned int offset2, void *method);int ReleaseMethod(void *method);// --------------------------------------------------------// この関数はベースint __declspec(naked) wrapper() { __asm { POP EAX; PUSH 1234567; PUSH EAX; LEA EAX, wrapper; JMP EAX; }}void *WrapperCreateMethod(void *wrapper, int size, unsigned int offset1, unsigned int value, unsigned int offset2, void *method) { void *Method; Method = malloc(size); if(Method == NULL) return NULL; memcpy(Method, wrapper, size); *((int *)((char *)Method + offset1)) = value; *((int *)((char *)Method + offset2)) = (int)method; return Method;}void *CreateMethod(unsigned int value, void *method) { return WrapperCreateMethod(wrapper, 16, 2, value, 9, method);}int ReleaseMethod(void *method) { if(method) free(method); return 0;}// --------------------------------------------------------int __stdcall Sub1(int a);int __stdcall Sub2(int a, int b);int __stdcall Sub3(int a, int b, int c);int main(int argc, char **argv) { int (__stdcall *sub1)(); int (__stdcall *sub2)(int); int (__stdcall *sub3)(int, int); int b, c; int a; if(argc > 1) a = atoi(argv[1]); else a = 0; sub1 = CreateMethod(a, Sub1); sub2 = CreateMethod(a, Sub2); sub3 = CreateMethod(a, Sub3); sub1(); sub2(2); sub3(4, 6); ReleaseMethod(sub1); ReleaseMethod(sub2); return 0;}// 本来呼び出される関数int __stdcall Sub1(int a) { printf("Sub1:a=%d\n", a); return 0;}int __stdcall Sub2(int a, int b) { printf("Sub2:a=%d b=%d\n", a, b); return 0;}int __stdcall Sub3(int a, int b, int c) { printf("Sub3:a=%d b=%d c=%d\n", a, b, c); return 0;}VC(32bit)限定で使う。(^^;