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

sinsi

  • Member
  • *****
  • Posts: 1007
Re: Examples for Win64 Iczelion tutorial
« Reply #30 on: May 06, 2015, 07:01:58 PM »
Hi, sinsi!
I write in bat-file
Quote
...
/LARGEADDRESSAWARE:NO
...
/BASE:0x400000
so the lines
Quote
sub ecx,ecx
    call GetModuleHandle
    mov hinst,rax
is not needed in my examples, hinst always is 400000h, and mov edx,offset var == lea rdx,var

Fair enough, but later versions of link.exe assume '/largeaddressaware:yes' and 'fixed:no', so if someone uses your code without your batch file it will cause problems.
Using 'mov' instead of 'lea' is an extra 3 bytes too. The only catch is that rip-relative is restricted to rip+/-2GB (signed 32-bit displacement).
Code: [Select]
.text:0000000140001013 48 8D 15 E6 2F 00 00                                lea     rdx, qword_140004000
.text:000000014000101A 48 BA 00 40 00 40 01 00 00 00                       mov     rdx, offset qword_140004000
I can walk on water but stagger on beer.

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #31 on: May 06, 2015, 07:07:16 PM »
Quote
if someone uses your code without your batch file it will cause problems.
sinsi,
programmer must be careful, observant and watchful, and a programmer in assembly in the first place

sinsi

  • Member
  • *****
  • Posts: 1007
Re: Examples for Win64 Iczelion tutorial
« Reply #32 on: May 06, 2015, 07:18:55 PM »
...a programmer in assembly in the first place
But these are tutorials, to teach someone who probably doesn't know ASM.
If you need to use your batch file it should be in every download then. Call it makeit.bat and it can be run from qeditor.
I can walk on water but stagger on beer.

jj2007

  • Member
  • *****
  • Posts: 7765
  • Assembler is fun ;-)
    • MasmBasic
Re: Examples for Win64 Iczelion tutorial
« Reply #33 on: May 06, 2015, 07:31:48 PM »
the program work and it is most importantly, and a style of writing programs can be any... Assembly language programming is creativity!

Sure. I've used such techniques, too, for fun and to obfuscate code. And I understand why some people don't like the HLL elements, like .if .else, .repeat ... .until, local variables and so on.

On the other hand, I'd love to establish a database showing the correlation between "HLL hate" and "lines of useful code produced". To give you an idea: currently I have 3,500+ assembler sources in the Masm32 folder and its sub-folders.

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: Examples for Win64 Iczelion tutorial
« Reply #34 on: May 06, 2015, 08:34:17 PM »
But these are tutorials, to teach someone who probably doesn't know ASM.
If you need to use your batch file it should be in every download then. Call it makeit.bat and it can be run from qeditor.

Good advice. The same is true for every make script or a shell script under Unix.

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

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #35 on: May 07, 2015, 10:05:14 AM »
sinsi,
there is bat-file in attachments, and about
Quote
Call it makeit.bat and it can be run from qeditor.
it's good idea, I'll try to do it
Quote from: sinsi
Code: [Select]
.text:0000000140001013 48 8D 15 E6 2F 00 00                                lea     rdx, qword_140004000
.text:000000014000101A 48 BA 00 40 00 40 01 00 00 00                       mov     rdx, offset qword_140004000
Code: [Select]
.text:00000000004001E8 BA F9 02 40 00                                           mov     edx,offset qword_0004002F9
.text:00000000004001ED 48 8D 15 05 01 00 00                                     lea     rdx, qword_0004002F9
« Last Edit: May 07, 2015, 11:19:43 AM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #36 on: May 08, 2015, 12:57:15 PM »
Win64 Tutorial #10a: DialogBoxParam+DlgProc
asm-file
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
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
IMAGE_BASE      equ 400000h
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
enter 30h,0
xor ebx,ebx
mov ecx,IMAGE_BASE
mov edx,IDC_DIALOG
mov r8,rbx
mov r9d,offset dialog_procedure
mov qword ptr [esp+20h],IDC_MENU
call DialogBoxParam
xor ecx,ecx
        call ExitProcess
