Author Topic: Examples for Win64 Iczelion tutorial  (Read 104341 times)

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #60 on: June 03, 2015, 07:59:41 PM »
Well, Siekmanski, I hope... (Nou, ik hoop)

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #61 on: June 05, 2015, 05:38:13 PM »
Win64 Tutorial #32: Multiple Document Interface (MDI)

asm-file
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include shell32.inc
includelib shell32.lib

OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
IDM_MENU equ 1000
IDM_FILE_EXIT equ 0
IDM_FILE_NEW equ 1
IDM_WINDOW_NEXT equ 2
IDM_WINDOW_PREVIOUS equ 3
MI_CLOSE equ 4
MI_TILEHOR equ 5
MI_TILEVER equ 6
MI_CASCADE equ 7
IDM_HELP_ABOUT equ 8
MI_CLOSE_ALL equ 9
.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov edi,offset ClassName
mov eax,10029h
mov esi,IMAGE_BASE
push rax ;hIconSm
push rdi ;lpszClassName
push IDM_MENU ;lpszMenuName
push COLOR_APPWORKSPACE;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
push rsi ;hInstance
push DLGWINDOWEXTRA;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov ecx,esp ;addr WNDCLASSEX
mov edi,ecx
sub esp,20h
    call RegisterClassEx

mov eax,offset MdiChildProc
        mov [rdi+WNDCLASSEX.lpfnWndProc],rax
mov [rdi+WNDCLASSEX.cbWndExtra],ebx
mov [rdi+WNDCLASSEX.lpszMenuName],rbx
mov eax,offset MdiChildClassName
mov [rdi+WNDCLASSEX.lpszClassName],rax
mov ecx,edi
call RegisterClassEx

push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 600
push 800
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE or WS_CLIPCHILDREN
mov edx,offset ClassName
mov r8,rdx ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
    call CreateWindowEx
        mov hWnd,rax
        mov ecx,eax
        call GetMenu
        mov hMenu,rax
        mov edx,1
        mov ecx,eax
        call GetSubMenu

        mov cc.hWindowMenu,rax
        mov edi,offset rect
        mov edx,edi
        mov rcx,hWnd
        call GetClientRect
        mov eax,offset cc
        push rax
        push rsi
        push rbx
        push hWnd
        mov eax,[rdi+RECT.bottom]
        push rax
        mov eax,[rdi+RECT.right]
        push rax
        push rbx
        push rbx
        mov r9d,WS_CHILD + WS_VISIBLE + WS_VSCROLL + WS_HSCROLL + WS_CLIPCHILDREN
        mov r8,rbx
        mov edx,offset MdiClientClassName
        mov ecx,WS_EX_CLIENTEDGE
        sub esp,20h
        call CreateWindowEx
        mov hClient,rax
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
        mov edx,edi
        mov rcx,hClient
        call TranslateMDISysAccel
        test eax,eax
        jnz @b
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
        push rbp
mov ebp,esp
sub esp,20h

mov hWin,rcx
mov wParam,r8
mov lParam,r9
xor ebx,ebx

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_SIZE
        je wmSIZE
        leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmCOMMAND:mov rax,r8;[wParam]
        cmp eax,MI_CLOSE_ALL;5
        ja wmBYE
        jmp [menu_handlers+rax*8]
New:    mov esi,IMAGE_BASE
        push rbx;NULL
        push rsi;hInstance
        shl esi,9
        push rbx
        push hClient
        push rsi
        push rsi
        push rsi
        push rsi
        mov r9d,MDIS_ALLCHILDSTYLES
        mov edx,offset MdiChildClassName
        mov r8,rdx
        mov ecx,WS_EX_MDICHILD + WS_EX_CLIENTEDGE
        sub esp,20h
        call CreateWindowEx
        jmp wmBYE
Exit:   mov rax,hWin
        jmp a1
Next:   mov r9d,TRUE
        jmp a3
Prev:   mov r9,rbx
a3:     mov r8,rbx
        mov edx,WM_MDINEXT
a4:     mov rcx,hClient
        jmp a2
Horiz:  mov r9,rbx
        mov r8d,MDITILE_HORIZONTAL
a5:     mov edx,WM_MDITILE
        jmp a4
Vert:   mov r9,rbx
        mov r8,rbx
        jmp a5
Cascade:mov r9,rbx
        mov r8d,MDITILE_SKIPDISABLED
        mov edx,WM_MDICASCADE
        jmp a4
Close:  mov r9,rbx
        mov r8,rbx
        mov edx,WM_MDIGETACTIVE
        mov rcx,hClient
        call SendMessage
a1:     mov r9,rbx
        mov r8,rbx
        mov edx,WM_CLOSE
        mov rcx,rax
a2:     call SendMessage
        jmp wmBYE
About:  mov r9,rbx
        mov r8d,offset AboutMsg
        mov edx,offset ClassName
        mov rcx,hWin
        call ShellAbout
        jmp wmBYE
CloseAll:mov r9,rbx
        mov r8,rbx
        mov edx,WM_MDIGETACTIVE
        mov rcx,hClient
        call SendMessage
        test eax,eax
        je wmBYE
        mov r9,rbx
        mov r8,rbx
        mov edx,WM_CLOSE
        mov ecx,eax
        call SendMessage
        jmp CloseAll
wmSIZE: mov edi,offset rect
        mov edx,edi
        mov rcx,hWin
        call GetClientRect
        push TRUE
        mov eax,[rdi+RECT.bottom]
        push rax
        mov r9d,[rdi+RECT.right]
        mov r8,rbx
        xor edx,edx
        mov rcx,hClient
        sub esp,20h
        call MoveWindow
wmBYE: leave
retn
menu_handlers dq Exit,New,Next,Prev,Close,Horiz,Vert,Cascade,About,CloseAll
WndProc endp
MdiChildProc proc

        push rbp
        mov ebp,esp
        sub esp,20h

        cmp edx,WM_MDIACTIVATE
        jz wmMDIACTIVATE
        leave
        jmp DefMDIChildProc
wmMDIACTIVATE: mov rax,r9;[lParam2]
        cmp rax,rcx;[hChild]
        setne bl;MF_ENABLED=0 MF_GRAYED=1
        mov r8,rbx
        mov edx,MI_CLOSE
        mov rcx,hMenu
        call EnableMenuItem
        mov r8,rbx
        mov edx,MI_TILEHOR
        mov rcx,hMenu
        call EnableMenuItem
        mov r8,rbx
        mov edx,MI_TILEVER
        mov rcx,hMenu
        call EnableMenuItem
        mov r8,rbx
        mov edx,MI_CASCADE
        mov rcx,hMenu
        call EnableMenuItem
        mov r8,rbx
        mov edx,IDM_WINDOW_NEXT
        mov rcx,hMenu
        call EnableMenuItem
        mov r8,rbx
        mov edx,IDM_WINDOW_PREVIOUS
        mov rcx,hMenu
        call EnableMenuItem
        mov r8,rbx
        mov edx,MI_CLOSE_ALL
        mov rcx,hMenu
        call EnableMenuItem
        xor ebx,ebx
        leave
