+ All Categories
Home > Documents > Td Win32asm 320.Asm

Td Win32asm 320.Asm

Date post: 03-Dec-2015
Category:
Upload: z4rm4r
View: 239 times
Download: 0 times
Share this document with a friend
Description:
Skola asemblera TD zakon
21
td_win32asm_320.asm ;============================================================================== ; Test Department's WINDOWS 32 BIT x86 ASSEMBLY example 320 ;============================================================================== ;============================================================================== ; ==> Part 320 : WRONG Window Proc (WP1) and CORRECT Window Proc (WP2). ;------------------------------------------------------------------------------ ; Wrong code inside my window procedure ... ; Thanks flys to Renй for the bug report (http://betov.free.fr/SpAsm.html). ; First I can't believe that, so I wrote this program to visualize the error. ; All my programs are corrected now (date: 23.10.2000). ; ; Test Department [email protected] ;============================================================================== ; Assembler directives ;------------------------------------------------------------------------------ .386 ; specifies the processor our program want run on .Model Flat ,StdCall ; Flat for Win9x (32 Bit), Calling Convention option casemap:none ; case sensitive ! ;============================================================================== ; Include all files where API functins resist you want use, set correct path ;------------------------------------------------------------------------------ include D:\Masm32\include\windows.inc includelib kernel32.lib includelib user32.lib includelib gdi32.lib ;============================================================================== ; Declaration of used API functions,take a look into WIN32.HLP and *.inc files ;------------------------------------------------------------------------------ GetModuleHandleA PROTO :DWORD CreateSolidBrush PROTO :DWORD LoadIconA PROTO :DWORD,:DWORD LoadCursorA PROTO :DWORD,:DWORD RegisterClassExA PROTO :DWORD CreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORD ShowWindow PROTO :DWORD,:DWORD UpdateWindow PROTO :DWORD GetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORD TranslateMessage PROTO :DWORD DispatchMessageA PROTO :DWORD PostQuitMessage PROTO :DWORD DefWindowProcA PROTO :DWORD,:DWORD,:DWORD,:DWORD ExitProcess PROTO :DWORD MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD SendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORD ;============================================================================== ; .const = the constants area starts here, constants are defined and fixed Page 1
Transcript

td_win32asm_320.asm;==============================================================================; Test Department's WINDOWS 32 BIT x86 ASSEMBLY example 320;==============================================================================

;==============================================================================; ==> Part 320 : WRONG Window Proc (WP1) and CORRECT Window Proc (WP2).;------------------------------------------------------------------------------; Wrong code inside my window procedure ...; Thanks flys to Renй for the bug report (http://betov.free.fr/SpAsm.html).; First I can't believe that, so I wrote this program to visualize the error.; All my programs are corrected now (date: 23.10.2000).;; Test Department [email protected]

;==============================================================================; Assembler directives;------------------------------------------------------------------------------.386 ; specifies the processor our program want run on.Model Flat ,StdCall ; Flat for Win9x (32 Bit), Calling Conventionoption casemap:none ; case sensitive !

;==============================================================================; Include all files where API functins resist you want use, set correct path;------------------------------------------------------------------------------include D:\Masm32\include\windows.incincludelib kernel32.libincludelib user32.libincludelib gdi32.lib

;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetModuleHandleA PROTO :DWORDCreateSolidBrush PROTO :DWORDLoadIconA PROTO :DWORD,:DWORDLoadCursorA PROTO :DWORD,:DWORDRegisterClassExA PROTO :DWORDCreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORDShowWindow PROTO :DWORD,:DWORDUpdateWindow PROTO :DWORDGetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDTranslateMessage PROTO :DWORDDispatchMessageA PROTO :DWORDPostQuitMessage PROTO :DWORDDefWindowProcA PROTO :DWORD,:DWORD,:DWORD,:DWORDExitProcess PROTO :DWORDMessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORDSendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORD

;==============================================================================; .const = the constants area starts here, constants are defined and fixed

Page 1

td_win32asm_320.asm;------------------------------------------------------------------------------.const; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) -WP2_CallBack equ [ebp+4] ;return addressWP2_hWnd equ [ebp+8] ;handle of window who receives messageWP2_uMsg equ [ebp+12] ;the message numberWP2_wParam equ [ebp+16] ;extra info about the messageWP2_lParam equ [ebp+20] ;extra info about the message

;==============================================================================; .Data = the data area starts here, datas are defined but not fixed;------------------------------------------------------------------------------.DataIconName db "TDIcon",0 ;icon name in rc fileClassStatic db "STATIC",0 ;predefined ClassNameClassButton db "BUTTON",0 ;predefined ClassNameNameButton db "SendMessage",0 ;button1 window texttable_ASCII db 48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70table_HEX db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