WinMain endp

dialog_procedure:
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]
enter 20h+size_of_buffer,0

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_COMMAND
jne wmBYE
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne wmBYE
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp wmBYE
wmINITDIALOG:xor edx,edx
        call GetDlgItem
mov ecx,eax
call SetFocus
jmp wmBYE
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp wmBYE
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
jmp wmBYE
wmCLOSE:xor edx,edx
call EndDialog
wmBYE:  xor eax,eax
leave
retn
;---------------------------------------
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our First Dialog Box',0
end
rc-file
Code: [Select]
#include "resource.h"

#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOG 10, 10, 205, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Tutorial 10a: DialogBoxParam+DlgProc"
MENU IDC_MENU
BEGIN
    EDITTEXT         IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,    141,10,52,13
    PUSHBUTTON      "E&xit", IDC_EXIT,  141,26,52,13
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Say Hello",IDM_SAYHELLO
        MENUITEM "Get Text",IDM_GETTEXT
        MENUITEM "Clear Edit Box",IDM_CLEAR
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "E&xit",IDM_EXIT
    END
END

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #37 on: May 12, 2015, 08:01:54 PM »
Win64 Tutorial #10b: CreateDialogParam+DlgProc
asm-file
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
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
IMAGE_BASE      equ 400000h
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
msg equ [rbp-sizeof MSG]
 
enter 30h+sizeof MSG,0
xor ebx,ebx
mov ecx,IMAGE_BASE
mov edx,IDC_DIALOG
mov r8,rbx
mov r9d,offset dialog_procedure
mov [esp+20h],rbx;IDC_MENU
call CreateDialogParam
mov hWnd,rax
lea edi,msg
message_loop: mov r9,rbx
mov r8,rbx
xor edx,edx
mov ecx,edi
call GetMessage
or eax,eax
jz exit_msg_loop
mov edx,edi
mov rcx,hWnd
call IsDialogMessage
or eax,eax
jnz message_loop
mov ecx,edi
call DispatchMessage
        jmp message_loop
exit_msg_loop:xor ecx,ecx
        call ExitProcess
WinMain endp

dialog_procedure:

hDlg  equ [rbp+10h]
wParam equ [rbp+20h]
lParam equ [rbp+28h]
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]


enter 20h+size_of_buffer,0
        mov hDlg,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
jne wmBYE
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]; choose menu
; choose button or EditBox
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne wmBYE
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp wmBYE
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp wmBYE
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
jmp wmBYE
wmCLOSE:mov rcx,hDlg
        call DestroyWindow
xor ecx,ecx
call PostQuitMessage
wmBYE:  xor eax,eax
leave
retn
;---------------------------------------
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our Second Dialog Box',0
hWnd dq ?
end
rc-file
Code: [Select]
#include "resource.h"

#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOG 10, 10, 205, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Tutorial 10b: CreateDialogParam+DlgProc"
MENU IDC_MENU
BEGIN
    EDITTEXT         IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,    141,10,52,13
    PUSHBUTTON      "E&xit", IDC_EXIT,  141,26,52,13
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Say Hello",IDM_SAYHELLO
        MENUITEM "Get Text",IDM_GETTEXT
        MENUITEM "Clear Edit Box",IDM_CLEAR
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "E&xit",IDM_EXIT
    END
END

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #38 on: May 12, 2015, 08:03:55 PM »
Win64 Tutorial #10c: CreateDialogParam+WndProc+Class
asm-file
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
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
IMAGE_BASE      equ 400000h
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
msg equ [rbp-sizeof MSG]
 
enter 30h+sizeof MSG+sizeof WNDCLASSEX,0
xor ebx,ebx
push 10029h ;hIconSm
mov edi,offset ClassName
push rdi ;lpszClassName
push IDC_MENU ;lpszMenuName
push COLOR_BTNFACE+1;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,IMAGE_BASE
push rsi ;hInstance
push DLGWINDOWEXTRA;cbClsExtra & cbWndExtra
mov eax,offset dialog_procedure
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
mov ecx,IMAGE_BASE
mov edx,IDC_DIALOG
mov r8,rbx
mov r9d,offset dialog_procedure
mov [esp+20h],rbx;IDC_MENU
call CreateDialogParam
mov hWnd,rax
lea edi,msg
message_loop: mov r9,rbx
mov r8,rbx
xor edx,edx
mov ecx,edi
call GetMessage
or eax,eax
jz exit_msg_loop
mov edx,edi
mov rcx,hWnd
call IsDialogMessage
or eax,eax
jnz message_loop
mov ecx,edi
call DispatchMessage
        jmp message_loop
exit_msg_loop:xor ecx,ecx
        call ExitProcess
WinMain endp

dialog_procedure:

hDlg  equ [rbp+10h]
wParam equ [rbp+20h]
lParam equ [rbp+28h]
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]

enter 20h+size_of_buffer,0
        mov hDlg,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
jne wmBYE
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]; choose menu
; choose button or EditBox
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne wmBYE
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp wmBYE
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp wmBYE
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
jmp wmBYE
wmCLOSE:mov rcx,hDlg
        call DestroyWindow
xor ecx,ecx
call PostQuitMessage
wmBYE:  xor eax,eax
leave
retn
;---------------------------------------
ClassName db 'DLGCLASS',0
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our Third Dialog Box',0
hWnd dq ?
end
rc-file
Code: [Select]
#include "resource.h"

#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOG 10, 10, 205, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Tutorial 10c: CreateDialogParam+WndProc+Class"
MENU IDC_MENU
BEGIN
    EDITTEXT         IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,    141,10,52,13
    PUSHBUTTON      "E&xit", IDC_EXIT,  141,26,52,13
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Say Hello",IDM_SAYHELLO
        MENUITEM "Get Text",IDM_GETTEXT
        MENUITEM "Clear Edit Box",IDM_CLEAR
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "E&xit",IDM_EXIT
    END
END

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #39 on: May 15, 2015, 12:15:06 PM »
Win64 Tutorial #10: Dialogs
DlgProcDlgProc+WndProcWndProc+Class
DialogBoxParam+10a+10b10c
CreateDialogParam+10d10e+10f
tut10a.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
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
IMAGE_BASE      equ 400000h
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
enter 30h,0
xor ebx,ebx
mov qword ptr [rsp+20h],IDC_MENU
mov r9d,offset DlgProc
mov r8,rbx
mov edx,IDC_DIALOG
mov ecx,IMAGE_BASE
  call DialogBoxParam
xor ecx,ecx
  call ExitProcess
WinMain endp
DlgProc proc
hWnd equ [rbp+10h]
uMsg equ [rbp+18h]
wParam equ [rbp+20h]
lParam equ [rbp+28h]
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]

enter 40h+size_of_buffer,0
mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
        mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
        cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_NCHITTEST
je wmNCHITTEST
cmp edx,WM_COMMAND
je wmCOMMAND
@1:    mov rax,FALSE
jmp wmBYE
wmCLOSE:;mov rcx,hWnd
xor edx,edx
call EndDialog
    jmp @2
wmINITDIALOG:xor edx,edx
        call GetDlgItem
mov ecx,eax
call SetFocus
mov qword ptr [rsp+30h],SWP_NOZORDER OR SWP_NOMOVE OR SWP_NOSIZE OR SWP_FRAMECHANGED OR SWP_NOACTIVATE
        mov [rsp+28h],rbx
        mov [rsp+20h],rbx
mov r9,rbx
mov r8,rbx
xor edx,edx
mov rcx,hWnd
    call SetWindowPos
    jmp @1
wmNCHITTEST:call DefWindowProc ; (not DefDlgProc, of course)
    cmp rax,HTCLIENT
jnz @f
      mov rax,HTCAPTION