retn

MdiChildProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #32: Multiple Document Interface (MDI)',0
MdiChildClassName db 'MDICHILD',0
MdiClientClassName db 'MDICLIENT',0
cc      CLIENTCREATESTRUCT <0,2000>
hWnd      dq ?
hClient  dq ?
hMenu    dq ?
rect      RECT <>
AboutMsg    db 'Mikl__ 2015',0
end
rc-file
Code: [Select]
#define IDM_MENU 1000
#define IDM_FILE_EXIT           0
#define IDM_FILE_NEW 1
#define IDM_WINDOW_NEXT         2
#define IDM_WINDOW_PREVIOUS 3
#define MI_CLOSE 4
#define MI_TILEHOR              5
#define MI_TILEVER              6
#define MI_CASCADE              7
#define IDM_HELP_ABOUT          8
#define MI_CLOSE_ALL            9

IDM_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
        MENUITEM "&New", IDM_FILE_NEW
                MENUITEM "&Close\tCtrl+F4",MI_CLOSE,GRAYED
                MENUITEM SEPARATOR
MENUITEM "&Exit",IDM_FILE_EXIT
END
        POPUP "&Window"   
    BEGIN
    MENUITEM "Tile Horizontal",MI_TILEHOR,GRAYED
    MENUITEM "Tile Vertical",MI_TILEVER,GRAYED
    MENUITEM "Cascade",MI_CASCADE,GRAYED
        MENUITEM "&Next\tCtrl+F6",IDM_WINDOW_NEXT,GRAYED
MENUITEM "&Previous\tShift+Ctrl+F6",IDM_WINDOW_PREVIOUS,GRAYED
MENUITEM "&Close All",MI_CLOSE_ALL,GRAYED
    END
    POPUP "&Help"   
    BEGIN
    MENUITEM "&About",IDM_HELP_ABOUT
    END
END
« Last Edit: August 24, 2015, 04:56:07 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #62 on: June 11, 2015, 11:22:39 AM »
Win64 Tutorial #14: Dynamic Link Libraries
makeDLL64.bat
Code: [Select]
cls
set masm64_path=\masm64\
set filename=tut_17a
if exist %filename%.dll del %filename%.dll
%masm64_path%bin\ml64.exe /c /Cp /I %masm64_path%include %filename%.asm || exit
%masm64_path%bin\Link.exe %filename%.obj /LIBPATH:%masm64_path%lib ^
/SUBSYSTEM:WINDOWS /ENTRY:DllMain /DLL /ALIGN:16 ^
/stub:%masm64_path%bin\stubby.exe /SECTION:.text,W /DEF:%filename%.def || exit
del %filename%.obj
del %filename%.exp
tut_17a.def
Code: [Select]
LIBRARY tut_17a
EXPORTS DllMain
EXPORTS TestHello
tut_17a.asm
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include user32.inc
includelib user32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

.code
DllMain proc hInstDLL:QWORD, reason:QWORD, unused:QWORD
sub esp,28h
.if edx==DLL_PROCESS_ATTACH
lea rdx,LoadMsg
.elseif edx==DLL_PROCESS_DETACH
lea rdx,UnloadMsg
.endif
mov r9d,MB_OK
jmp exit
DllMain Endp
TestHello proc
sub esp,28h
lea rdx,HelloMsg
mov r9d,MB_OK + MB_ICONERROR
exit:: lea r8,AppName
xor ecx,ecx
call MessageBox
add esp,28h
mov eax,TRUE
ret
TestHello endp
AppName db "DLL Skeleton",0
HelloMsg db "Hello, you're calling a function in this DLL",0
LoadMsg db "The DLL is loaded",0
UnloadMsg db "The DLL is unloaded",0
end
operating system loads address of TestHello function from dll-file to import section
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
includelib tut_17a.lib
 
OPTION PROLOGUE:none
OPTION EPILOGUE:none
TestHello PROTO

.code
WinMain proc
sub esp,28h
        call [TestHello]
xor ecx,ecx
call ExitProcess
WinMain endp
end
use LoadLibrary to load a DLL
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

.code
WinMain proc
sub esp,28h
mov ecx,offset LibName
call LoadLibrary
        or eax,eax;.if eax==NULL  ;the dll not found
        jnz @f
xor ecx,ecx
mov r9,rcx;MB_OK=0
mov r8d,offset AppName
mov edx,offset DllNotFound
        call MessageBox
        jmp exit;.else
@@:     mov hLib,rax
mov edx,offset FunctionName
mov ecx,eax
        call GetProcAddress
        or eax,eax;.if eax==NULL ;requested function not found
jnz @f
xor ecx,ecx
mov r9,rcx;MB_OK = 0
mov r8d,offset AppName
mov edx,offset FunctionNotFound
        call MessageBox
        jmp @0
@@:     call rax
@0: mov rcx,hLib
        call FreeLibrary
exit:   xor ecx,ecx
call ExitProcess
WinMain endp
LibName db "tut_17a.dll",0
FunctionName db "TestHello",0
DllNotFound db "Cannot load library",0
AppName db "Load Library",0
FunctionNotFound db "TestHello function not found",0
hLib dq ?
end

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #63 on: June 11, 2015, 01:04:33 PM »
Win64 Tutorial #20: Window Subclassing
asm-file
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov eax,10029h
mov esi,IMAGE_BASE
push rax ;hIconSm
mov edi,offset ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax     ;hIcon
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
db 68h
dd WndProc;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
sub esp,20h
call RegisterClassEx
        push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 240
push 410
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
push rbx
push IMAGE_BASE
push rbx
push rax;hWnd
push 24
push 300
push 20
push 20
mov r9d,WS_CHILD + WS_VISIBLE + WS_BORDER
mov r8,rbx
mov edx,offset ctlClsNameEdit
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
mov  edit1H,rax
mov ecx,eax
call SetFocus
mov r8d,offset edit1_procedure
mov edx,GWL_WNDPROC
mov rcx,edit1H
call SetWindowLongPtr
mov wndProcAddr,rax
lea edi,msg
@@: mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
call GetMessage
mov ecx,edi
call TranslateMessage
mov ecx,edi
call DispatchMessage
jmp @b
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
cmp  edx,WM_DESTROY
je   wmDESTROY
wmDEFAULT:jmp DefWindowProc
wmDESTROY:xor ecx,ecx
call ExitProcess
WndProc endp
edit1_procedure proc hWnd:HWND, uMsg:QWORD, wParam:WPARAM, lParam:LPARAM
push rbp
mov ebp,esp
sub esp,30h

        mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
mov lParam,r9

        cmp edx,WM_KEYDOWN
je   edit1_wmKEYDOWN
cmp edx,WM_CHAR
jne  a1

edit1_wmCHAR: cmp r8b,VK_BACK ;compare with virtual key BACKSPACE
je a1
cmp r8b,30h ;compare with ascii 0
jb edit1_wmBYE
cmp r8b,39h ;compare with ascii 9
jbe a1
        and r8b,-33 ;so our DL become big letter
cmp r8b,41h ;compare with ascii A
jb edit1_wmBYE
cmp r8b,46h ;compare with ascii F
ja edit1_wmBYE     ;something else
       
a1: mov [esp+20h],r9;lParam
mov r9,r8;wParam
        mov r8,rdx;uMsg
        mov rdx,rcx;hWnd
mov rcx,wndProcAddr
        call CallWindowProc
jmp  edit1_wmBYE

edit1_wmKEYDOWN: cmp r8b,VK_RETURN ;compare with virtual key RETURN
jne  a1
mov r9,rbx;MB_OK
mov r8d,offset ClassName
mov edx,offset edit1Txt1
call MessageBox
mov rcx,hWnd
invoke SetFocus
edit1_wmBYE:
leave
ret
edit1_procedure endp
ClassName db 'Win64 Iczelion''s lesson #20: Window Subclassing',0
ctlClsNameEdit db 'EDIT',0
edit1Txt1 db 'A simple HEX edit control!',0
wndProcAddr dq ?
edit1H dq ?
end

mabdelouahab

  • Member
  • ***
  • Posts: 449
Re: Examples for Win64 Iczelion tutorial
« Reply #64 on: June 11, 2015, 05:16:08 PM »
Thank you Mikl__  :t
I think I will need these examples in the future

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #65 on: June 11, 2015, 05:26:25 PM »
mabdelouahab,
آمل أن تستخدموا هذه الأمثلة

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: Examples for Win64 Iczelion tutorial
« Reply #66 on: June 11, 2015, 05:35:26 PM »
Hi Mikl__,

do you plan a full set of Iczelion's tutorials for Windows 64-bit? That would be a lot of work. I've ordered web space today, so we could provide the entire material for download.

Gunther
Get your facts first, and then you can distort them.

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #67 on: June 11, 2015, 06:02:21 PM »
Hi, Gunther!
Yes, I do. I plan a full set of Iczelion's tutorials for Windows 64-bit. You may send materials to my e-mail. Part of tutorials x64 is ready. Some of the material will have to finalize with the joint efforts. Comments in asm-files need to be reviewed or possibly write new comments.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: Examples for Win64 Iczelion tutorial
« Reply #68 on: June 11, 2015, 07:44:55 PM »
Hi Mikl__,

Yes, I do. I plan a full set of Iczelion's tutorials for Windows 64-bit. You may send materials to my e-mail. Part of tutorials x64 is ready. Some of the material will have to finalize with the joint efforts. Comments in asm-files need to be reviewed or possibly write new comments.

that's fine. Let's send our contact data via PM, okay?

Gunther
Get your facts first, and then you can distort them.

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #69 on: June 13, 2015, 01:16:52 PM »
Part 1-st
Win64 Tutorial #21: Pipe
asm-file
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib

OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
MI_CSCRIPT equ 100
IDC_MENU    equ 30
.code
WinMain proc
local msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov eax,10027h
mov esi,IMAGE_BASE
mov edi,offset ClassName

push rax ;hIconSm
push rdi ;lpszClassName
push IDC_MENU ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax      ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
sub rsp,20h
    call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 350
push 600
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
sub rsp,20h
    call CreateWindowEx
        push rbx
push IMAGE_BASE
push rbx
push rax
push 280
push 575
push rbx
push rbx
mov r9d,WS_CHILD + WS_VISIBLE + WS_HSCROLL + WS_VSCROLL + ES_MULTILINE + ES_AUTOHSCROLL + ES_AUTOVSCROLL
mov r8,rbx
mov edx,offset ctlClsNameEdit
mov ecx,WS_EX_CLIENTEDGE
        sub rsp,20h
    call CreateWindowEx
mov edit1H,rax
lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
call TranslateMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
;----------------------------------------
WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local pipeReadH:QWORD
local pipeWriteH:QWORD
local pro1StartInfo:STARTUPINFO
local pro1Info:PROCESS_INFORMATION
local pipeRead:QWORD
local pipeBuffer[400h]:BYTE

push rbp
mov ebp,esp
sub esp,(48h+3*8+sizeof STARTUPINFO+sizeof PROCESS_INFORMATION+400h+15)and(-16)
mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_COMMAND
        je wmCOMMAND
        cmp edx,WM_SIZE
        je wmSIZE
        cmp edx,WM_CTLCOLOREDIT
        je wmCTLCOLOREDIT
        leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmSIZE: mov qword ptr [esp+28h],TRUE
mov rax,r9
movzx r9,ax
shr eax,16
mov [esp+20h],rax
mov r8,rbx
        xor edx,edx
        mov rcx,edit1H
call MoveWindow
jmp wmBYE
wmCTLCOLOREDIT:mov edx,0C9B5AFh
mov rcx,r8
call SetTextColor
xor edx,edx
mov rcx,wParam
call SetBkColor
mov ecx,BLACK_BRUSH
call GetStockObject
jmp wmBYE
wmCOMMAND:cmp r8,0FFFFh and MI_CSCRIPT
jne wmBYE
wmCOMMAND_MI_CSCRIPT:mov edi,offset pipeSecAttr
        mov  [rdi+SECURITY_ATTRIBUTES.nLength], sizeof SECURITY_ATTRIBUTES
mov  [edi+SECURITY_ATTRIBUTES.lpSecurityDescriptor],rbx
        mov  [edi+SECURITY_ATTRIBUTES.bInheritHandle],TRUE
mov r9,rbx
mov r8,rdi
lea edx,pipeWriteH
lea ecx,pipeReadH
call CreatePipe
or eax,eax;NULL
je   MI_CSCRIPT_error_pipe
lea edi,pro1StartInfo
mov  [edi+STARTUPINFO.cb],sizeof STARTUPINFO
mov ecx,edi
call GetStartupInfo
mov  rax,pipeWriteH
mov  [rdi+STARTUPINFO.hStdOutput],rax
mov  [rdi+STARTUPINFO.hStdError],rax
mov  [rdi+STARTUPINFO.dwFlags],STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES
mov  [rdi+STARTUPINFO.wShowWindow],SW_HIDE
;+----------------+
;| create process |
;+----------------+
lea eax,pro1Info
mov [rsp+48h],rax
mov [rsp+40h],rdi
mov [rsp+38h],rbx
        mov [rsp+30h],rbx
        mov [rsp+28h],rbx
