flat assembler
Message board for the users of flat assembler.

Index > Windows > moving x86 to 64

Author
Thread Post new topic Reply to topic
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 17 Feb 2014, 15:31
I need to move some x86 to 64 source code
The result not make window or canvas, not error under fasm compile or run , just windows try show me something into taskbar ( I think is a error).
Also I need a good debugger for fasm .
This is the source code :
Code:
       mov     [hwnd],rcx
       mov     [wmsg],rdx
       mov     [wparam],r8
       mov     [lparam],r9
       mov     rax,[wmsg]
 local ps:PAINTSTRUCT
        mov     rax,[wmsg]
        cmp     rax,WM_PAINT
        je      .wmpaint
        cmp     rdx,WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmpaint:
        lea     rax,[ps]
        invoke  BeginPaint,[hwnd],rax      
Post 17 Feb 2014, 15:31
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 Feb 2014, 16:38
1. This already looks like 64 bit code.
2. ??
3. A good Assembly* debugger is always OllyDbg (32 bit only, 64-bit is in development). There's Visual DuxDebugger (64 bit) but it's buggy as hell. The best free debugger for both 32 and 64 is WinDbg. If you want to invest there's IDAPro.
Post 17 Feb 2014, 16:38
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 17 Feb 2014, 16:53
... maybe is something with addressing regs !?
maybe if I running under debugger will see where is the error .
typedef wrote:
1. This already looks like 64 bit code.
2. ??
3. A good Assembly* debugger is always OllyDbg (32 bit only, 64-bit is in development). There's Visual DuxDebugger (64 bit) but it's buggy as hell. The best free debugger for both 32 and 64 is WinDbg. If you want to invest there's IDAPro.
Post 17 Feb 2014, 16:53
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 Feb 2014, 17:52
Lol. Pass the parameters in this order on windows

rcx : 1st parameter
rdx : 2nd parameter
r8 : 3rd
r9 : 4th

Any more parameters are passed on stack.

Also make note of the Red Zone

http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
Post 17 Feb 2014, 17:52
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 17 Feb 2014, 19:05
I don't understand not is apply the stack rules ?
first - in , first - out , where is the error ?
also this mean: 64-bit code you must align the stack to 0 mod 16 !?

typedef wrote:
Lol. Pass the parameters in this order on windows

rcx : 1st parameter
rdx : 2nd parameter
r8 : 3rd
r9 : 4th

Any more parameters are passed on stack.

Also make note of the Red Zone

http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
Post 17 Feb 2014, 19:05
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 17 Feb 2014, 20:05
OK . I understend from where came the error . Smile
See my source code ... I think is working well under 64 bit .
If somebody has any idea then let me know Smile
Code:
format PE64 GUI 5.0
entry start

include 'win64a.inc'

section '.text' code readable executable

  start:
        sub     rsp,8           ; Make stack dqword aligned

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],rax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],rax
        mov     [wc.hIconSm],rax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],rax
        invoke  RegisterClassEx,wc
        test    rax,rax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
        test    eax,eax
        jz      error

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     rax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses rbx rsi rdi, hwnd,wmsg,wparam,lparam

       mov     [hwnd],rcx
       mov     [wmsg],rdx
       mov     [wparam],r8
       mov     [lparam],r9
       mov     rax,[wmsg]
align  16
local ps:PAINTSTRUCT
        cmp     rax  ,WM_PAINT
        je      .wmpaint
        cmp     rax  ,WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmpaint:
        lea     rax  ,[ps]
        invoke  BeginPaint,[hwnd],rax
        invoke  SetPixel,[ps.hdc],10,10,0x00000000 ; paint black pixel at [x,y]
        lea     rax,[ps]
        invoke  EndPaint,[hwnd],rax
        jmp     .zfinish
  .wmdestroy:
        invoke  PostQuitMessage,0
  .zfinish:
        xor     eax,eax
  .finish:
        ret

endp

section '.data' data readable writeable

  _title TCHAR 'Graphics 64',0
  _class TCHAR 'FASMWIN64',0
  _error TCHAR 'Startup failed.',0

  wc WNDCLASSEX sizeof.WNDCLASSEX,0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class,NULL

  msg MSG

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\ 
          user32,'USER32.DLL',\ 
          gdi32,'GDI32.DLL' 


  include 'API\KERNEL32.INC' 
  include 'API\USER32.INC' 
  include 'API\GDI32.INC'
    
Post 17 Feb 2014, 20:05
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.