W1_Class db "TDWinClass1",0 ;name of window classW1_WindowName db "Test Department Error",0 ;text in title barW1_NameStatic db ".data?",13,10 db "WP1_CallBack dd ?",13,10 db "WP1_hWnd dd ?",13,10 db "WP1_uMsg dd ?",13,10 db "WP1_wParam dd ?",13,10 db "WP1_lParam dd ?",13,10,13,10 db "WP1:",13,10 db "pop WP1_CallBack",13,10 db "pop WP1_hWnd",13,10 db "pop WP1_uMsg",13,10 db "pop WP1_wParam",13,10 db "pop WP1_lParam",13,10 db "push WP1_CallBack",13,10 db "pushad",13,10,13,10 db "cmp WP1_uMsg,2h",13,10 db "jne WP1_return",13,10 db "push 0h",13,10 db "call PostQuitMessage",13,10 db "popad",13,10 db "xor eax,eax",13,10 db "ret",13,10,13,10 db "WP1_return:",13,10 db "popad",13,10 db "push WP1_lParam",13,10 db "push WP1_wParam",13,10 db "push WP1_uMsg",13,10 db "push WP1_hWnd",13,10 db "call DefWindowProcA",13,10 db "ret",0

W1_MB1_Title db "Error in WinProc",0

Page 2

td_win32asm_320.asmW1_MB1_Text db "before API SendMessage",13,10 db "====================",13,10W1_before_CallBack db "Return..--------",13,10W1_before_hWnd db "hWnd....--------",13,10W1_before_uMsg db "uMsg....--------",13,10W1_before_wParam db "wParam..--------",13,10W1_before_lParam db "lParam..--------",13,10,13,10 db "while API SendMessage",13,10 db "====================",13,10W1_while_CallBack db "Return..--------",13,10W1_while_hWnd db "hWnd....--------",13,10W1_while_uMsg db "uMsg....--------",13,10W1_while_wParam db "wParam..--------",13,10W1_while_lParam db "lParam..--------",13,10,13,10 db "after API SendMessage",13,10 db "====================",13,10W1_after_CallBack db "Return..--------",13,10W1_after_hWnd db "hWnd....--------",13,10W1_after_uMsg db "uMsg....--------",13,10W1_after_wParam db "wParam..--------",13,10W1_after_lParam db "lParam..--------",13,10,13,10 db "Register on Proc return",13,10 db "====================",13,10W1_register_EBP db "[EBP]...--------",13,10W1_register_ESP db "[ESP]...--------",0

W2_Class db "TDWinClass2",0 ;name of window classW2_WindowName db "Test Department Correct",0;text in title barW2_NameStatic db ".const",13,10 db "WP2_CallBack equ [ebp+4]",13,10 db "WP2_hWnd equ [ebp+8]",13,10 db "WP2_uMsg equ [ebp+12]",13,10 db "WP2_wParam equ [ebp+16]",13,10 db "WP2_lParam equ [ebp+20]",13,10,13,10 db "WP2:",13,10 db "push ebp",13,10 db "mov ebp,esp",13,10 db "pushad",13,10,13,10 db "cmp WP2_uMsg,2h",13,10 db "jne WP2_return",13,10 db "push 0h",13,10 db "call PostQuitMessage",13,10 db "popad",13,10 db "xor eax,eax",13,10 db "mov esp,ebp",13,10 db "pop ebp",13,10 db "ret 10h",13,10,13,10 db "WP2_return:",13,10 db "popad",13,10 db "push WP2_lParam",13,10 db "push WP2_wParam",13,10 db "push WP2_uMsg",13,10 db "push WP2_hWnd",13,10

Page 3

td_win32asm_320.asm db "call DefWindowProcA",13,10 db "mov esp,ebp",13,10 db "pop ebp",13,10 db "ret 10h",0 W2_MB1_Title db "Correct WinProc",0 W2_MB1_Text db "before API SendMessage",13,10 db "====================",13,10W2_before_CallBack db "Return..--------",13,10W2_before_hWnd db "hWnd....--------",13,10W2_before_uMsg db "uMsg....--------",13,10W2_before_wParam db "wParam..--------",13,10W2_before_lParam db "lParam..--------",13,10,13,10 db "while API SendMessage",13,10 db "====================",13,10W2_while_CallBack db "Return..--------",13,10W2_while_hWnd db "hWnd....--------",13,10W2_while_uMsg db "uMsg....--------",13,10W2_while_wParam db "wParam..--------",13,10W2_while_lParam db "lParam..--------",13,10,13,10 db "after API SendMessage",13,10 db "====================",13,10W2_after_CallBack db "Return..--------",13,10W2_after_hWnd db "hWnd....--------",13,10W2_after_uMsg db "uMsg....--------",13,10W2_after_wParam db "wParam..--------",13,10W2_after_lParam db "lParam..--------",13,10,13,10 db "Register on Proc return",13,10 db "====================",13,10W2_register_EBP db "[EBP]...--------",13,10W2_register_ESP db "[ESP]...--------",0

