Only two questions :
First question :
I would like to create an X64 program using POASM.
I get the message in the title for many lines of sources could you help me.
include mydsm.inc
include resource.inc
include Includes\user32.inc
include Includes\kernel32.inc
include Includes\gdi32.inc
include Includes\comdlg32.inc
includelib Libraries\user32.lib
includelib Libraries\kernel32.lib
includelib Libraries\comctl32.lib
includelib Libraries\advapi32.lib
includelib Libraries\shell32.lib
includelib Libraries\shlwapi.lib
; includelib Libraries\shfolder.lib
includelib Libraries\gdi32.lib
includelib Libraries\comdlg32.lib
WinMain PROTO :HINSTANCE,:HINSTANCE,:DWORD,:DWORD
WndProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
.Data
ALIGN 4
szClassName db "MainWinClass",0
szAppName db "Main Window",0
szTahoma db "Tahoma",0
Icc INITCOMMONCONTROLSEX <SIZEOF INITCOMMONCONTROLSEX,ICC_WIN95_CLASSES or ICC_STANDARD_CLASSES or ICC_COOL_CLASSES or ICC_TAB_CLASSES>
.Data?
ALIGN 4
hInstance HINSTANCE ?
szModuleFileName db 260 dup(?)
szProgramFolder db 260 dup(?)
szCurrentDirectory db 260 dup(?)
lpszCommandLine LPSTR ?
.Code
ALIGN 16
Start:
and rsp,-16
sub rsp,32
call InitCommonControls
lea rcx,Icc
call InitCommonControlsEx
xor rcx,rcx
call GetModuleHandle
mov hInstance,rax
mov rcx,rax
lea rdx,szModuleFileName
mov r8d,SIZEOF szModuleFileName
call GetModuleFileName
lea rcx,szProgramFolder
lea rdx,szModuleFileName
call lstrcpy
mov rcx,rax
call PathFindFileName
mov BYTE PTR [rax - 1],0
lea rdx,szCurrentDirectory
mov rcx,MAX_PATH
call GetCurrentDirectory
call GetCommandLine
mov lpszCommandLine,rax
mov rcx,hInstance
xor rdx,rdx
mov r8,lpszCommandLine
mov r9,SW_SHOWDEFAULT
call WinMain
mov rcx,rax
add rsp,32
call ExitProcess
WinMain PROC __hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:DWORD,CmdShow:DWORD
LOCAL _Wc:WNDCLASSEX
LOCAL _Msg:MSG
LOCAL _hWnd:HWND
and rsp,-16 ;to make the stack 16byte aligned
mov __hInst,rcx ;hInst is the name of the shadow space variable!
sub rsp,96
xor rcx,rcx
mov rdx,IDC_ARROW
call LoadCursor
mov _Wc.hCursor,rax
mov rcx,__hInst
mov rdx,IDI_ICON_01
call LoadIcon
lea rcx,_Wc
mov rdx,__hInst
mov _Wc.hIcon,rax
mov _Wc.hIconSm,rax
mov _Wc.cbSize,SIZEOF WNDCLASSEX
lea rax,WndProc
mov _Wc.style,CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS; or CS_DROPSHADOW
mov _Wc.lpfnWndProc,rax
xor rax,rax
mov _Wc.hInstance,rdx
mov _Wc.cbClsExtra,eax
mov _Wc.cbWndExtra,eax
mov _Wc.lpszMenuName,IDM_MENU
lea rax,szClassName
mov _Wc.hbrBackground,COLOR_WINDOW + 1
mov _Wc.lpszClassName,rax
call RegisterClassEx
mov eax,CW_USEDEFAULT
xor rcx,rcx
mov DWORD PTR [rsp+32],eax
mov DWORD PTR [rsp+40],eax
mov DWORD PTR [rsp+48],eax
mov DWORD PTR [rsp+56],eax
lea rdx,szClassName
lea r8,szAppName
mov rax,__hInst
mov r9d,WS_OVERLAPPEDWINDOW
mov [rsp+64],rcx
mov [rsp+72],rcx
mov [rsp+80],rax
mov [rsp+88],rcx
call CreateWindowEx
mov _hWnd,rax
mov rcx,rax
mov edx,SW_SHOWNORMAL
call ShowWindow
mov rcx,_hWnd
call UpdateWindow
add rsp,96
@Loop :
sub rsp,32
lea rcx,_Msg
xor r8,r8
mov rdx,r8
mov r9,r8
call GetMessage
test rax,rax
jz @EndLoop
lea rcx,_Msg
call TranslateMessage
lea rcx,_Msg
call DispatchMessage
add rsp,32
jmp @Loop
@EndLoop :
add rsp,32
mov rax,_Msg.wParam
ret
WinMain ENDP
WndProc PROC hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor rax,rax
ret
WndProc ENDP
END Start
Building mydsm.obj.
Building Window.exe.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szAppName'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szClassName'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szClassName'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'WndProc'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'lpszCommandLine'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'hInstance'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'lpszCommandLine'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szCurrentDirectory'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szModuleFileName'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szProgramFolder'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'szModuleFileName'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'hInstance'.
POLINK: error: Relocation type ADDR32 is invalid without /LARGEADDRESSAWARE:NO, for symbol 'Icc'.
*** Error code: 1 ***
Done.
Second question :
What is the POASm equivalent syntax for :
mov (WNDCLASSEX PTR [rcx]).lpszClassName,rax
Thanks for your help
> I get the message in the title for many lines of sources could you help me.
Most likely Poasm generates "wrong" fixups: absolute 32-bit fixups instead of RIP-relative 32-bit fixups.
You can check this by running the MS Dumpbin utility with the object module:
DUMPBIN /relocations test.obj
the output must not contain ADDR32 fixups ( it should contain REL32 and ADDR64 fixups only )
> mov (WNDCLASSEX PTR [rcx]).lpszClassName,rax
should be rewritten to:
mov [rcx].WNDCLASSEX.lpszClassName,rax
Case I will try any assembly experiments in the future:
What do you mean with 'fixups'?
Quote from: czerny on August 26, 2013, 08:11:22 AM
Case I will try any assembly experiments in the future:
Fixups ( aka relocations ) are nothing specific to assembly language or assemblers. If you have happily written working C code for years and never had any need to know what a fixup is, you most likely also won't need to know it with your assembly experiments.
Generally, fixups is information written by the assembler/compiler to tell the linker where relocatable addresses are found in the object module and how to handle them. Virtually all global variables in your code have such a type of address.
Ok, so 'fixup' is only a synonym for 'relocation table entry'. Thanks!