mov qword ptr [rsp+20h],TRUE
mov r9,rbx
mov r8,rbx
mov edx,offset pro1CmdLine
xor ecx,ecx
call CreateProcess
or eax,eax;cmp  eax,NULL
je MI_CSCRIPT_error_process
@@:     mov rcx,pipeWriteH
call CloseHandle
cmp  eax,TRUE
jne  @b
mov edx,400h
lea ecx,pipeBuffer
call RtlZeroMemory
mov [rsp+20h],rbx
lea r9,pipeRead
mov r8d,1023
lea edx,pipeBuffer
mov rcx,pipeReadH
call ReadFile
or eax,eax;cmp  eax,NULL
je   @f
mov r8,rbx
mov r8,-1
mov edx,EM_SETSEL
mov rcx,edit1H
call SendMessage
lea r9,pipeBuffer
mov r8,rbx
mov edx,EM_REPLACESEL
mov rcx,edit1H
call SendMessage
jmp  @f
MI_CSCRIPT_error_pipe:mov r9,rbx;MB_OK
mov r8d,offset ClassName
mov edx,offset errStr1
mov rcx,hWnd
call MessageBox
jmp  wmBYE
MI_CSCRIPT_error_process:mov r9,rbx;MB_OK
mov r8d,offset ClassName
mov edx,offset errStr2
mov rcx,hWnd
call MessageBox
@@:     mov rcx,pipeReadH
call CloseHandle
mov rcx,pro1Info.hProcess
call CloseHandle
mov rcx,pro1Info.hThread
call CloseHandle
wmBYE:  leave
        retn
WndProc endp
;-----------------------------------------
ClassName db 'Win64 Iczelion''s lesson #21: Pipe',0
ctlClsNameEdit db 'EDIT',0
edit1H dq ?
pipeSecAttr  SECURITY_ATTRIBUTES <>
errStr1 db 'Error - Pipe Creation Failed!',0
errStr2 db 'Error - Process Creation Failed!',0
pro1CmdLine db 'ml64 /Cp  msgbox.asm /link /subsystem:windows /entry:WinMain',0
end
rc-file
Code: [Select]
#define MI_CSCRIPT 100
#define IDC_MENU   30

IDC_MENU  MENU
{
POPUP "&Action"
{       MENUITEM "&Assemble",MI_CSCRIPT
}
}

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #70 on: June 13, 2015, 01:19:27 PM »
Part 2-nd
the contents of two zip-files need to be unpacked in the same folder
(Restrictions of masm32.forum: 4 zip-files per post, maximum total size 512KB, maximum individual size 512KB)

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #71 on: June 16, 2015, 11:58:24 AM »
Win64 Tutorial #22:  Superclassing Demo
asm-file
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,(sizeof MSG+15)and(-16)

xor ebx,ebx
mov eax,10029h
mov esi,IMAGE_BASE
push rax ;hIconSm
mov edi,offset ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax     ;hIcon
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
db 68h
dd WndProc;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
sub esp,20h
call RegisterClassEx
        push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 240
push 410
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx

lea edi,msg
@@: mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
call GetMessage
mov ecx,edi
call TranslateMessage
mov ecx,edi
call DispatchMessage
jmp @b
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local editCls:WNDCLASSEX
push rbp
mov ebp,esp
sub esp,(20h+sizeof WNDCLASSEX+15)and(-16)

mov hWnd,rcx

cmp edx,WM_CREATE
je wmCREATE
cmp  edx,WM_DESTROY
je   wmDESTROY
wmDEFAULT:leave
jmp DefWindowProc
wmDESTROY:xor ecx,ecx
call ExitProcess

wmCREATE:lea edi,editCls
        mov dword ptr [edi+WNDCLASSEX.cbSize],sizeof WNDCLASSEX
        mov esi,offset ctlClsNameEdit+3;ClsName="EDIT"
        mov r8,rdi
        mov edx,esi
        xor ecx,ecx
        call GetClassInfoEx
        sub esi,3

        mov rax,[rdi+WNDCLASSEX.lpfnWndProc]
        mov wndProcAddr,rax

        mov dword ptr [rdi+WNDCLASSEX.lpfnWndProc],offset edit1_procedure
        mov dword ptr [rdi+WNDCLASSEX.hInstance],IMAGE_BASE
        mov [rdi+WNDCLASSEX.lpszClassName],rsi;OFFSET ctlClsNameEdit ClsName="HEXEDIT"
mov ecx,edi
call RegisterClassEx
mov ebx,5
mov edi,20
@@: push 0;rbx
push IMAGE_BASE
push rbx
push hWnd
push 24
push 300
push rdi
push 20
mov r9d,WS_CHILD + WS_VISIBLE + WS_BORDER
mov r8,0;rbx
mov edx,esi ;offset ctlClsNameEdit
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
mov [edit1H+8*rbx],rax

        mov r9d,0 ;limit to 15 chars
mov r8d,15
mov edx,EM_LIMITTEXT
mov ecx,eax
call SendMessage

add edi,30
dec ebx
jns @b
inc ebx
mov rcx,[edit1H+8*5]
call SetFocus
wmBYE: leave
retn
WndProc endp
edit1_procedure proc hWnd:HWND, uMsg:QWORD, wParam:WPARAM, lParam:LPARAM
push rbp
mov ebp,esp
sub esp,30h

        mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
mov lParam,r9

        cmp edx,WM_KEYDOWN
je   edit1_wmKEYDOWN
cmp edx,WM_CHAR
jne  @f

edit1_wmCHAR: cmp r8b,VK_BACK ;compare with virtual key BACKSPACE
je @f
cmp r8b,30h ;compare with ascii 0
jb edit1_wmBYE
cmp r8b,39h ;compare with ascii 9
jbe @f
        and r8b,-33 ;so our DL become big letter
cmp r8b,41h ;compare with ascii A
jb edit1_wmBYE
cmp r8b,46h ;compare with ascii F
ja edit1_wmBYE     ;something else
       
@@: mov [esp+20h],r9;lParam
mov r9,r8;wParam
        mov r8,rdx;uMsg
        mov rdx,rcx;hWnd
mov rcx,wndProcAddr
        call CallWindowProc
jmp  edit1_wmBYE

edit1_wmKEYDOWN: cmp r8b,VK_RETURN ;compare with virtual key RETURN
        je wmKEYDOWN_VK_RETURN
        cmp r8b,VK_TAB
jne @b
;-----------------------------------------------------
wmKEYDOWN_VK_TAB:mov ecx,VK_SHIFT
  call GetKeyState