@@:     mov r8,rax
mov edx,DWL_MSGRESULT
mov rcx,hWnd
    call SetWindowLong
    jmp @2
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne @2
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp @2
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp @2
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
@2: mov eax,TRUE
wmBYE: leave
retn
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
DlgProc endp
;---------------------------------------
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our First Dialog Box',0
end
tut10a.rc
Code: [Select]
#include "resource.h"

#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOGEX 10, 10, 205, 60
STYLE WS_POPUP | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
EXSTYLE WS_EX_TOPMOST | WS_EX_CLIENTEDGE
CAPTION "Tutorial 10a: DialogBoxParam+DlgProc"
; CLASS "DlgClass"
MENU IDC_MENU
BEGIN
    EDITTEXT         IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,    141,10,52,13
    PUSHBUTTON      "E&xit", IDC_EXIT,  141,26,52,13
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Say Hello",IDM_SAYHELLO
        MENUITEM "Get Text",IDM_GETTEXT
        MENUITEM "Clear Edit Box",IDM_CLEAR
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "E&xit",IDM_EXIT
    END
END
tut10b
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
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
IMAGE_BASE      equ 400000h
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
enter 30h,0
xor ebx,ebx
mov ecx,IMAGE_BASE
mov edx,IDC_DIALOG
mov r8,rbx
mov r9d,offset dialog_procedure
mov qword ptr [esp+20h],IDC_MENU
call DialogBoxParam
xor ecx,ecx
        call ExitProcess
WinMain endp
align 8
WndProc:
hWnd  equ [rbp+10h]
wParam equ [rbp+20h]
lParam equ [rbp+28h]
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]

enter 20h+size_of_buffer,0
mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
        leave
jmp DefDlgProc
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne wmBYE
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp wmBYE
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp wmBYE
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
jmp wmBYE
wmCLOSE:xor edx,edx
mov rcx,hWnd
call EndDialog
wmBYE:  leave
retn
;----------------------------------------
dialog_procedure:push rbp
mov ebp,esp
sub esp,20h
        cmp rdx,WM_INITDIALOG
jne @f
lea r8d,WndProc
mov edx,GWL_WNDPROC
call SetWindowLongPtr
@@:    xor eax,eax
leave
retn
;---------------------------------------
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our Fifth Dialog Box',0
end
tut10b.rc
Code: [Select]
#include "resource.h"

#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOG 10, 10, 250, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Tutorial 10b: DialogBoxParam+DlgProc+WndPoc"

MENU IDC_MENU
BEGIN
    EDITTEXT         IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,    141,10,52,13
    PUSHBUTTON      "E&xit", IDC_EXIT,  141,26,52,13
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Say Hello",IDM_SAYHELLO
        MENUITEM "Get Text",IDM_GETTEXT
        MENUITEM "Clear Edit Box",IDM_CLEAR
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "E&xit",IDM_EXIT
    END
END
tut10d.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
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
IMAGE_BASE      equ 400000h
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
msg equ [rbp-sizeof MSG]
        enter 40h+sizeof MSG,0

xor ebx,ebx
mov [rsp+20h],rbx
mov r9d,offset DlgProc
mov r8,rbx
mov edx,IDC_DIALOG
mov ecx,IMAGE_BASE
call CreateDialogParam
mov hWin,rax
lea edi,msg
message_loop:mov r9,rbx
mov r8,rbx
xor edx,edx
mov ecx,edi
    call GetMessage
or eax,eax
jz exit_msg_loop
    mov edx,edi
mov rcx,hWin
    call IsDialogMessage
or eax,eax
jnz message_loop
    mov ecx,edi
      call TranslateMessage
        mov ecx,edi
      call DispatchMessage
  jmp message_loop
exit_msg_loop:xor ecx,ecx
call ExitProcess

WinMain endp
DlgProc proc

hWnd equ [rbp+10h]
uMsg equ [rbp+18h]
wParam equ [rbp+20h]
lParam equ [rbp+28h]
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]

enter 40h+size_of_buffer,0
mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
        mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
        cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_NCHITTEST
