Last active
May 16, 2022 16:35
-
-
Save littlefuntik/f9da1ab81c62fd7f6412a5455d372b70 to your computer and use it in GitHub Desktop.
FASM - create window using win32 library. Work fine!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format PE GUI | |
entry start | |
include 'win32a.inc' | |
_style equ WS_VISIBLE+WS_OVERLAPPEDWINDOW | |
section '.data' data readable writeable | |
_class TCHAR 'FASMW32',0 | |
_title TCHAR 'Hello from FASM!',0 | |
_err_reg TCHAR 'Call to RegisterClassEx failed!',0 | |
_err_create TCHAR 'Call to CreateWindowEx failed!',0 | |
wc WNDCLASS | |
msg MSG | |
hwnd dd ? | |
section '.text' code readable executable | |
start: | |
xor ebx,ebx | |
invoke GetModuleHandle,ebx | |
mov [wc.hInstance],eax | |
invoke LoadCursor,NULL,IDC_ARROW | |
mov [wc.hCursor],eax | |
invoke LoadIcon,NULL,IDI_ASTERISK | |
mov [wc.hIcon],eax | |
mov [wc.lpfnWndProc],WindowProc | |
mov [wc.lpszClassName],_class | |
mov [wc.hbrBackground],COLOR_WINDOW+1 | |
invoke RegisterClass,wc | |
test eax,eax | |
jz err_reg_class | |
invoke CreateWindowEx,ebx,_class,_title,_style,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,[wc.hInstance],ebx | |
test eax,eax | |
jz err_win_create | |
mov [hwnd],eax | |
msg_loop: | |
invoke GetMessage,msg,NULL,0,0 | |
or eax,eax | |
jz end_loop | |
invoke TranslateMessage,msg | |
invoke DispatchMessage,msg | |
jmp msg_loop | |
jmp end_loop | |
end_loop: | |
invoke ExitProcess,[msg.wParam] | |
err_reg_class: | |
invoke MessageBox,NULL,_err_reg,_title,MB_ICONERROR+MB_OK | |
jmp end_loop | |
err_win_create: | |
invoke MessageBox,NULL,_err_create,_title,MB_ICONERROR+MB_OK | |
jmp end_loop | |
proc WindowProc uses ebx esi edi,hwnd,wmsg,wparam,lparam | |
cmp [wmsg],WM_DESTROY | |
je .wmdestroy | |
cmp [wmsg],WM_CREATE | |
je .wmcreate | |
.defwndproc: | |
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] | |
jmp .finish | |
.wmcreate: | |
xor eax,eax | |
jmp .finish | |
.wmdestroy: | |
invoke PostQuitMessage,0 | |
xor eax,eax | |
.finish: | |
ret | |
endp | |
section '.idata' import data readable writeable | |
library\ | |
kernel32,'kernel32.dll',\ | |
user32,'user32.dll' | |
include 'api\kernel32.inc' | |
include 'api\user32.inc' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment