逆向分析_win_api基础(2)

win_api基础(2)
(一) 查看MessageBox返回值

环境 : vc++ 6.0

//msgbox2.cpp 配置工程为 release
#include <windows.h>
#include <stdio.h>
#include <tchar.h>

int main()
{
    int a;
    a = MessageBoxA(NULL, "content", "title", MB_YESNO);
	printf("addr : %p, \t data : %d\n",&a, a));
	/*
    if(a == IDYES)
    {
        printf("addr : %p, \t data : %d\n",&a, char(a));
    }
	*/
    return 0;
}

MessageBox的返回值为控件ID。通过printf来找到返回值放在哪个寄存器上。

生成exe文件后,用OLlydbg调试运行,按F8到出现弹窗,按下按键后如下:

00401113  |.  50               push eax
00401114  |.  FF35 30994000    push dword ptr ds:[0x409930]
0040111A  |.  FF35 2C994000    push dword ptr ds:[0x40992C]
00401120  |.  E8 DBFEFFFF      call msgbox2.00401000

重新运行exe,光标放在 00401120 call msgbox2.00401000 上,F7跟踪

00401000  /$  51               push ecx                                 ;  msgbox2.004070D8
00401001  |.  6A 04            push 0x4                                 ; /Style = MB_YESNO|MB_APPLMODAL
00401003  |.  68 50704000      push msgbox2.00407050                    ; |Title = "title"
00401008  |.  68 48704000      push msgbox2.00407048                    ; |Text = "content"
0040100D  |.  6A 00            push 0x0                                 ; |hOwner = NULL
0040100F  |.  FF15 B0604000    call dword ptr ds:[<&USER32.MessageBoxA>>; \MessageBoxA
00401015  |.  894424 00        mov dword ptr ss:[esp],eax
00401019  |.  8D4C24 00        lea ecx,dword ptr ss:[esp]
0040101D  |.  0FBEC0           movsx eax,al
00401020  |.  50               push eax
00401021  |.  51               push ecx                                 ;  msgbox2.004070D8
00401022  |.  68 30704000      push msgbox2.00407030                    ;  ASCII "addr : %p, \t data : %d\n"
00401027  |.  E8 14000000      call msgbox2.00401040
0040102C  |.  33C0             xor eax,eax
0040102E  |.  83C4 10          add esp,0x10
00401031  \.  C3               retn

可以看出返回值放在EAX,变量地址放在ECX

00401020  |.  50               push eax
00401021  |.  51               push ecx                                 ;  msgbox2.004070D8
00401022  |.  68 30704000      push msgbox2.00407030                    ;  ASCII "addr : %p, \t data : %d\n"
(二) 重新用masm plus写汇编程序验证
;02_msgbox.asm
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data
MsgBoxCaption db "Tutorial",0
MsgBoxText  db "Win32 Assembly",0

.code
start:
invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_YESNOCANCEL
.if eax == IDCANCEL
	invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_OK
.endif
invoke ExitProcess, NULL
end start
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值