je wmNCHITTEST
cmp edx,WM_COMMAND
je wmCOMMAND
@1:    xor eax,eax;mov rax,FALSE
jmp wmBYE
wmCLOSE:call DestroyWindow
xor ecx,ecx
    call PostQuitMessage
    jmp @2
wmINITDIALOG:mov qword ptr [rsp+30h],SWP_NOZORDER OR SWP_NOMOVE OR SWP_NOSIZE OR SWP_FRAMECHANGED OR SWP_NOACTIVATE
mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9,rbx
mov r8,rbx
xor edx,edx
call SetWindowPos
        jmp @1
wmNCHITTEST:call DefWindowProc ; (not DefDlgProc, of course)
cmp eax,HTCLIENT
jnz @f
      mov eax,HTCAPTION
@@: mov r8,rax
mov edx,DWL_MSGRESULT
mov rcx,hWnd
    call SetWindowLong
    jmp @2

wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne @1
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp @2
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp @2
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
@2: mov eax,TRUE
wmBYE: leave
retn
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
DlgProc endp
;---------------------------------------
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our Fourth Dialog Box',0
hWin dq ?
end
tut10d.rc
Code: [Select]
#include "resource.h"

#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOGEX 10, 10, 205, 60
STYLE WS_POPUP | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
EXSTYLE WS_EX_TOPMOST | WS_EX_CLIENTEDGE
CAPTION "Tutorial 10d: CreateDialogParam+DlgProc"
; CLASS "DlgClass"
MENU IDC_MENU
BEGIN
    EDITTEXT         IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,    141,10,52,13
    PUSHBUTTON      "E&xit", IDC_EXIT,  141,26,52,13
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Say Hello",IDM_SAYHELLO
        MENUITEM "Get Text",IDM_GETTEXT
        MENUITEM "Clear Edit Box",IDM_CLEAR
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "E&xit",IDM_EXIT
    END
END
tut10f.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
IDM_SAYHELLO equ 0
IDM_GETTEXT equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDC_EDIT equ 0
IDC_BUTTON equ 1
IDC_EXIT equ 2
IDC_MENU equ 100
IDC_DIALOG equ 200
.code
WinMain proc
msg equ [rbp-sizeof MSG]
 
push rbp
mov rbp,rsp
sub rsp,sizeof MSG

xor ebx,ebx
push 10029h ;hIconSm
push rbx ;lpszClassName
push IDC_MENU ;lpszMenuName
push COLOR_BTNFACE+1;hbrBackground
push 10005h ;hCursor
push 10029h     ;hIcon
mov esi,IMAGE_BASE
push rsi ;hInstance
push DLGWINDOWEXTRA;cbClsExtra & cbWndExtra
push rbx ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
mov qword ptr [esp+20h],IDC_MENU
mov r9d,offset WndProc
mov r8,rbx
mov edx,IDC_DIALOG
mov ecx,IMAGE_BASE
call DialogBoxParam
xor ecx,ecx
        call ExitProcess
WinMain endp

WndProc:
size_of_buffer equ 96
buffer equ [rbp-size_of_buffer]

push rbp
mov rbp,rsp
sub rsp,20h+size_of_buffer

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
jne wmBYE
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
cmp r9,rbx ;cmp lParam,0
jnz @f
jmp [menu_handlers+eax*8]
@@: dec eax ;cmp eax,IDC_BUTTON=1
jne @f
SAYHELLO:mov r8d,offset expTxt
jmp @0
@@: dec eax ;cmp eax,IDC_EXIT=2
jne wmBYE
mov edx,WM_CLOSE
mov r8,rbx
mov r9,rbx
call SendMessage
jmp wmBYE
CLEAR: mov r8,rbx
@0: xor edx,edx
call SetDlgItemText
jmp wmBYE
GETTEXT:xor edx,edx
lea r8d,buffer
mov r9d,size_of_buffer
call GetDlgItemText
xor ecx,ecx
mov r9,rcx
mov r8d,offset AppName
lea edx,buffer
call MessageBox
jmp wmBYE
wmCLOSE:xor edx,edx
call EndDialog
wmBYE:  xor eax,eax
leave
retn
;---------------------------------------
menu_handlers dq SAYHELLO,GETTEXT,CLEAR,wmCLOSE
expTxt db "Wow! I'm in an edit box now",0
AppName db 'Our Sixth Dialog Box',0
end
tut10f.rc
Code: [Select]
#include "resource.h"
#define IDM_SAYHELLO 0
#define IDM_GETTEXT 1
#define IDM_CLEAR 2
#define IDM_EXIT 3
#define IDC_EDIT 0
#define IDC_BUTTON 1
#define IDC_EXIT 2

