My thoughts on Windows ASM
Code:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib ; calls to functions in user32.lib and kernel32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.DATA ; initialized data
ClassName db "SimpleWinClass",0 ; the name of our window class
AppName db "Our First Window",0 ; the name of our window
.DATA? ; Uninitialized data
hInstance HINSTANCE ? ; Instance handle of our program
CommandLine LPSTR ?
.CODE ; Here begins our code
start:
invoke GetModuleHandle, NULL ; get the instance handle of our program.
; Under Win32, hmodule==hinstance mov hInstance,eax
mov hInstance,eax
invoke GetCommandLine ; get the command line. You don't have to call this function IF
; your program doesn't process the command line.
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT ; call the main function
invoke ExitProcess, eax ; quit our program. The exit code is returned in eax from WinMain.
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc ; register our window class
invoke CreateWindowEx,NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
NULL,\
NULL,\
hInst,\
NULL
mov hwnd,eax
invoke ShowWindow, hwnd,CmdShow ; display our window on desktop
invoke UpdateWindow, hwnd ; refresh the client area
.WHILE TRUE ; Enter message loop
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam ; return exit code in eax
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY ; if the user closes our window
invoke PostQuitMessage,NULL ; quit our application
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ; Default message processing
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
)I figure What I'll do is follow Iczelion's tutorials and then view the Disassembly of each program. I also found this Tutorial by someone named Exagone that explain more of the traditional asm: Exagone's Tut
I think I will add this to the main tutorial which has been in shambles due to no one knowing what they are doing, and those who do not giving a shit. (excuse my language). This is Exagone's introduction. It may give you a feel for how his tutorial is different then others.
Code:
00401000 >/$ 6A 00 PUSH 0 ; /pModule = NULL 00401002 |. E8 A7010000 CALL <JMP.&kernel32.GetModuleHandleA> ; \GetModuleHandleA 00401007 |. A3 44304000 MOV DWORD PTR DS:[403044],EAX 0040100C |. E8 97010000 CALL <JMP.&kernel32.GetCommandLineA> ; [GetCommandLineA 00401011 |. A3 48304000 MOV DWORD PTR DS:[403048],EAX 00401016 |. 6A 0A PUSH 0A ; /Arg4 = 0000000A 00401018 |. FF35 48304000 PUSH DWORD PTR DS:[403048] ; |Arg3 = 00000000 0040101E |. 6A 00 PUSH 0 ; |Arg2 = 00000000 00401020 |. FF35 44304000 PUSH DWORD PTR DS:[403044] ; |Arg1 = 00000000 00401026 |. E8 06000000 CALL MyFirstA.00401031 ; \MyFirstA.00401031 0040102B |. 50 PUSH EAX ; /ExitCode 0040102C \. E8 71010000 CALL <JMP.&kernel32.ExitProcess> ; \ExitProcess 00401031 /$ 55 PUSH EBP 00401032 |. 8BEC MOV EBP,ESP 00401034 |. 83C4 B0 ADD ESP,-50 00401037 |. C745 D0 300000>MOV DWORD PTR SS:[EBP-30],30 0040103E |. C745 D4 030000>MOV DWORD PTR SS:[EBP-2C],3 00401045 |. C745 D8 191140>MOV DWORD PTR SS:[EBP-28],MyFirstA.00401> 0040104C |. C745 DC 000000>MOV DWORD PTR SS:[EBP-24],0 00401053 |. C745 E0 000000>MOV DWORD PTR SS:[EBP-20],0 0040105A |. FF35 44304000 PUSH DWORD PTR DS:[403044] 00401060 |. 8F45 E4 POP DWORD PTR SS:[EBP-1C] 00401063 |. C745 F0 060000>MOV DWORD PTR SS:[EBP-10],6 0040106A |. C745 F4 000000>MOV DWORD PTR SS:[EBP-C],0 00401071 |. C745 F8 003040>MOV DWORD PTR SS:[EBP-8],MyFirstA.004030>; ASCII "SimpleWinClass" 00401078 |. 68 007F0000 PUSH 7F00 ; /RsrcName = IDI_APPLICATION 0040107D |. 6A 00 PUSH 0 ; |hInst = NULL 0040107F |. E8 F4000000 CALL <JMP.&user32.LoadIconA> ; \LoadIconA 00401084 |. 8945 E8 MOV DWORD PTR SS:[EBP-18],EAX 00401087 |. 8945 FC MOV DWORD PTR SS:[EBP-4],EAX 0040108A |. 68 007F0000 PUSH 7F00 ; /RsrcName = IDC_ARROW 0040108F |. 6A 00 PUSH 0 ; |hInst = NULL 00401091 |. E8 DC000000 CALL <JMP.&user32.LoadCursorA> ; \LoadCursorA 00401096 |. 8945 EC MOV DWORD PTR SS:[EBP-14],EAX 00401099 |. 8D45 D0 LEA EAX,DWORD PTR SS:[EBP-30] 0040109C |. 50 PUSH EAX ; /pWndClassEx 0040109D |. E8 E8000000 CALL <JMP.&user32.RegisterClassExA> ; \RegisterClassExA 004010A2 |. 6A 00 PUSH 0 ; /lParam = NULL 004010A4 |. FF75 08 PUSH DWORD PTR SS:[EBP+8] ; |hInst 004010A7 |. 6A 00 PUSH 0 ; |hMenu = NULL 004010A9 |. 6A 00 PUSH 0 ; |hParent = NULL 004010AB |. 68 00000080 PUSH 80000000 ; |Height = 80000000 (-2147483648.) 004010B0 |. 68 00000080 PUSH 80000000 ; |Width = 80000000 (-2147483648.) 004010B5 |. 68 00000080 PUSH 80000000 ; |Y = 80000000 (-2147483648.) 004010BA |. 68 00000080 PUSH 80000000 ; |X = 80000000 (-2147483648.) 004010BF |. 68 0000CF00 PUSH 0CF0000 ; |Style = WS_OVERLAPPED|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU|WS_THICKFRAME|WS_CAPTION 004010C4 |. 68 0F304000 PUSH MyFirstA.0040300F ; |WindowName = "My First Asm Window" 004010C9 |. 68 00304000 PUSH MyFirstA.00403000 ; |Class = "SimpleWinClass" 004010CE |. 6A 00 PUSH 0 ; |ExtStyle = 0 004010D0 |. E8 85000000 CALL <JMP.&user32.CreateWindowExA> ; \CreateWindowExA 004010D5 |. 8945 B0 MOV DWORD PTR SS:[EBP-50],EAX 004010D8 |. FF75 14 PUSH DWORD PTR SS:[EBP+14] ; /ShowState 004010DB |. FF75 B0 PUSH DWORD PTR SS:[EBP-50] ; |hWnd 004010DE |. E8 AD000000 CALL <JMP.&user32.ShowWindow> ; \ShowWindow 004010E3 |. FF75 B0 PUSH DWORD PTR SS:[EBP-50] ; /hWnd 004010E6 |. E8 B1000000 CALL <JMP.&user32.UpdateWindow> ; \UpdateWindow 004010EB |> 6A 00 /PUSH 0 ; /MsgFilterMax = 0 004010ED |. 6A 00 |PUSH 0 ; |MsgFilterMin = 0 004010EF |. 6A 00 |PUSH 0 ; |hWnd = NULL 004010F1 |. 8D45 B4 |LEA EAX,DWORD PTR SS:[EBP-4C] ; | 004010F4 |. 50 |PUSH EAX ; |pMsg 004010F5 |. E8 72000000 |CALL <JMP.&user32.GetMessageA> ; \GetMessageA 004010FA |. 0BC0 |OR EAX,EAX 004010FC |. 74 14 |JE SHORT MyFirstA.00401112 004010FE |. 8D45 B4 |LEA EAX,DWORD PTR SS:[EBP-4C] 00401101 |. 50 |PUSH EAX ; /pMsg 00401102 |. E8 8F000000 |CALL <JMP.&user32.TranslateMessage> ; \TranslateMessage 00401107 |. 8D45 B4 |LEA EAX,DWORD PTR SS:[EBP-4C] 0040110A |. 50 |PUSH EAX ; /pMsg 0040110B |. E8 56000000 |CALL <JMP.&user32.DispatchMessageA> ; \DispatchMessageA 00401110 |.^EB D9 \JMP SHORT MyFirstA.004010EB 00401112 |> 8B45 BC MOV EAX,DWORD PTR SS:[EBP-44] 00401115 |. C9 LEAVE 00401116 \. C2 1000 RETN 10 00401119 /. 55 PUSH EBP 0040111A |. 8BEC MOV EBP,ESP 0040111C |. 837D 0C 02 CMP DWORD PTR SS:[EBP+C],2 00401120 |. 75 1D JNZ SHORT MyFirstA.0040113F 00401122 |. 6A 00 PUSH 0 ; /Style = MB_OK|MB_APPLMODAL 00401124 |. 68 23304000 PUSH MyFirstA.00403023 ; |Title = "Noooo!!!" 00401129 |. 68 2C304000 PUSH MyFirstA.0040302C ; |Text = "Don't Kill me! Why?!" 0040112E |. FF75 08 PUSH DWORD PTR SS:[EBP+8] ; |hOwner 00401131 |. E8 48000000 CALL <JMP.&user32.MessageBoxA> ; \MessageBoxA 00401136 |. 6A 00 PUSH 0 ; /ExitCode = 0 00401138 |. E8 47000000 CALL <JMP.&user32.PostQuitMessage> ; \PostQuitMessage 0040113D |. EB 15 JMP SHORT MyFirstA.00401154 0040113F |> FF75 14 PUSH DWORD PTR SS:[EBP+14] ; /lParam 00401142 |. FF75 10 PUSH DWORD PTR SS:[EBP+10] ; |wParam 00401145 |. FF75 0C PUSH DWORD PTR SS:[EBP+C] ; |Message 00401148 |. FF75 08 PUSH DWORD PTR SS:[EBP+8] ; |hWnd 0040114B |. E8 10000000 CALL <JMP.&user32.DefWindowProcA> ; \DefWindowProcA 00401150 |. C9 LEAVE 00401151 |. C2 1000 RETN 10 00401154 |> 33C0 XOR EAX,EAX 00401156 |. C9 LEAVE 00401157 \. C2 1000 RETN 10 0040115A $-FF25 3C204000 JMP DWORD PTR DS:[<&user32.CreateWindowE>; user32.CreateWindowExA 00401160 $-FF25 34204000 JMP DWORD PTR DS:[<&user32.DefWindowProc>; user32.DefWindowProcA 00401166 $-FF25 30204000 JMP DWORD PTR DS:[<&user32.DispatchMessa>; user32.DispatchMessageA 0040116C $-FF25 20204000 JMP DWORD PTR DS:[<&user32.GetMessageA>] ; user32.GetMessageA 00401172 $-FF25 10204000 JMP DWORD PTR DS:[<&user32.LoadCursorA>] ; user32.LoadCursorA 00401178 $-FF25 14204000 JMP DWORD PTR DS:[<&user32.LoadIconA>] ; user32.LoadIconA 0040117E $-FF25 18204000 JMP DWORD PTR DS:[<&user32.MessageBoxA>] ; user32.MessageBoxA 00401184 $-FF25 1C204000 JMP DWORD PTR DS:[<&user32.PostQuitMessa>; user32.PostQuitMessage 0040118A $-FF25 38204000 JMP DWORD PTR DS:[<&user32.RegisterClass>; user32.RegisterClassExA 00401190 $-FF25 24204000 JMP DWORD PTR DS:[<&user32.ShowWindow>] ; user32.ShowWindow 00401196 $-FF25 28204000 JMP DWORD PTR DS:[<&user32.TranslateMess>; user32.TranslateMessage 0040119C $-FF25 2C204000 JMP DWORD PTR DS:[<&user32.UpdateWindow>>; user32.UpdateWindow 004011A2 .-FF25 04204000 JMP DWORD PTR DS:[<&kernel32.ExitProcess>; kernel32.ExitProcess 004011A8 $-FF25 00204000 JMP DWORD PTR DS:[<&kernel32.GetCommandL>; kernel32.GetCommandLineA 004011AE $-FF25 08204000 JMP DWORD PTR DS:[<&kernel32.GetModuleHa>; kernel32.GetModuleHandleA
Exagone's tutorial.rar