or eax,eax;test eax,0x80000000
js VK_TAB_PREV;jne   VK_TAB_PREV
VK_TAB_NEXT:mov edx,GW_HWNDNEXT;=2
mov rcx,hWnd
call GetWindow
or eax,eax
jne VK_TAB_BYE
xor edx,edx;GW_HWNDFIRST=0
jmp @f
VK_TAB_PREV:mov edx,GW_HWNDPREV;=3
mov rcx,hWnd
call GetWindow
test eax,eax
jne VK_TAB_BYE
mov edx,GW_HWNDLAST;=1
@@: mov rcx,hWnd
call GetWindow
VK_TAB_BYE:mov ecx,eax
jmp @f
wmKEYDOWN_VK_RETURN:
mov r9,rbx;MB_OK
mov r8d,offset ClassName
mov edx,offset edit1Txt1
call MessageBox
mov rcx,hWnd
@@: invoke SetFocus
edit1_wmBYE:
leave
ret
edit1_procedure endp
ClassName db 'Win64 Iczelion''s lesson #22: Superclassing Demo',0
ctlClsNameEdit db 'HEXEDIT',0
edit1Txt1 db 'A simple HEX edit control!',0
wndProcAddr dq ?
edit1H dq 6 dup(?)
end

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #72 on: June 18, 2015, 05:52:14 PM »
Win64 Tutorial #26: Splash Screen
makedll64.bat
Code: [Select]
cls
set masm64_path=\masm64\
set filename=tut_26a
if exist %filename%.dll del %filename%.dll
%masm64_path%bin\RC /r  %filename%.rc || exit
%masm64_path%bin\ml64.exe /c /Cp /I %masm64_path%include %filename%.asm || exit
%masm64_path%bin\Link.exe %filename%.obj %filename%.res /LIBPATH:%masm64_path%lib ^
/SUBSYSTEM:WINDOWS /ENTRY:DllEntry /DLL /ALIGN:16 /section:.bss,S ^
/stub:%masm64_path%bin\stubby.exe /DEF:%filename%.def || exit
del %filename%.obj
del %filename%.exp
del %filename%.res
tut_26a.asm
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
.data
BitmapName db "MySplashBMP",0
ClassName db "SplashWndClass",0
hBitMap dq ?
TimerID dq ?
hInstance dq ?

.code

DllEntry proc hInst:QWORD, reason:QWORD, reserved1:QWORD
sub esp,28h
    cmp edx,DLL_PROCESS_ATTACH  ; When the dll is loaded
jnz @f
      mov hInstance,rcx
      call ShowBitMap     
@@:    add esp,28h
    mov eax,TRUE
    retn
DllEntry Endp
ShowBitMap proc

LOCAL msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
        push rdi ;lpszClassName
push rbx ;lpszMenuName
        push COLOR_WINDOW+1;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
push hInstance
        push rbx        ;cbClsExtra & cbWndExtra
        lea rax,WndProc
push rax ;lpfnWndProc
        push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
sub esp,20h
        call RegisterClassEx
push rbx
push hInstance
push rbx
push rbx
push 250
push 250
push CW_USEDEFAULT
push CW_USEDEFAULT
mov r9d,WS_POPUP or WS_VISIBLE
mov r8,rbx
mov edx,edi
xor ecx,ecx
sub esp,20h
        call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
or eax,eax
jz @f
mov ecx,edi
        call DispatchMessage
        jmp @b
@@: leave
retn
ShowBitMap endp

WndProc proc hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD

LOCAL ps:PAINTSTRUCT
LOCAL hMemoryDC:HDC
LOCAL hOldBmp:QWORD
LOCAL bitmap:BITMAP
LOCAL DlgHeight:QWORD
LOCAL DlgWidth:QWORD
LOCAL DlgRect:RECT
LOCAL DesktopRect:RECT

push rbp
mov ebp,esp
sub esp,(20h+sizeof PAINTSTRUCT+sizeof BITMAP+2*(sizeof RECT)+4*32+15)and(-16)       

mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_CREATE
je wmCREATE
cmp edx,WM_TIMER
je wmTIMER
cmp edx,WM_PAINT
je wmPAINT
cmp edx,WM_LBUTTONDOWN
je wmLBUTTONDOWN
leave
jmp DefWindowProc

wmDESTROY:mov rcx,hBitMap
jrcxz @f;.if hBitMap!=0
        call DeleteObject
@@:     xor ecx,ecx
        call PostQuitMessage
        jmp wmBYE
wmCREATE:lea rdx,DlgRect
        call GetWindowRect
        call GetDesktopWindow
        mov ecx,eax
lea rdx,DesktopRect
        call GetWindowRect
        push rbx                   ;Part of the later call to MoveWindow (no repaint)
        mov eax,DlgRect.bottom              ;Get the bottom of our dialogs window
        sub eax,DlgRect.top                 ;subtract the y value at the top of our window
        mov DlgHeight,rax                   ;And store it as the dialog's height
        push rax                   ;Push it for the call to MoveWindow
        mov r9d,DlgRect.right               ;The X coordinate of the right side of our dialog
        sub r9d,DlgRect.left                ;minus that of the left side
        mov DlgWidth,r9                     ;gives us the width
        mov r8d,DesktopRect.bottom          ;Get the bottom of the desktop window
        sub r8,DlgHeight                   ;Subtract the height of our dialog
        shr r8,1                            ;and divide by 2...this gives the middle of the screen
        mov edx,DesktopRect.right           ;Get the right side of the desktop
        sub rdx,DlgWidth                    ;Minus the width of our dialog
        shr edx,1                           ;Divide by 2
        mov rcx,hWnd                        ;Push the window handle
sub esp,20h
        call MoveWindow                     ;Move the window               
lea edx,BitmapName
mov rcx,hInstance
        call LoadBitmap
        mov hBitMap,rax
mov r9,rbx
mov r8d,2000
mov edx,1
mov rcx,hWnd
        call SetTimer
        mov TimerID,rax
jmp wmBYE
wmTIMER:mov r9,rbx
        mov r8,rbx
mov edx,WM_LBUTTONDOWN
mov rcx,hWnd
        call SendMessage
mov rdx,TimerID
mov rcx,hWnd
        call KillTimer
jmp wmBYE
wmPAINT:lea edx,ps
        call BeginPaint
        mov ecx,eax
        call CreateCompatibleDC
        mov hMemoryDC,rax
mov rdx,hBitMap
mov ecx,eax
        call SelectObject
        mov hOldBmp,rax
lea r8,bitmap
mov edx,sizeof BITMAP
mov rcx,hBitMap
        call GetObject
        push SRCCOPY
mov eax,bitmap.bmHeight
        push rax
mov eax,bitmap.bmWidth
        push rax
        push rbx
        push rbx
push hMemoryDC
push 250
mov r9d,250
mov r8,rbx
xor edx,edx
mov rcx,ps.hdc
sub esp,20h
        call StretchBlt
        mov rdx,hOldBmp
mov rcx,hMemoryDC
        call SelectObject
mov rcx,hMemoryDC
        call DeleteDC
lea edx,ps
mov rcx,hWnd
        call EndPaint
jmp wmBYE
wmLBUTTONDOWN:call DestroyWindow
wmBYE:  leave
        retn