#define IDC_MENU 100
#define IDC_DIALOG 200

IDC_DIALOG DIALOGEX 10, 10, 220, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Iczelion Tutorial #10f: DialogBoxParam+WndProc+Class"
MENU IDC_MENU
BEGIN
    EDITTEXT                     IDC_EDIT,   15,17,111,13, ES_AUTOHSCROLL | ES_LEFT |WS_TABSTOP
    DEFPUSHBUTTON   "Say Hello", IDC_BUTTON,141,10,52, 13,WS_TABSTOP
    PUSHBUTTON      "E&xit",     IDC_EXIT,  141,26,52, 13,WS_TABSTOP
END


IDC_MENU  MENU
BEGIN
    POPUP "Test Controls"
    BEGIN
        MENUITEM "Get Text", IDM_GETTEXT
        MENUITEM "Clear Text", IDM_CLEAR
        MENUITEM SEPARATOR
        MENUITEM "E&xit", IDM_EXIT
    END
END
« Last Edit: May 23, 2015, 11:14:40 AM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #40 on: May 23, 2015, 04:46:34 PM »
Win64 Tutorial #5a: Painting with Rotation Text
Code: [Select]
include win64a.inc
include gdi32.inc
includelib gdi32.lib

.code
WinMain proc
local msg:MSG

        push rbp
mov rbp,rsp
sub rsp,sizeof MSG+20h
xor ebx,ebx
        mov ecx,0FF0000h
call CreateSolidBrush
push 10029h ;hIconSm
mov edi,offset ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push rax;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
mov eax,offset WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
    call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shr esi,7;Special CreateWindow position value CW_USEDEFAULT=8000h
push rbx
push rbx
push rsi
push rsi
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
        mov r9,rbx
mov r8d,50;создаем таймер #0 на 50mSec
xor edx,edx
mov ecx,eax
call SetTimer
  ; +---------------------------+
  ; | entering the message loop |
  ; +---------------------------+
    lea edi,msg
message_loop:mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp message_loop
WinMain endp
WndProc proc hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local ps:PAINTSTRUCT
local expRect:RECT
local expSize:POINT
local newFont:qword
local oldFont:qword

push rbp
mov rbp,rsp
sub rsp,sizeof PAINTSTRUCT+sizeof RECT+sizeof POINT+16+20h

        mov  hwnd,rcx
        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_PAINT
        je   wmPAINT
cmp edx,WM_TIMER
je wmTIMER
        leave
        jmp DefWindowProc
wmDESTROY:xor edx,edx;уничтожаем таймер #0
call KillTimer
xor ecx,ecx
        call ExitProcess
wmTIMER:cmp angle,3600; сравниваем угол с 360 градусами
sbb edx,edx;если угол равен 360 делаем угол равным 0
and dword ptr angle,edx
mov r8d,1
xor edx,edx
call InvalidateRect; перерисовываем текст с текущим значением угла
add angle,16 ;увеличиваем угол на 1,6 градуса
jmp wmBYE
wmPAINT:lea edx,ps
        call BeginPaint
mov ecx,26
mov edx,12
mov r8,angle
mov r9,r8
mov eax,offset expFont
push rax
push DEFAULT_PITCH or FF_SCRIPT
        push rbx;DEFAULT_QUALITY=0
