Author: Jacky Chou
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;WinMain_Asm.Inc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386 ;
.model flat,stdcall ;
option casemap:none ;这3条不用说了
include windows.inc ;需要包含的头文件和库文件
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
include comctl32.inc
includelib comctl32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;WinMain_Asm.Asm
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include WinMain_Asm.inc
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD ;WinMain函数的申明
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Data Segment --- initialized data
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
WndClassName db "MyFirstWin",0 ;类名
WndAppName db "WinMainTest",0 ;窗口名
MsgText db "hello JackyChou",0 ;消息内容
MsgCaption db "Hello",0 ;消息标题
btnkeyinfo db "You Have Entered Key ",?,0
char db "%c",0
LButtonDown db "Left Button clicked!",0
RButtonDown db "Right Buttond clicked!",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Data Segment --- Uninitialized data
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance HINSTANCE ? ;句柄 在Win32下,应用程序的句柄和模块的句柄是一样的。您可以把实例句柄看成是您的应用程序的 ID 号。
CommandLine LPSTR ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Code Segment
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
start:
invoke GetModuleHandle,NULL ;获取我们应用程序的句柄
mov hInstance,eax
invoke GetCommandLine ;您的应用程序不处理命令行那么就无须调用 GetCommandLine,这里只是告诉您如果要调用应该怎么做。
mov CommandLine,eax
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWNORMAL ;调用WinMain函数
invoke ExitProcess,eax ;退出我们的程序,退出代码是从WinMain函数返回的EAX
WinMain proc hInStance:HINSTANCE,hPreInstance:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL hWnd:HWND ;创建局部变量
LOCAL msg:MSG
LOCAL myWndClass:WNDCLASS
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;窗口类是一个结构题,我们只要像做填空题一样,把结构体中需要填写的内容全部进行相应赋值就可以了。
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mov myWndClass.style,CS_HREDRAW or CS_VREDRAW
mov myWndClass.lpfnWndProc,offset myWndProc
mov myWndClass.cbClsExtra,NULL
mov myWndClass.cbWndExtra,NULL
push hInStance
pop myWndClass.hInstance
invoke LoadIcon,NULL,IDI_WINLOGO ;装载图标
mov myWndClass.hIcon,eax
invoke LoadCursor,NULL,IDC_HAND ;装载光标
mov myWndClass.hCursor,eax
invoke GetStockObject,WHITE_BRUSH
mov myWndClass.hbrBackground,eax ;背景
mov myWndClass.lpszMenuName,NULL
mov myWndClass.lpszClassName,offset WndClassName
invoke RegisterClass,addr myWndClass ;注册窗口
invoke CreateWindowEx,NULL,\ ;创建窗口
addr WndClassName,\
addr WndAppName,\
WS_OVERLAPPEDWINDOW, \ ;and (not WS_MAXIMIZEBOX),\ ;如何去除一个其中一个选项
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,\
NULL,\
NULL,\
hInStance,\
NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL ;显示窗口
invoke UpdateWindow,hWnd
.while TRUE ;循环处理消息
invoke GetMessage,addr msg,NULL,0,0
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endw
mov eax,msg.wParam
ret
WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;消息处理部分
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
myWndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
LOCAL hDc:HDC
.if uMsg == WM_DESTROY ;窗口销毁消息
invoke PostQuitMessage,0
.elseif uMsg == WM_PAINT ;重画消息
invoke BeginPaint,hWnd,addr ps
invoke GetDC,hWnd
mov hDc,eax
invoke TextOut,hDc,0,0,addr MsgText,(sizeof MsgText)-1
invoke ReleaseDC,hWnd,hDc
invoke EndPaint,hWnd,addr ps
.elseif uMsg == WM_KEYDOWN ;键盘键按下消息
.if wParam == VK_F8 ;F8关闭程序,相当于给程序留一个关闭的后门
invoke ExitProcess,0
.endif
invoke wsprintf,addr btnkeyinfo+21,addr char,wParam ;参考wsprintf的用法
invoke MessageBox,hWnd,addr btnkeyinfo,addr MsgCaption,MB_OK
.elseif uMsg == WM_LBUTTONDOWN ;鼠标左键按下消息
invoke MessageBox,hWnd,addr LButtonDown,addr MsgCaption,MB_OK
.elseif uMsg == WM_RBUTTONDOWN ;鼠标右键按键消息
invoke MessageBox,hWnd,addr RButtonDown,addr MsgCaption,MB_OK
.elseif uMsg == WM_CLOSE ;关闭消息
invoke ExitProcess,0
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ;默认处理
ret
.endif
xor eax,eax
ret
myWndProc endp
end start
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)