WndProc endp
end
tut_26a.def
Code: [Select]
LIBRARY tut_26a.dlltut_26a.rc
Code: [Select]
MySplashBMP  BITMAP "Images\\JourneyStart.bmp"tut_26b.asm
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
.code
WinMain proc
local msg:MSG

        push rbp

mov ecx,offset libName
call LoadLibrary
or eax,eax
je @f
mov ecx,eax
call FreeLibrary

@@:     mov ebp,esp
sub esp,sizeof MSG
xor ebx,ebx
mov eax,10029h
mov edi,offset ClassName
        mov esi,IMAGE_BASE

push rax ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon

push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
sub esp,20h
    call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 240
push 400
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
    call CreateWindowEx

    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

        cmp  edx,WM_DESTROY
        je   wmDESTROY       
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #26: Splash Screen',0
libName db 'tut_26A.dll',0
end
« Last Edit: June 19, 2015, 10:02:54 AM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #73 on: June 22, 2015, 11:51:14 AM »
Win64 Tutorial #24:  Mouse Hook Demo
makeDLL64.bat
Code: [Select]
cls
set masm64_path=\masm64\
set filename=tut_24a
if exist %filename%.dll del %filename%.dll
%masm64_path%bin\ml64.exe /c /Cp /I %masm64_path%include %filename%.asm || exit
%masm64_path%bin\Link.exe %filename%.obj /LIBPATH:%masm64_path%lib ^
/SUBSYSTEM:WINDOWS /ENTRY:DllEntry /DLL /section:.bss,S ^
/stub:%masm64_path%bin\stubby.exe /DEF:%filename%.def || exit
del %filename%.obj
del %filename%.exp
tut_24a.asm
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include user32.inc
includelib user32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
WM_MOUSEHOOK equ WM_USER+6
MOUSEHOOKSTRUCT STRUCT
  pt            POINT      <>
  hwnd          QWORD      ?
  wHitTestCode  QWORD      ?
  dwExtraInfo   QWORD      ?
MOUSEHOOKSTRUCT ENDS

.data?
hInstance dq ?
hHook dq ?
hWnd dq ?
.code
DllEntry proc hInstDLL:QWORD, reason:QWORD, unused:QWORD
mov hInstance,rcx
mov eax,TRUE
        ret
DllEntry Endp
MouseProc proc nCode:QWORD,wParam:QWORD,lParam:QWORD
push rbp
mov ebp,esp
sub rsp,20h
mov lParam,r8

        mov r9,r8;lParam
mov r8,rdx;wParam
mov edx,ecx;nCode
mov rcx,hHook
call CallNextHookEx
mov rax,lParam
        mov rcx,[rax]
call WindowFromPoint
mov rcx,hWnd
mov edx,WM_MOUSEHOOK
mov r8,rax
mov r9d,0
call PostMessage;,hWnd,WM_MOUSEHOOK,eax,0
xor eax,eax
leave
ret
MouseProc endp

InstallHook proc hwnd:QWORD
push rbp
mov ebp,esp
        sub esp,20h

mov hWnd,rcx
mov ecx,WH_MOUSE
mov rdx,offset MouseProc
mov r8,hInstance
mov r9d,0
call SetWindowsHookEx;,WH_MOUSE,addr MouseProc,hInstance,NULL
mov hHook,rax
leave
ret
InstallHook endp

UninstallHook proc
push rbp
mov ebp,esp
sub esp,20h
mov rcx,hHook
call UnhookWindowsHookEx
leave
ret
UninstallHook endp
end
tut_24a.def
Code: [Select]
LIBRARY tut_24a
EXPORTS
MouseProc
InstallHook
UninstallHook
asm2.bat
Code: [Select]
cls
set masm64_path=\masm64\
set filename=tut_24b
if exist %filename%.exe del %filename%.exe
%masm64_path%bin\RC /r  %filename%.rc || exit
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj %filename%.res /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%bin\stubby.exe || exit
del %filename%.res
del %filename%.obj
tut_24b.asm
Code: [Select]
OPTION DOTNAME
include temphls.inc
include win64.inc
include mymacros.asm
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
includelib tut_24a.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IDD_MAINDLG equ 101
IDC_CLASSNAME equ 1000
IDC_HANDLE equ 1001
IDC_WNDPROC equ 1002
IDC_HOOK equ 1004
IDC_EXIT equ 1005
WM_MOUSEHOOK equ WM_USER+6
IMAGE_BASE equ 400000h
InstallHook proto :QWORD
UninstallHook proto
MouseProc proto :QWORD,:QWORD,:QWORD
DlgFunc proto :QWORD,:QWORD,:QWORD,:QWORD


.data
HookFlag dq FALSE
HookText db "&Hook",0
UnhookText db "&Unhook",0
template db "%lx",0
hHook dq ?

.code
WinMain proc
sub esp,38h
xor ebx,ebx
mov [rsp+20h],rbx
mov r9d,offset DlgFunc
mov r8,rbx
mov edx,IDD_MAINDLG
mov ecx,IMAGE_BASE
        call DialogBoxParam;,hInstance,IDD_MAINDLG,NULL,addr DlgFunc,NULL
xor ecx,ecx
        call ExitProcess
WinMain endp

DlgFunc proc hDlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD

LOCAL hLib:QWORD
LOCAL buffer[128]:byte
LOCAL buffer1[128]:byte
LOCAL rect:RECT

push rbp
mov ebp,esp
sub esp,(38h+8+2*128+sizeof RECT+15)and(-16)
mov hDlg,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_INITDIALOG
je wmINITDIALOG
        cmp edx,WM_MOUSEHOOK
je wmMOUSEHOOK
        cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CLOSE
je wmCLOSE
        xor eax,eax;FALSE
leave
        retn
wmCLOSE:cmp HookFlag,TRUE
jnz @f
        call UninstallHook
@@: xor edx,edx
        mov rcx,hDlg
        call EndDialog
jmp wmBYE
wmINITDIALOG:lea edi,rect
mov edx,edi
mov rcx,hDlg
        call GetWindowRect
mov qword ptr [rsp+30h],SWP_SHOWWINDOW
mov eax,[rdi+RECT.bottom]
mov [rsp+28h],rax
mov eax,[rdi+RECT.right]
mov [rsp+20h],rax
        mov r9d,[rdi+RECT.top]
mov r8d,[rdi+RECT.left]
or edx,HWND_TOPMOST
mov rcx,hDlg
        call SetWindowPos
jmp wmBYE
wmMOUSEHOOK:mov r9d,128
lea r8,buffer1
mov edx,IDC_HANDLE
;mov rcx,hDlg
        call GetDlgItemText
        mov r8,wParam
mov edx,offset template
lea ecx,buffer
        call wsprintf
lea edx,buffer1
lea ecx,buffer
        call lstrcmpi
        or eax,eax;.if eax!=0
jz @f
lea r8,buffer
mov edx,IDC_HANDLE
mov rcx,hDlg
        call SetDlgItemText