;==============================================================================; .Data? = the data? area starts here, not defined and not fixed;------------------------------------------------------------------------------.data?hInstance dd ? ;program handle (API=GetModuleHandleA)

W1_handleStatic dd ? ;handle static windowW1_handleButton dd ? ;handle button window

align 4; - WndClassEx Structure ( API=RegisterClassExA ) -W1_cbSize dd ? ;size in bytes of this structureW1_style dd ? ;window styleW1_lpfnWndProc dd ? ;address of user proc functionW1_cbclsExtra dd ? ;extra bytes to allocate set to 0W1_cbWndExtra dd ? ;extra bytes class directive, rc fileW1_hInstance dd ? ;program handle(API=GetModuleHandleA)W1_hIcon dd ? ;handle of icon (API=LoadIconA)W1_hcursor dd ? ;handle of cursor (API=LoadCursor)W1_hbrBackground dd ? ;background color, 0=transparentW1_lpszMenuName dd ? ;name of menu class in resource file

Page 4

td_win32asm_320.asmW1_lpszClassName dd ? ;name of windows this window classW1_hIconSm dd ? ;iconhandle 0=search in resource fileW1_hdcDest dd ? ;handle of dest. device context

align 4; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structureW1_hWnd dd ? ;handle of window who receives messageW1_message dd ? ;the message numberW1_wParam dd ? ;extra info about the messageW1_lParam dd ? ;extra info about the messageW1_time dd ? ;time the message was postedW1_xpt dd ? ;cursor x-position, POINT strucW1_ypt dd ? ;cursor x-position, POINT struc

; - Push Parameter MAIN WINDOW CallBack procedure ( API=RegisterClassExA ) -WP1_CallBack dd ? ;return address of calling routineWP1_hWnd dd ? ;handle of window who receives messageWP1_uMsg dd ? ;the message numberWP1_wParam dd ? ;extra info about the messageWP1_lParam dd ? ;extra info about the message

W2_handleStatic dd ? ;handle static windowW2_handleButton dd ? ;handle button window

align 4; - WndClassEx Structure ( API=RegisterClassExA ) -W2_cbSize dd ? ;size in bytes of this structureW2_style dd ? ;window styleW2_lpfnWndProc dd ? ;address of user proc functionW2_cbclsExtra dd ? ;extra bytes to allocate set to 0W2_cbWndExtra dd ? ;extra bytes class directive, rc fileW2_hInstance dd ? ;program handle(API=GetModuleHandleA)W2_hIcon dd ? ;handle of icon (API=LoadIconA)W2_hcursor dd ? ;handle of cursor (API=LoadCursor)W2_hbrBackground dd ? ;background color, 0=transparentW2_lpszMenuName dd ? ;name of menu class in resource fileW2_lpszClassName dd ? ;name of windows this window classW2_hIconSm dd ? ;iconhandle 0=search in resource fileW2_hdcDest dd ? ;handle of dest. device context

align 4; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structureW2_hWnd dd ? ;handle of window who receives messageW2_message dd ? ;the message numberW2_wParam dd ? ;extra info about the messageW2_lParam dd ? ;extra info about the messageW2_time dd ? ;time the message was postedW2_xpt dd ? ;cursor x-position, POINT strucW2_ypt dd ? ;cursor x-position, POINT struc

;==============================================================================; .CODE = our code area starts here Main = label of our program code

Page 5

td_win32asm_320.asm;------------------------------------------------------------------------------.CodeMain:

;==============================================================================; Always get your program ID first (API=GetModuleHandleA);------------------------------------------------------------------------------push 0h ;lpModuleHandle, 0=get program handlecall GetModuleHandleA ;- API Function -mov hInstance,eax ;return value in eax=handle of program

;==============================================================================; The API function "RegisterClassExA" registers a window class.; This API needs a "WNDCLASSEX" structure so we fill it with correct values.;------------------------------------------------------------------------------mov W1_hInstance,eax ;eax=handle of programmov W1_cbSize,30h ;size in bytes of WNDCLASSEX structuremov W1_style,3h ;window stylemov W1_lpfnWndProc,OFFSET WP1 ;address of user lpfnWndProc functionmov W1_cbclsExtra,0h ;extra bytes to allocate set to 0mov W1_cbWndExtra,0h ;class directive in rc file;------------------------------------------------------------------------------; API "CreateSolidBrush" creates a logical brush with the specified solid color;------------------------------------------------------------------------------push 000000FFh ;crColor, brush color valuecall CreateSolidBrush ;- API Function -mov W1_hbrBackground,eax ;background colormov W1_lpszMenuName,0h ;menu name in resource file,0=no menumov W1_lpszClassName,OFFSET W1_Class;name of windows classmov W1_hIconSm,0h ;iconhandle 0=search in rc file;------------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and stores the; handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push OFFSET IconName ;icon-string or icon resource idpush hInstance ;our program handlecall LoadIconA ;- API Function -mov W1_hIcon,eax ;store handle of newly loaded icon;------------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set; hInstance to 0 and lpCursorName to a default system cursor value, here 32512; Then we store the cursor handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push 32512 ;lpCursorName, default value in dezimalpush 0h ;hInstance, 0=default system cursorcall LoadCursorA ;- API Function -mov W1_hcursor,eax ;store handle of the cursor;------------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx";------------------------------------------------------------------------------push OFFSET W1_cbSize ;pointer to WNDCLASSEX structurecall RegisterClassExA ;- API Function -

