从 C++ 调用汇编函数
在函数的顶部和下面添加了更多的程序集以获得更清晰的图像
00427F38 . 50 PUSH EAX
00427F39 . 8975 08 MOV DWORD PTR SS:[EBP+8],ESI
00427F3C . E8 0FFE0200 CALL Test.00457D50
00427F41 . 8B4D 08 MOV ECX,DWORD PTR SS:[EBP+8]
00427F44 . 51 PUSH ECX ; /Arg1
00427F45 . 8D4D E8 LEA ECX,DWORD PTR SS:[EBP-18] ; |
00427F48 . E8 13FE0200 CALL Test.00457D60 ; \Test.00457D60
00427F4D . 8B55 08 MOV EDX,DWORD PTR SS:[EBP+8]
00427F50 . 8D4D E8 LEA ECX,DWORD PTR SS:[EBP-18]
00427F53 . 52 PUSH EDX
IDA Pro 生成了这个函数声明
void *__userpurge sub_457D60<eax>(void **a1<ecx>, int a2<ebx>, int a3)
这是我尝试过的,但不起作用。
int callAddress = (*This is calculated by me 100% correct*)
//void *__userpurge sub_457D60<eax>(void **a1<ecx>, int a2<ebx>, int a3)
__declspec(naked) void stepOneWrapped(int a1, char* a2, int a3)
{
__asm{
push ebp
mov ebp, esp
push a3
mov ebx, [a2]
mov ecx, a1
call [callAddress]
leave
ret
}
}
特别注意:这就像 dll 注入,因此测试程序会与该程序一起加载。
Added a bit more assembly on top of the function and below it to get a clearer image
00427F38 . 50 PUSH EAX
00427F39 . 8975 08 MOV DWORD PTR SS:[EBP+8],ESI
00427F3C . E8 0FFE0200 CALL Test.00457D50
00427F41 . 8B4D 08 MOV ECX,DWORD PTR SS:[EBP+8]
00427F44 . 51 PUSH ECX ; /Arg1
00427F45 . 8D4D E8 LEA ECX,DWORD PTR SS:[EBP-18] ; |
00427F48 . E8 13FE0200 CALL Test.00457D60 ; \Test.00457D60
00427F4D . 8B55 08 MOV EDX,DWORD PTR SS:[EBP+8]
00427F50 . 8D4D E8 LEA ECX,DWORD PTR SS:[EBP-18]
00427F53 . 52 PUSH EDX
IDA Pro produced this function declaration
void *__userpurge sub_457D60<eax>(void **a1<ecx>, int a2<ebx>, int a3)
Here is what I tried, doesn't work.
int callAddress = (*This is calculated by me 100% correct*)
//void *__userpurge sub_457D60<eax>(void **a1<ecx>, int a2<ebx>, int a3)
__declspec(naked) void stepOneWrapped(int a1, char* a2, int a3)
{
__asm{
push ebp
mov ebp, esp
push a3
mov ebx, [a2]
mov ecx, a1
call [callAddress]
leave
ret
}
}
Special note: this is like a dll injection so the Test program is loaded with this program altogether.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要保留 ebx,因为它是一个非易失性寄存器:
但是根据你的 IDA 转储,你的参数是错误的,所以它应该是这样的(以匹配 IDA):
you need to preserve ebx, as its a non-volatile register:
but according to you IDA dump, your params are wrong, so it should be like this (to match IDA):