@@:     mov r9d,128
lea r8,buffer1
mov edx,IDC_CLASSNAME
mov rcx,hDlg
        call GetDlgItemText
mov r8d,128
lea edx,buffer
mov rcx,wParam
call GetClassName
        lea edx,buffer1
lea ecx,buffer
        call lstrcmpi
or eax,eax;.if eax!=0
jz @f
lea r8,buffer
mov edx,IDC_CLASSNAME
mov rcx,hDlg
        call SetDlgItemText
@@:     mov r9d,128
lea r8,buffer1
mov edx,IDC_WNDPROC
mov rcx,hDlg
        call GetDlgItemText
mov edx,GCL_WNDPROC
mov rcx,wParam
        call GetClassLong
mov r8,rax
mov edx,offset template
lea ecx,buffer
        call wsprintf
lea edx,buffer1
lea ecx,buffer
        call lstrcmpi
        or eax,eax;.if eax!=0
jz wmBYE
lea r8,buffer
mov edx,IDC_WNDPROC
mov rcx,hDlg
        call SetDlgItemText
jmp wmBYE
wmCOMMAND:cmp r9,rbx;cmp lParam,rbx;.if lParam!=0
jz wmBYE           
        mov rax,r8;wParam
        mov edx,eax
        shr edx,16
        or edx,edx;.if dx==BN_CLICKED
        jnz wmBYE
and eax,0FFFFh
cmp eax,IDC_EXIT
jnz @f
        mov r9,rbx
        mov r8,rbx
mov edx,WM_CLOSE
mov rcx,hDlg
        call SendMessage
jmp wmBYE
@@:     cmp HookFlag,rbx;FALSE
        jnz @f
mov rcx,hDlg
        call InstallHook
        or eax,eax;     .if eax!=NULL
        jz wmBYE
        mov HookFlag,TRUE
mov r8d,offset UnhookText
mov edx,IDC_HOOK
mov rcx,hDlg
        call SetDlgItemText
        jmp wmBYE
@@:     call UninstallHook
        mov r8d,offset HookText
mov edx,IDC_HOOK
mov rcx,hDlg
        call SetDlgItemText
        mov HookFlag,rbx;FALSE
mov r8,rbx
mov edx,IDC_CLASSNAME
mov rcx,hDlg
        call SetDlgItemText
mov r8,rbx
mov edx,IDC_HANDLE
mov rcx,hDlg
        call SetDlgItemText
        mov r8,rbx
mov edx,IDC_WNDPROC
mov rcx,hDlg
        call SetDlgItemText
wmBYE: leave
       mov eax,TRUE
       retn
DlgFunc endp
end
tut_24b.rc
Code: [Select]
#define IDD_MAINDLG                     101
#define IDC_CLASSNAME                   1000
#define IDC_HANDLE                      1001
#define IDC_WNDPROC                     1002
#define IDC_HOOK                        1004
#define IDC_EXIT                        1005
#define IDC_STATIC                      -1
#define DS_MODALFRAME                   0x80
#define WS_POPUP                        0x80000000
#define WS_CAPTION                      0xC00000
#define WS_SYSMENU                      0x80000
#define ES_AUTOHSCROLL                  0x80
#define ES_READONLY                     0x800

IDD_MAINDLG DIALOG DISCARDABLE  0, 0, 229, 85
STYLE DS_MODALFRAME |  WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Iczelion Tutorial #24: Mouse Hook Demo"
FONT 8, "MS Sans Serif"
BEGIN
    GROUPBOX        "Window Information",IDC_STATIC,7,7,214,67
    LTEXT           "Class name:",IDC_STATIC,21,22,39,8
    EDITTEXT        IDC_CLASSNAME,69,20,139,12,ES_AUTOHSCROLL | ES_READONLY
    LTEXT           "Handle:",IDC_STATIC,33,37,26,8
    EDITTEXT        IDC_HANDLE,69,36,77,12,ES_AUTOHSCROLL | ES_READONLY
    LTEXT           "Window Proc:",IDC_STATIC,13,52,46,8
    EDITTEXT        IDC_WNDPROC,69,51,77,12,ES_AUTOHSCROLL | ES_READONLY
    DEFPUSHBUTTON   "&Hook",IDC_HOOK,159,35,50,14
    PUSHBUTTON      "E&xit",IDC_EXIT,159,50,50,14
END

Mikl__

  • Member
  • ****
  • Posts: 883
Re: Examples for Win64 Iczelion tutorial
« Reply #74 on: June 27, 2015, 02:11:53 PM »
Win64 Tutorial #31a:  ListView Control
asm-file
Code: [Select]
include win64a.inc

IMAGE_BASE equ 400000h
IDM_MAINMENU equ 10000
IDM_ICON equ LVS_ICON
IDM_SMALLICON equ LVS_SMALLICON
IDM_LIST equ LVS_LIST
IDM_REPORT equ LVS_REPORT

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
call InitCommonControls
        mov eax,10029h
mov esi,IMAGE_BASE
mov edi,offset ClassName
push rax ;hIconSm
push rdi ;lpszClassName
push IDM_MAINMENU;lpszMenuName
push COLOR_WINDOW+1;hbrBackground
push 10005h ;hCursor
push rax     ;hIcon
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
db 68h
dd WndProc;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
call RegisterClassEx

push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 400
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx

push rbx;<-- align 10h

push IMAGE_BASE
push rbx;NULL
push rax;hWnd
push 240
push 400
push rbx;0
push rbx;0
mov r9d,LVS_REPORT+WS_CHILD+WS_VISIBLE
mov r8,rbx;NULL
mov edx,offset ListViewClassName
xor ecx,ecx;NULL
sub esp,20h
call CreateWindowEx
mov hList,rax

call InsertColumn
        call lv_col_info_fill
lea edi,msg
@@: mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
call GetMessage
mov ecx,edi
call DispatchMessage
jmp @b
WinMain endp

InsertColumn proc

LOCAL lvc:LV_COLUMN

push rbp
mov ebp,esp
sub esp,(20h+sizeof LV_COLUMN+15)and(-16)

lea r9,lvc
mov [r9+LV_COLUMN.imask],LVCF_TEXT+LVCF_WIDTH
mov eax,offset Heading1
mov [r9+LV_COLUMN.pszText],rax
mov [r9+LV_COLUMN.lx],150
mov r8,rbx;0
mov edx,LVM_INSERTCOLUMN
mov rcx,hList
call SendMessage
lea r9,lvc
mov eax,offset Heading2
mov [r9+LV_COLUMN.pszText],rax
mov [r9+LV_COLUMN.lx],100
mov r8d,1
mov edx,LVM_INSERTCOLUMN
mov rcx,hList
call SendMessage
leave
retn
InsertColumn endp

lv_col_info_fill proc
LOCAL lvItem:LV_ITEM
local old_rdi:QWORD