Page 6

td_win32asm_320.asm;==============================================================================; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an; extended style. The return value in EAX is the handle of the new window.; This API sends a WM_CREATE message to the window procedure (WP1).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush 0h ;hWndParent, handle parent window 0=nopush 00000248h ;intnHeight, window height pixelpush 000000E4h ;intnWidth, window width pixelpush 00000008h ;inty, vertical position windowpush 00000008h ;intx, horizontal position windowpush 04CA0000h ;dwStyle, look into WIN32.HLPpush OFFSET W1_WindowName ;lpWindowName, pointer to window namepush OFFSET W1_Class ;lpClassName, pointer to class namepush 100h ;dwExStyle, extra window style 0=nocall CreateWindowExA ;- API Function -mov W1_hWnd,eax ;hwnd,return value=handle of window

;==============================================================================; API "ShowWindow" function sets the specified window's show state. ;------------------------------------------------------------------------------push 1h ;nCmdShow, show state 1=SW_SHOWNORMALpush W1_hWnd ;hwnd, handle of windowcall ShowWindow ;- API Function -

;==============================================================================; API "UpdateWindow" updates the area of the specified window by sending a; WM_PAINT message to the window if the window's update region is not empty.;------------------------------------------------------------------------------push W1_hWnd ;hwnd, handle of windowcall UpdateWindow ;- API Function -

;==============================================================================; The API function "RegisterClassExA" registers a window class.; This API needs a "WNDCLASSEX" structure so we fill it with correct values.;------------------------------------------------------------------------------mov W2_cbSize,30h ;size in bytes of WNDCLASSEX structuremov W2_style,3h ;window stylemov W2_lpfnWndProc,OFFSET WP2 ;address of user lpfnWndProc functionmov W2_cbclsExtra,0h ;extra bytes to allocate set to 0mov W2_cbWndExtra,0h ;class directive in rc file;------------------------------------------------------------------------------; API "CreateSolidBrush" creates a logical brush with the specified solid color;------------------------------------------------------------------------------push 0000FF00h ;crColor, brush color valuecall CreateSolidBrush ;- API Function -mov W2_hbrBackground,eax ;background colormov W2_lpszMenuName,0h ;menu name in resource file,0=no menumov W2_lpszClassName,OFFSET W2_Class;name of windows classmov W2_hIconSm,0h ;iconhandle 0=search in rc file;------------------------------------------------------------------------------

Page 7

td_win32asm_320.asm; API "LoadIconA" loads an icon defined in the resource file and stores the; handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push OFFSET IconName ;icon-string or icon resource idpush hInstance ;our program handlecall LoadIconA ;- API Function -mov W2_hIcon,eax ;store handle of newly loaded icon;------------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set; hInstance to 0 and lpCursorName to a default system cursor value, here 32512; Then we store the cursor handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push 32512 ;lpCursorName, default value in dezimalpush 0h ;hInstance, 0=default system cursorcall LoadCursorA ;- API Function -mov W2_hcursor,eax ;store handle of the cursor;------------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx";------------------------------------------------------------------------------push OFFSET W2_cbSize ;pointer to WNDCLASSEX structurecall RegisterClassExA ;- API Function -

;==============================================================================; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an; extended style. The return value in EAX is the handle of the new window.; This API sends a WM_CREATE message to the window procedure (WP1).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush 0h ;hWndParent, handle parent window 0=nopush 00000248h ;intnHeight, window height pixelpush 000000E4h ;intnWidth, window width pixelpush 00000008h ;inty, vertical position windowpush 00000190h ;intx, horizontal position windowpush 04CA0000h ;dwStyle, look into WIN32.HLPpush OFFSET W2_WindowName ;lpWindowName, pointer to window namepush OFFSET W2_Class ;lpClassName, pointer to class namepush 100h ;dwExStyle, extra window style 0=nocall CreateWindowExA ;- API Function -mov W2_hWnd,eax ;hwnd,return value=handle of window

;==============================================================================; API "ShowWindow" function sets the specified window's show state. ;------------------------------------------------------------------------------push 1h ;nCmdShow, show state 1=SW_SHOWNORMALpush W2_hWnd ;hwnd, handle of windowcall ShowWindow ;- API Function -