push rbx;CLIP_DEFAULT_PRECIS=0
push rbx;OUT_DEFAULT_PRECIS=0
push OEM_CHARSET
push rbx
push rbx
push rbx
push 400
push rbx
push rbx
push rbx
push rbx
        call CreateFont
mov newFont,rax
        mov rdx,rax
        mov rcx,ps.PAINTSTRUCT.hdc
        call SelectObject
mov oldFont,rax
        lea edx,expRect
mov rcx,hwnd
call GetClientRect
;---------вывожу текст
        mov edx,32C8C8h;RGB=50,200,200 золотистые буквы
        mov rcx,ps.PAINTSTRUCT.hdc
        call SetTextColor
        mov edx,0FF0000h;RGB=0,0,255 на синем фоне
        mov rcx,ps.PAINTSTRUCT.hdc
        call SetBkColor
        lea r9,expSize
mov r8d,sizeof expTxt-1
lea edx,expTxt
mov rcx,ps.PAINTSTRUCT.hdc
call GetTextExtentPoint32
mov qword ptr [rsp+20h],sizeof expTxt
mov r9d,offset expTxt
;---------расчитываю положение начала текста
finit
fld temp3;грузим в FPU коэффициент pi/1800
mov rax,angle
add rax,1800;получили истинный угол
mov temp2,eax
fimul temp2;перевели градусы в радианы
fsincos;в st(0) синус угла, в st(1) косинус
mov eax,expSize.y
mul eax ;получили квадрат высоты текста
mov temp2,eax
mov eax,expSize.x
mul eax ;получили квадрат ширины текста
add temp2,eax;сумма квадратов катетов
shr temp2,2
fild temp2;квадрат гипотенузы=SQR(SIZE.cy)/4 + SQR(SIZE.cx)/4
fsqrt
fistp temp2;получили гипотенузу
fimul temp2;гипотенуза * sin = x
fistp temp1
fimul temp2;гипотенуза * cos = y
fchs;меняем знак y
fistp temp2;-y
mov eax,expRect.bottom
shr eax,1;y-координата середины экрана
add temp2,eax;y-координата начала текста
         mov r8d,temp2
mov ecx,expRect.right
shr ecx,1;x-координата середины экрана
add temp1,ecx;x-координата начала текста
         mov edx,temp1
mov rcx,ps.hdc
         call TextOut
         mov rcx,newFont
call DeleteObject;возвращаем системе старый шрифт
         mov rdx,oldFont
         mov rcx,ps.PAINTSTRUCT.hdc
         call SelectObject
         lea edx,ps
         mov rcx,hwnd
         call EndPaint
wmBYE:   leave
         retn
WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #5a: Painting with Rotation Text',0
expTxt    db 'Win64 assembly with MASM is great and easy',0
expFont   db   'script',0
angle     dq 0
temp1   dd ?
temp2   dd ?
temp3   dq 0.00174532925199432957692369;=pi/1800
end
« Last Edit: August 18, 2015, 05:45:37 PM by Mikl__ »

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: Examples for Win64 Iczelion tutorial
« Reply #41 on: May 23, 2015, 07:51:48 PM »
Hi Mikl__,

thank you for your care. What do you think about this: Should we make a Web site with your examples with the option of download etc?

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

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #42 on: May 23, 2015, 09:48:49 PM »
Thank you, Gunther!
I wouldn't mind, perhaps you can correct my comments, I don't know English enough

Gunther

  • Member
  • *****
  • Posts: 3518
  • Forgive your enemies, but never forget their names
Re: Examples for Win64 Iczelion tutorial
« Reply #43 on: May 24, 2015, 11:03:59 PM »
Hi Mikl__,

Thank you, Gunther!
I wouldn't mind, perhaps you can correct my comments, I don't know English enough

the comments shouldn't be a large problem. We can do it step by step.

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

Mikl__

  • Member
  • ****
  • Posts: 556
Re: Examples for Win64 Iczelion tutorial
« Reply #44 on: May 25, 2015, 12:27:37 PM »
Well, Gunther,
what should be the first step?