NO

Author Topic: Undecorated symbols  (Read 4302 times)

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Undecorated symbols
« on: June 12, 2011, 11:16:11 AM »
Hello,

The SYSCALL calling convention allows the usage of undecorated symbols. Here is an example.

Code: [Select]
\PellesC\bin\polib /OUT:kernel32.lib C:\WINDOWS\system32\kernel32.dll
\PellesC\bin\polib /OUT:user32.lib C:\WINDOWS\system32\user32.dll

\PellesC\bin\poasm Window.asm
\PellesC\bin\polink /SUBSYSTEM:WINDOWS Window.obj kernel32.lib user32.lib

Code: [Select]
; Source code assembled with Pelles Macro Assembler, Version 6.50.0

.386
.model flat,syscall
option casemap:none

include     Window.inc

.data
ClassName   db "WindowClasss",0
AppName     db "Window demo",0

.data?
hInstance   dd ?

.code

_start:

    _invoke     GetModuleHandle,0
    mov         hInstance,eax
    _invoke     GetCommandLine
    _invoke     WinMain,hInstance,NULL,eax,SW_SHOWDEFAULT
    _invoke     ExitProcess,eax

WinMain PROC hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:DWORD

    mov     wc.cbSize,SIZEOF WNDCLASSEX
    mov     wc.style, CS_HREDRAW or CS_VREDRAW
    mov     wc.lpfnWndProc, OFFSET WndProc
    mov     wc.cbClsExtra,NULL
    mov     wc.cbWndExtra,NULL
    push    hInstance
    pop     wc.hInstance
    mov     wc.hbrBackground,COLOR_WINDOW+1
    mov     wc.lpszMenuName,NULL
    mov     wc.lpszClassName,OFFSET ClassName
    _invoke LoadIcon,NULL,IDI_APPLICATION
    mov     wc.hIcon,eax
    mov     wc.hIconSm,eax
    _invoke LoadCursor,NULL,IDC_ARROW
    mov     wc.hCursor,eax
    _invoke RegisterClassEx,<ADDR wc>
    _invoke CreateWindowEx,NULL,<ADDR ClassName>,<ADDR AppName>,\
            <WS_OVERLAPPEDWINDOW or WS_VISIBLE>,100,\
            100,500,400,NULL,NULL,\
            hInst,NULL
    mov     hwnd,eax
    _invoke UpdateWindow,hwnd
   
    .WHILE  TRUE
   
        _invoke GetMessage,<ADDR msg>,NULL,0,0
        .BREAK  .IF (!eax)
        _invoke TranslateMessage,<ADDR msg>
        _invoke DispatchMessage,<ADDR msg>

    .ENDW
   
    mov     eax,msg.wParam
    ret     4*4

WinMain ENDP


WndProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
 
    .IF uMsg==WM_DESTROY
        _invoke PostQuitMessage,NULL

    .ELSE
        _invoke DefWindowProc,hWnd,uMsg,wParam,lParam       
        ret     4*4     
       
    .ENDIF
   
    xor     eax,eax
    ret     4*4

WndProc ENDP


END _start
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Undecorated symbols
« Reply #1 on: June 12, 2011, 01:52:52 PM »
Using PellesCDir environment variable for that bat:
Code: [Select]
"%PellesCDir%\bin\polib.exe" /OUT:kernel32.lib C:\WINDOWS\system32\kernel32.dll
"%PellesCDir%\bin\polib.exe" /OUT:user32.lib C:\WINDOWS\system32\user32.dll

"%PellesCDir%\bin\poasm.exe" Window.asm
"%PellesCDir%\bin\polink.exe" /SUBSYSTEM:WINDOWS Window.obj kernel32.lib user32.lib
May the source be with you