;==============================================================================; API "UpdateWindow" updates the area of the specified window by sending a; WM_PAINT message to the window if the window's update region is not empty.;------------------------------------------------------------------------------

Page 8

td_win32asm_320.asmpush W2_hWnd ;hwnd, handle of windowcall UpdateWindow ;- API Function -

LoopGetMessage:;==============================================================================; API "GetMessageA" retrieves a message + places it in the specified structure.;------------------------------------------------------------------------------push 0h ;wMsgFilterMax, highest message valuepush 0h ;wMsgFilterMin, lowest message valuepush 0h ;hWnd, handle of window who gets msg.push OFFSET W1_hWnd ;lpMsg, pointer to MSG structurecall GetMessageA ;- API Function -cmp eax,0h ;check if return value=0 (exit)je ExitPrg ;if return value is 0 goto LABEL

;==============================================================================; API "TranslateMessage" translates virtual-key messages in character messages;------------------------------------------------------------------------------push OFFSET W1_hWnd ;lpMSG, pointer to msg structurecall TranslateMessage ;- API Function - keyboard code

;==============================================================================; API "DispatchMessageA" function dispatches a message to a window procedure.;------------------------------------------------------------------------------push OFFSET W1_hWnd ;lpMSG, pointer to msg structurecall DispatchMessageA ;- API Function -

;==============================================================================; API "GetMessageA" retrieves a message + places it in the specified structure.;------------------------------------------------------------------------------push 0h ;wMsgFilterMax, highest message valuepush 0h ;wMsgFilterMin, lowest message valuepush 0h ;hWnd, handle of window who gets msg.push OFFSET W2_hWnd ;lpMsg, pointer to MSG structurecall GetMessageA ;- API Function -cmp eax,0h ;check if return value=0 (exit)je ExitPrg ;if return value is 0 goto LABEL

;==============================================================================; API "TranslateMessage" translates virtual-key messages in character messages;------------------------------------------------------------------------------push OFFSET W2_hWnd ;lpMSG, pointer to msg structurecall TranslateMessage ;- API Function - keyboard code

;==============================================================================; API "DispatchMessageA" function dispatches a message to a window procedure.;------------------------------------------------------------------------------push OFFSET W2_hWnd ;lpMSG, pointer to msg structurecall DispatchMessageA ;- API Function -jmp LoopGetMessage ;check for message again, goto LABEL

ExitPrg:;==============================================================================

Page 9

td_win32asm_320.asm; Next we terminate our program (API=ExitProcess);------------------------------------------------------------------------------push hInstance ;push our programm handle to exitcall ExitProcess ;- API Function -

;##############################################################################; The Window Procedure (API=RegisterClassExA) for this registered window (WP1).;------------------------------------------------------------------------------WP1:pop WP1_CallBack ;POP return address lpfnWndProcpop WP1_hWnd ;handle of window who receives messagepop WP1_uMsg ;the message numberpop WP1_wParam ;extra info about the messagepop WP1_lParam ;extra info about the messagepush WP1_CallBack ;PUSH return address lpfnWndProc !!!!!pushad ;push all register to the stack

mov eax,WP1_uMsg ;move the message number to eax;==============================================================================; WM_CREATE (value=01h) message received ?;------------------------------------------------------------------------------WP1_uMsg_01h:cmp eax,1h ;check if WM_CREATE message recievedjne WP1_uMsg_02h ;if not goto LABEL;------------------------------------------------------------------------------; API "CreateWindowExA" creates a window with a predefined class name (STATIC).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush WP1_hWnd ;hWndParent, handle parent window 0=nopush 00000208h ;intnHeight, window height pixelpush 000000D7h ;intnWidth, window width pixelpush 0000001Ch ;inty, vertical position windowpush 00000004h ;intx, horizontal position windowpush 54000000h ;dwStyle, look WIN32.HLP + windows.incpush OFFSET W1_NameStatic ;lpWindowName, pointer to window namepush OFFSET ClassStatic ;lpClassName, pointer to class namepush 1h ;dwExStyle,look WIN32.HLP + windows.inccall CreateWindowExA ;- API Function -mov W1_handleStatic,eax ;hwnd,return value=handle of window;------------------------------------------------------------------------------; API "CreateWindowExA" creates a window with a predefined class name (BUTTON).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0100h ;hMenu, the child-window IDpush WP1_hWnd ;hWndParent, handle parent window 0=nopush 00000014h ;intnHeight, window height pixelpush 000000AFh ;intnWidth, window width pixelpush 00000004h ;inty, vertical position windowpush 00000018h ;intx, horizontal position windowpush 50000001h ;dwStyle, style ( BS_DEFPUSHBUTTON )

Page 10

td_win32asm_320.asmpush OFFSET NameButton ;lpWindowName, pointer to window namepush OFFSET ClassButton ;lpClassName, pointer to class namepush 0h ;dwExStyle,call CreateWindowExA ;- API Function -mov W1_handleButton,eax ;return value=handle of windowjmp WP1_return