push rbp
mov ebp,esp
sub esp,(28h+sizeof LV_ITEM+15)and(-16)

mov old_rdi,rdi
xor edi,edi
@@: mov  lvItem.imask,LVIF_TEXT + LVIF_PARAM
mov  rax,[handle+rdi*8]
mov  lvItem.pszText,rax
mov  lvItem.iSubItem,0
mov  lvItem.iItem,edi
mov  lvItem.lParam,edi
lea  r9,lvItem
mov r8d,0
mov edx,LVM_INSERTITEM
mov rcx,hList
call SendMessage
mov  lvItem.imask,LVIF_TEXT
inc  lvItem.iSubItem
mov  rax,[handle+rdi*8+8*5]
mov  lvItem.pszText,rax
lea  r9,lvItem
mov r8d,0
mov edx,LVM_SETITEM
mov rcx,hList
call SendMessage
inc  edi
cmp  edi,5
jb   @b
@0: mov rdi,old_rdi
leave
retn
lv_col_info_fill endp
;------------------------------------------------
lv_param_update proc
LOCAL lvi:LV_ITEM
local old_rdi:QWORD

push rbp
mov ebp,esp
sub esp,(28h+sizeof LV_ITEM+15)and(-16)
mov old_rdi,rdi
mov r9,rbx
mov r8,rbx
mov edx, LVM_GETITEMCOUNT
mov rcx,hList
call SendMessage
mov edi,eax
mov lvi.imask,LVIF_PARAM
mov lvi.iSubItem,0
mov lvi.iItem,0
@@: lea r9,lvi
mov eax,lvi.iItem
mov lvi.lParam,eax
mov r8,rbx;0
mov edx, LVM_SETITEM
mov rcx,hList
call SendMessage
inc lvi.iItem
dec edi
jnz @b;.endw
mov rdi,old_rdi
leave
retn
lv_param_update endp
;------------------------------------------------
lv_compare proc lParam1:QWORD,lParam2:QWORD,lParamSort:QWORD
local buf1[100h]:BYTE
local buf2[100h]:BYTE
local lvi0:LV_ITEM
local old_rdi:QWORD
local old_rsi:QWORD
push rbp
mov ebp,esp
sub esp,(30h+sizeof LV_ITEM+200h+15)and(-16)
mov lParam2,rdx
mov lParamSort,r8

mov  lvi0.imask,LVIF_TEXT
lea  eax,buf1
mov  lvi0.pszText,rax
mov  lvi0.cchTextMax,100h
test r8b,00000010b;[lParamSort],1;2
jnz compare_3
compare_1:mov old_rdi,rdi
mov old_rsi,rsi
mov lvi0.iSubItem,1
lea  r9,lvi0
mov r8,rcx;[lParam1]
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea  esi,buf1
call convert_strhval
mov  edi,eax
lea  r9,lvi0
mov r8,lParam2
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea esi,buf1
call convert_strhval
test lParamSort,1
jne @f
xchg edi,eax
@@: sub eax,edi
compare_1_exit: mov rdi,old_rdi
mov rsi,old_rsi
leave
retn
compare_3:mov lvi0.iSubItem,0
lea r9,lvi0
mov r8,rcx;[lParam1]
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea  ecx,buf2 ;destination
lea  edx,buf1 ;source
call lstrcpy
lea  r9,lvi0
mov r8,lParam2
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea  edx,buf2
lea  ecx,buf1
test lParamSort,1
jne  @f
xchg edx,ecx
@@: call lstrcmpi
leave
retn
lv_compare endp
;---------------------------------------
convert_strhval proc
push rbp
mov ebp,esp
sub esp,20h

mov ecx,esi
call lstrlen
mov ecx,eax
jrcxz b
xor eax,eax
cdq
@@: imul edx,10
lodsb
lea edx,[rdx+rax-'0']
loop @b
mov  eax,edx
b: leave
ret
convert_strhval endp
;----------------------------------------
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
push rbp
mov ebp,esp
sub esp,30h

mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_NOTIFY
je wmNOTIFY
cmp edx,WM_SIZE
je wmSIZE
cmp edx,WM_DESTROY
je wmDESTROY
wmDEFAULT:leave
jmp DefWindowProc
wmDESTROY:xor ecx,ecx
call ExitProcess


wmNOTIFY:mov  rdi,r9;[lParam]
mov  rax,[rdi + NMHDR.hwndFrom]
cmp  rax,hList
jne  wmDEFAULT
cmp  [rdi + NMHDR._code],LVN_COLUMNCLICK
jne wmDEFAULT
wmNOTIFY_LVN_COLUMNCLICK:
cmp  [rdi + NM_LISTVIEW.iSubItem+4],1
jne   COLUMNCLICK_FILE
COLUMNCLICK_SIZE:xor lvSortSize,1
mov r8d,lvSortSize
jmp  @f
COLUMNCLICK_FILE:xor lvSortFile,1
mov r8d,lvSortFile
@@: mov r9d,lv_compare
mov edx,LVM_SORTITEMS
mov rcx,hList
call SendMessage
call lv_param_update
jmp wmBYE
wmSIZE: mov eax,r9d;lParam
and r9,0FFFFh
        shr  eax,16
mov qword ptr [rsp+28h],TRUE
mov [rsp+20h],rax
xor edx,edx
mov r8,rdx
mov rcx,hList
call MoveWindow
wmBYE: leave
ret
WndProc endp
;-------------------------------------------------------------
ClassName db 'Win64 Iczelion''s lesson #31a: ListView Control',0
ListViewClassName db 'SysListView32',0
Heading1 db 'Filename',0
Heading2 db 'Size',0
hList dq ?
hMenu dq ?
lvSortSize dd 0
lvSortFile dd 2
lvI1a db 'Durian',0
lvI1b db '34',0
lvI2a db 'Banana',0
lvI2b db '54',0
lvI3a db 'Watermelon',0
lvI3b db '44',0
lvI4a db 'Apple',0
lvI4b db '55',0
lvI5a db 'Papaya',0
lvI5b db '1',0
handle dq lvI1a,lvI2a,lvI3a,lvI4a,lvI5a,lvI1b,lvI2b,lvI3b,lvI4b,lvI5b
end
rc-file
Code: [Select]
#include "resource.h"
#define IDM_MAINMENU 10000
#define IDM_ICON LVS_ICON
#define IDM_SMALLICON LVS_SMALLICON
#define IDM_LIST LVS_LIST
#define IDM_REPORT LVS_REPORT

IDM_MAINMENU MENU
{
 POPUP "&View"
        {
         MENUITEM "&Icon View",IDM_ICON
         MENUITEM "&Small Icon View",IDM_SMALLICON
         MENUITEM "&List View", IDM_LIST
         MENUITEM "&Report View",IDM_REPORT
        }
}
« Last Edit: August 18, 2015, 05:50:17 PM by Mikl__ »