2
일부 주소에있는 다른 함수를 호출하는 함수를 만들려고합니다. 다른 함수를 호출하는 함수는 (char *로) 전달 된 args 유형, 반환 유형 및 인수 자체 만받습니다. 하지만 함수를 호출 할 때마다 또는 호출 한 후에 갑자기 충돌이 발생합니다.이전에 전달 된 인수가있는 주소에서 함수 호출
function callfunc(name,...) --Lua
local func=_G[name];
func(...)
end
그래서 여기 내 코드입니다 : 기본적으로,이 도달하는 것을 시도하고있는 무슨, C++에서이 같이 쓰기 기능입니다
#include <stdio.h>
#include <stdarg.h>
void testfunc(char *c){
printf("Text: %s\n",c);
}
void callfunc(void *ptr,char ret,char *types,int argc,...){
//#define push(w,h,t) *(t*)(w-sizeof(t))=h; w-=sizeof(t)
#define push(w) asm("push %0"::"r"(w))
typedef void (*funcptr)(...);
typedef char* char_ptr;
funcptr func=(funcptr)ptr;
double d;
char *p;
int n;
va_list vl;
va_start(vl, argc);
for(int i=0;i<argc;i++){
switch(types[i]){
case 'p':
p=va_arg(vl,char_ptr);
printf("Pushing char*: %s\n",p);
push(p);
break;
case 'n':
n=va_arg(vl,int);
printf("Pushing int: %d",n);
push(n);
break;
case 'd':
d=va_arg(vl,double);
printf("Pushing double: %f",d);
push(d);
break;
}
}
va_end(vl);
asm(
"call *%0"
::"r"(func)
);
}
int main(int argc, const char * argv[])
{
//address can be directly set to lets say 0x450F10E0
//we only know what is passed to function, we cant change function itself
callfunc((void*)testfunc,'v',"p",1,"Hi!");
return 0;
}
아무도 도와 주 시겠어요?
편집 기능 전화를 걸고 싶습니다. __stdcall입니다.
참조 http://stackoverflow.com/questions/16142284/convert-inline-assembly-code-to-c 및 http://stackoverflow.com/questions/16294841/inline-assembly-language –