;==============================================================================; WM_DESTROY (value=02h) message received ?;------------------------------------------------------------------------------WP1_uMsg_02h:cmp eax,2h ;check if value=2h (WM_DESTROY)jne WP1_uMsg_0500h ;if not 2h go to LABEL;------------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate;------------------------------------------------------------------------------push 0h ;nExitCode, exit code=wParamcall PostQuitMessage ;- API Function -popad ;pop all register back from stackxor eax,eax ;set eax to 0 to exit our programret ;return

;==============================================================================; WM_USER+X (value=0500h) message received;------------------------------------------------------------------------------WP1_uMsg_0500h:cmp eax,0500h ;check if WM_USER+X message recievedjne WP1_uMsg_111h ;if not goto label;------------------------------------------------------------------------------; Convert the "while" parameter to an ASCII string;------------------------------------------------------------------------------mov esi,WP1_CallBack ;pointer to parametermov edi,OFFSET W1_while_CallBack;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_hWnd ;pointer to parametermov edi,OFFSET W1_while_hWnd ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_uMsg ;pointer to parametermov edi,OFFSET W1_while_uMsg ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_wParam ;pointer to parametermov edi,OFFSET W1_while_wParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_lParam ;pointer to parametermov edi,OFFSET W1_while_lParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -jmp WP1_return

