21,458
社区成员
发帖
与我相关
我的任务
分享
void ThunkTemplate(DWORD& addr1,DWORD& addr2,int calltype=0)
{
int flag = 0;
DWORD x1,x2;
if(flag)
{
__asm //__thiscall
{
thiscall_1: mov ecx,-1; //-1占位符,运行时将被替换为this指针.
mov eax,-2; //-2占位符,运行时将被替换为CTimer::CallBcak的地址.
jmp eax;
thiscall_2: ;
}
__asm //__stdcall
{
stdcall_1: push dword ptr [esp] ; //保存(复制)返回地址到当前栈中
mov dword ptr [esp+4], -1 ; //将this指针送入栈中,即原来的返回地址处
mov eax, -2;
jmp eax ; //跳转至目标消息处理函数(类成员函数)
stdcall_2: ;
}
}
if(calltype==0)//this_call
{
__asm
{
mov x1,offset thiscall_1; //取 Thunk代码段 的地址范围.
mov x2,offset thiscall_2 ;
}
}
else
{
__asm
{
mov x1,offset stdcall_1;
mov x2,offset stdcall_2 ;
}
}
addr1 = x1;
addr2 = x2;
}
void ThunkTemplate(DWORD& addr1,DWORD& addr2,int calltype=0)
{
long x1 = 0, x2 = 0;
bool flag = false;
if (flag)
{
asm volatile
(
"thiscall_1:\n\t" // 这里我感觉有问题!
"movl -1, %ecx\n\t"
"movl -2, %eax\n\t"
"jmp * %eax\n\t"
"thiscall_2:" // 这里我感觉有问题!
);
asm volatile
(
"stdcall_1:\n\t"
"pushl (%esp)\n\t"
"movl -1, %esp\n\t" // 这里我感觉有问题!
"movl -2, %eax\n\t"
"jmp * %eax\n\t"
"stdcall_2:"
);
}
if (calltype==0)
{
asm volatile("movl $thiscall_1, %0;" : "=r"(x1)); // 这里我感觉有问题!
asm volatile("movl $thiscall_2, %0;" : "=r"(x2));
}
else
{
asm volatile("movl $stdcall_1, %0;" : "=r"(x1));
asm volatile("movl $stdcall_2, %0;" : "=r"(x1));
}
addr1 = x1;
addr2 = x2;
}
printf("\n CTimer::CallBcak,ID=%d, Elapse=%d\n",m_TimerID,m_uElapse);
static void ThunkTemplate(DWORD &addr1,DWORD &addr2,int calltype=0)
{
int flag = 0;
DWORD x1,x2;
__asm__ __volatile__("testl $0,%3;jz 0f;thiscall_1:movl $-1,%%ecx;"
"movl $-2,%%eax;jmp *%%eax;thiscall_2:;"
"stdcall_1:pushl (%%esp);movl $-1,4(%%esp);"
"movl $-2,%%eax;jmp *%%eax;stdcall_2:;"
"0:testl $0,%2;jnz 1f;movl $thiscall_1,%0;"
"movl $thiscall_2,%1;jmp 2f;1:mov $stdcall_1,%0;"
"mov $stdcall_2,%1;2:;"
:"=r"(x1)/*%0*/,"=r"(x2)/*%1*/:"r"(calltype)/*%2*/,\
"r"(flag)/*%3*/);
addr1 = x1;
addr2 = x2;
}
void ThunkTemplate(DWORD *addr1,DWORD *addr2,int calltype)
{
int flag = 0;
DWORD x1,x2;
__asm__ __volatile__("testl $0,%3;jz 0f;thiscall_1:movl $-1,%%ecx;"
"movl $-2,%%eax;jmp *%%eax;thiscall_2:;"
"stdcall_1:pushl (%%esp);movl $-1,4(%%esp);"
"movl $-2,%%eax;jmp *%%eax;stdcall_2:;"
"0:testl $0,%2;jnz 1f;movl $thiscall_1,%0;"
"movl $thiscall_2,%1;jmp 2f;1:mov $stdcall_1,%0;"
"mov $stdcall_2,%1;2:;"
:"=r"(x1)/*%0*/,"=r"(x2)/*%1*/:"r"(calltype)/*%2*/,\
"r"(flag)/*%3*/);
*addr1 = x1;
*addr2 = x2;
}