;==============================================================================; WM_COMMAND (value=111h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_111h:cmp eax,111h ;check if WM_COMMAND message recieved

Page 11

td_win32asm_320.asmjne WP1_return ;if not goto label;------------------------------------------------------------------------------; Check extra message, button (SendMessage, ID=0100h) clicked ?;------------------------------------------------------------------------------mov eax,WP1_wParam ;extra info about the message in axcmp ax,0100h ;ID of button, child windowjne WP1_return ;;------------------------------------------------------------------------------; Convert the "before" parameter to an ASCII string;------------------------------------------------------------------------------mov esi,WP1_CallBack ;pointer to parametermov edi,OFFSET W1_before_CallBack;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_hWnd ;pointer to parametermov edi,OFFSET W1_before_hWnd ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_uMsg ;pointer to parametermov edi,OFFSET W1_before_uMsg ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_wParam ;pointer to parametermov edi,OFFSET W1_before_wParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_lParam ;pointer to parametermov edi,OFFSET W1_before_lParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -;------------------------------------------------------------------------------; API "SendMessageA" sends a message to the Window Procedure;------------------------------------------------------------------------------push 0h ;lParam,push 0h ;wParam,push 0500h ;uMsg, message to send ( WM_USER+X )push WP1_hWnd ;hWnd, handle of destination windowcall SendMessageA ;- API Function -;------------------------------------------------------------------------------; Convert the "after" parameter to an ASCII string;------------------------------------------------------------------------------mov esi,WP1_CallBack ;pointer to parametermov edi,OFFSET W1_after_CallBack;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_hWnd ;pointer to parametermov edi,OFFSET W1_after_hWnd ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_uMsg ;pointer to parametermov edi,OFFSET W1_after_uMsg ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_wParam ;pointer to parametermov edi,OFFSET W1_after_wParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP1_lParam ;pointer to parametermov edi,OFFSET W1_after_lParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -;==============================================================================; API "DefWindowProcA" calls the window procedure to provide default processing

Page 12

td_win32asm_320.asm; for any window messages that an application does not process.; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------popad ;pop all register from stackpush WP1_lParam ;extra info about the messagepush WP1_wParam ;extra info about the messagepush WP1_uMsg ;the message numberpush WP1_hWnd ;handle of window who receives messagecall DefWindowProcA ;- API Function -;------------------------------------------------------------------------------; Convert the "register" value to an ASCII string;------------------------------------------------------------------------------mov eax,ebp ;get EBPpushadmov esi,[eax] ;register to convertmov edi,OFFSET W1_register_EBP ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -popadmov eax,esp ;get ESPpushadmov esi,[eax] ;register to convertmov edi,OFFSET W1_register_ESP ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -popad;------------------------------------------------------------------------------; API "MessageBoxA" creates a message box to visualize all parameter blocks !;------------------------------------------------------------------------------push 0h ;uType, style, 0=MB_OK Buttonpush OFFSET W1_MB1_Title ;lpCaption,pointer to title textpush OFFSET W1_MB1_Text ;lpText,pointer to text message boxpush WP1_hWnd ;handle of owner window 0=no ownercall MessageBoxA ;- API Function -ret ;return

;==============================================================================; API "DefWindowProcA" calls the window procedure to provide default processing; for any window messages that an application does not process.; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------WP1_return:popad ;pop all register from stackpush WP1_lParam ;extra info about the messagepush WP1_wParam ;extra info about the messagepush WP1_uMsg ;the message numberpush WP1_hWnd ;handle of window who receives messagecall DefWindowProcA ;- API Function -ret ;return;##############################################################################

;##############################################################################; The Window Procedure (API=RegisterClassExA) for this registered window (WP2).

Page 13

td_win32asm_320.asm;------------------------------------------------------------------------------WP2:push ebp ;create stack framemov ebp,esp ;pushad ;push all register to the stack

mov eax,WP2_uMsg ;move the message number to eax;==============================================================================; WM_CREATE (value=01h) message received ?;------------------------------------------------------------------------------WP2_uMsg_01h:cmp eax,1h ;check if WM_CREATE message recievedjne WP2_uMsg_02h ;if not goto LABEL;------------------------------------------------------------------------------; API "CreateWindowExA" creates a window with a predefined class name (STATIC).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush WP2_hWnd ;hWndParent, handle parent window 0=nopush 00000208h ;intnHeight, window height pixelpush 000000D7h ;intnWidth, window width pixelpush 0000001Ch ;inty, vertical position windowpush 00000004h ;intx, horizontal position windowpush 54000000h ;dwStyle, look WIN32.HLP + windows.incpush OFFSET W2_NameStatic ;lpWindowName, pointer to window namepush OFFSET ClassStatic ;lpClassName, pointer to class namepush 1h ;dwExStyle,look WIN32.HLP + windows.inccall CreateWindowExA ;- API Function -mov W2_handleStatic,eax ;hwnd,return value=handle of window;------------------------------------------------------------------------------; API "CreateWindowExA" creates a window with a predefined class name (BUTTON).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0100h ;hMenu, the child-window IDpush WP2_hWnd ;hWndParent, handle parent window 0=nopush 00000014h ;intnHeight, window height pixelpush 000000AFh ;intnWidth, window width pixelpush 00000004h ;inty, vertical position windowpush 00000018h ;intx, horizontal position windowpush 50000001h ;dwStyle, style ( BS_DEFPUSHBUTTON )push OFFSET NameButton ;lpWindowName, pointer to window namepush OFFSET ClassButton ;lpClassName, pointer to class namepush 0h ;dwExStyle,call CreateWindowExA ;- API Function -mov W2_handleButton,eax ;return value=handle of windowjmp WP2_return

;==============================================================================; WM_DESTROY (value=02h) message received ?;------------------------------------------------------------------------------WP2_uMsg_02h:

Page 14

td_win32asm_320.asmcmp eax,2h ;check if value=2h (WM_DESTROY)jne WP2_uMsg_0500h ;if not 2h go to LABEL;------------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate;------------------------------------------------------------------------------push 0h ;nExitCode, exit code=wParamcall PostQuitMessage ;- API Function -popad ;pop all register back from stackxor eax,eax ;set eax to 0 to exit our programmov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack

;==============================================================================; WM_USER+X (value=0500h) message received;------------------------------------------------------------------------------WP2_uMsg_0500h:cmp eax,0500h ;check if WM_USER+X message recievedjne WP2_uMsg_111h ;if not goto label;------------------------------------------------------------------------------; Convert the "while" parameter to an ASCII string;------------------------------------------------------------------------------mov esi,WP2_CallBack ;pointer to parametermov edi,OFFSET W2_while_CallBack;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_hWnd ;pointer to parametermov edi,OFFSET W2_while_hWnd ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_uMsg ;pointer to parametermov edi,OFFSET W2_while_uMsg ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_wParam ;pointer to parametermov edi,OFFSET W2_while_wParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_lParam ;pointer to parametermov edi,OFFSET W2_while_lParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -jmp WP2_return

;==============================================================================; WM_COMMAND (value=111h) message recieved ?;------------------------------------------------------------------------------WP2_uMsg_111h:cmp eax,111h ;check if WM_COMMAND message recievedjne WP2_return ;if not goto label;------------------------------------------------------------------------------; Check extra message, button (SendMessage, ID=0100h) clicked ?;------------------------------------------------------------------------------mov eax,WP2_wParam ;extra info about the message in axcmp ax,0100h ;ID of button, child windowjne WP2_return ;;------------------------------------------------------------------------------; Convert the "before" parameter to an ASCII string

Page 15

td_win32asm_320.asm;------------------------------------------------------------------------------mov esi,WP2_CallBack ;pointer to parametermov edi,OFFSET W2_before_CallBack;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_hWnd ;pointer to parametermov edi,OFFSET W2_before_hWnd ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_uMsg ;pointer to parametermov edi,OFFSET W2_before_uMsg ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_wParam ;pointer to parametermov edi,OFFSET W2_before_wParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_lParam ;pointer to parametermov edi,OFFSET W2_before_lParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -;------------------------------------------------------------------------------; API "SendMessageA" sends a message to the Window Procedure;------------------------------------------------------------------------------push 0h ;lParam,push 0h ;wParam,push 0500h ;uMsg, message to send ( WM_USER+X )push WP2_hWnd ;hWnd, handle of destination windowcall SendMessageA ;- API Function -;------------------------------------------------------------------------------; Convert the "after" parameter to an ASCII string;------------------------------------------------------------------------------mov esi,WP2_CallBack ;pointer to parametermov edi,OFFSET W2_after_CallBack;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_hWnd ;pointer to parametermov edi,OFFSET W2_after_hWnd ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_uMsg ;pointer to parametermov edi,OFFSET W2_after_uMsg ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_wParam ;pointer to parametermov edi,OFFSET W2_after_wParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -mov esi,WP2_lParam ;pointer to parametermov edi,OFFSET W2_after_lParam ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -;------------------------------------------------------------------------------; API "DefWindowProcA" calls the window procedure to provide default processing; for any window messages that an application does not process.; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------popad ;pop all register from stackpush WP2_lParam ;extra info about the messagepush WP2_wParam ;extra info about the messagepush WP2_uMsg ;the message numberpush WP2_hWnd ;handle of window who receives message

Page 16

td_win32asm_320.asmcall DefWindowProcA ;- API Function -;------------------------------------------------------------------------------; Convert the "register" value to an ASCII string;------------------------------------------------------------------------------mov esp,ebp ;delete stack framepop ebpmov eax,ebp ;get EBPpush ebp ;create stack framemov ebp,esppushadmov esi,[eax] ;register to convertmov edi,OFFSET W2_register_EBP ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -popadmov esp,ebp ;delete stack framepop ebpmov eax,esp ;get ESPpush ebp ;create stack framemov ebp,esppushadmov esi,[eax] ;register to convertmov edi,OFFSET W2_register_ESP ;pointer to message box text areacall My_MBTextOut ;- SubRoutine -popad;------------------------------------------------------------------------------; API "MessageBoxA" creates a message box to visualize all parameter blocks !;------------------------------------------------------------------------------push 0h ;uType, style, 0=MB_OK Buttonpush OFFSET W2_MB1_Title ;lpCaption,pointer to title textpush OFFSET W2_MB1_Text ;lpText,pointer to text message boxpush WP2_hWnd ;handle of owner window 0=no ownercall MessageBoxA ;- API Function -mov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack

;==============================================================================; API "DefWindowProcA" calls the window procedure to provide default processing; for any window messages that an application does not process.; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------WP2_return:popad ;pop all register from stackpush WP2_lParam ;extra info about the messagepush WP2_wParam ;extra info about the messagepush WP2_uMsg ;the message numberpush WP2_hWnd ;handle of window who receives messagecall DefWindowProcA ;- API Function -mov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack;##############################################################################

Page 17

td_win32asm_320.asm

;******************************************************************************; My own subroutine(s) for a compacter code resist here ...;------------------------------------------------------------------------------My_MBTextOut:;------------------------------------------------------------------------------; Converts a 32 bit value in ESI into an ascii string to OFFSET EDI !;------------------------------------------------------------------------------mov ecx,0hloop_1:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,28and eax,15cmp al,[edx]jne loop_1mov eax,ediadd eax,08mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_2:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,24and eax,15cmp al,[edx]jne loop_2mov eax,ediadd eax,9mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_3:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecx

Page 18

td_win32asm_320.asmcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,20and eax,15cmp al,[edx]jne loop_3mov eax,ediadd eax,10mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_4:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,16and eax,15cmp al,[edx]jne loop_4mov eax,ediadd eax,11mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_5:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,12and eax,15cmp al,[edx]jne loop_5mov eax,ediadd eax,12mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_6:mov edx,OFFSET table_HEX

Page 19

td_win32asm_320.asmadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,8and eax,15cmp al,[edx]jne loop_6mov eax,ediadd eax,13mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_7:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,4and eax,15cmp al,[edx]jne loop_7mov eax,ediadd eax,14mov dl,[ebx]mov [eax],dl

mov ecx,0hloop_8:mov edx,OFFSET table_HEXadd edx,ecxmov ebx,OFFSET table_ASCIIadd ebx,ecxinc ecxcmp ecx,11hjae My_MBTextOut_returnmov eax,esishr eax,0and eax,15cmp al,[edx]jne loop_8mov eax,ediadd eax,15mov dl,[ebx]mov [eax],dl

Page 20

td_win32asm_320.asmMy_MBTextOut_return:ret;******************************************************************************

;==============================================================================; end Main = end of our program code;------------------------------------------------------------------------------end Main ;end of our program code, entry point

;==============================================================================; To create the exe file use this commands with your Microsoft Assembler/Linker;------------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_320.asm ;asm command; rc.exe /v rsrc.rc ;rc command; cvtres.exe /machine:ix86 rsrc.res; link.exe /subsystem:windows td_win32asm_320.obj rsrc.obj ;link command;==============================================================================

Page 21


Recommended