flat assembler
Message board for the users of flat assembler.

Index > Windows > Win32 API call problem

Author
Thread Post new topic Reply to topic
bobsobol



Joined: 31 May 2010
Posts: 18
Location: U.K.
bobsobol
Code:
section '.rdata' data readable export import
library Kernel32, KERNEL32.dll
include 'api\kernel32.inc'
call [GetCurrentThread]    

Error: undefined symbol 'GetCurrentThread'

And yet it is defined in 'api\kernel32.inc'... I've tried all sorts of simple combinations to get syntax it may accept, but get the same result.

The manual only tells you how to "invoke" or "stdcall" DLL imports, and states that they are both interpreted as
Code:
invoke MessageBox,0,szText,szCaption,MB_OK    
or
Code:
stdcall [MessageBox],0,szText,szCaption,MB_OK    
or
Code:
push MB_OK
push szCaption
push szText
push 0
call [MessageBox]    
So why can't I manually write the final form?

Do I need to be more specific [KERNEL32!GetCurrentThread] or [KERNEL32:GetCurrentThread] or DWord[GetCurrentThread] all seem to work out the same. :s

Edit:-
Actually... my include clearly isn't working, as "invoke GetCurrentThread" isn't working either. So how have I got that wrong?

I'm sure it's simple syntax issue.

TIA.
Post 09 Jun 2010, 15:15
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
bobsobol,

API\KERNEL32.INC expects import macro to be defined. import macro from MACRO\IMPORT32.INC expects library macro to be invoked (its expansion from API\KERNEL32.INC invocation is effectively nothing if kernel32.referred isn't defined).

FASM symbols are case-sensitive (Kernel32 != kernel32). library macro expects even argument to be a string.

You may use extended headers to simplify import (API\KERNEL32.INC is a supplementary include file for WIN32[AW]X.INC).
Post 09 Jun 2010, 15:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
Well you didn't post all of your code so we don't know what is really wrong, but the library macro needs a string parameter.
Code:
library kernel32, 'KERNEL32.dll'    
Post 09 Jun 2010, 15:42
View user's profile Send private message Visit poster's website Reply with quote
bobsobol



Joined: 31 May 2010
Posts: 18
Location: U.K.
bobsobol
Complete source listing exceeds 23Meg... I think nobody would read it. XD

Thanks for the responses.

Let's see if I can minimise the true source to essential parts.

Main.asm
Code:
format PE GUI 4.0
entry EntryPoint

include 'win32a.inc'

include 'macro.inc'
include 'static.inc'
include 'data.inc'

section '.text' code readable executable 
...
...
...    


win32a.inc you all have and know.

macro.inc
Code:
ptr    equ    
Just for compatibility reasons with old ASM.

static.inc
Code:
section '.rdata' data readable export import
include '.\imports.inc'
...
...
...    
Lots of dd, db, dw, db xxx DUP (?) and so on.

imports.inc
Code:
 library DSound, DSOUND.dll, \
         ODBC32, ODBC32.dll, \
         Kernel32, KERNEL32.dll, \
         User32, USER32.dll, \
         GDI32, GDI32.dll, \
         AdvAPI32, ADVAPI32.dll, \
         Shell32, SHELL32.dll, \
         OLE32, ole32.dll, \
         Custom, Custom.dll, \
         DDraw, DDRAW.dll, \
         WinMM, WINMM.dll, \
         ShlWAPI, SHLWAPI.dll, \
         WinINet, WININET.dll, \
         IMM32, IMM32.dll, \
         CustomSQL, CustomSQLDll.dll

; library DSound, DSOUND.dll
 import DSound,\
        DirectSoundEnumerate,'DirectSoundEnumerateA'    ; DSOUND.dll!DSOUND.1

; library ODBC, ODBC32.dll
 import ODBC32,\
        SQLBindParam, 'SQLBindParam', \                         ; ODBC32.24
        SQLExecute, 'SQLExecute', \                             ; ODBC32.11
        SQLCancel, 'SQLCancel', \                               ; ODBC32.4
        SQLFreeConnect, 'SQLFreeConnect', \                     ; ODBC32.13
        SQLGetCursorName, 'SQLGetCursorName', \                 ; ODBC32.16
        SQLGetConnectAttr, 'SQLGetConnectAttr', \               ; ODBC32.31
        SQLError, 'SQLError', \                                 ; ODBC32.9
        SQLSetStmtAttr, 'SQLSetStmtAttr', \                     ; ODBC32.75
        SQLDescribeCol, 'SQLDescribeCol'                        ; ODBC32.7

 include 'api\kernel32.inc'

 include 'api\user32.inc'

 include 'api\gdi32.inc'
 
 include 'api\advapi32.inc'

 include 'api\SHELL32.inc'

; library OLE32, ole32.dll
 import OLE32, \
        CoUninitialize, 'CoUninitialize', \
        CoCreateInstance, 'CoCreateInstance', \
        CoInitialize, 'CoInitialize'

; library Custom, Custom.dll
 import Custom, \
        DecryptFunc, '?DecryptFunc@@YAHPAD0@Z'

; library DDraw, DDRAW.dll
 import DDraw, \
        DirectDrawCreate, 'DirectDrawCreate'

; library WinMM, WINMM.dll
 import WinMM, \
        timeGetTime, 'timeGetTime', \
        timeEndPeriod, 'timeEndPeriod', \
        mixerSetControlDetails, 'mixerSetControlDetails', \
        mixerGetLineInfo, 'mixerGetLineInfoA', \
        mixerGetLineControls, 'mixerGetLineControlsA', \
        mixerGetControlDetails, 'mixerGetControlDetailsA', \
        mixerGetDevCaps, 'mixerGetDevCapsA', \
        mixerOpen, 'mixerOpen', \
        mixerClose, 'mixerClose', \
        mmioGetInfo, 'mmioGetInfo', \
        mmioAdvance, 'mmioAdvance', \
        mmioSetInfo, 'mmioSetInfo', \
        mmioSeek, 'mmioSeek', \
        mmioOpen, 'mmioOpenA', \
        mmioDescend, 'mmioDescend', \
        mmioRead, 'mmioRead', \
        mmioAscend, 'mmioAscend', \
        mmioClose, 'mmioClose', \
        timeBeginPeriod, 'timeBeginPeriod', \
        timeSetEvent, 'timeSetEvent', \
        timeKillEvent, 'timeKillEvent'

; library ShlWAPI, SHLWAPI.dll
 import ShlWAPI, \
        PathFileExists, 'PathFileExistsA'

; library WinINet, WININET.dll
 import WinINet, \
        HttpQueryInfo, 'HttpQueryInfoA', \
        InternetCloseHandle, 'InternetCloseHandle', \
        InternetQueryDataAvailable, 'InternetQueryDataAvailable', \
        InternetOpen, 'InternetOpenA', \
        InternetOpenUrl, 'InternetOpenUrlA', \
        InternetReadFile, 'InternetReadFile'

; library IMM32, IMM32.dll
 import IMM32, \
        ImmSetConversionStatus, 'ImmSetConversionStatus', \
        ImmGetContext, 'ImmGetContext', \
        ImmSetCompositionWindow, 'ImmSetCompositionWindow', \
        ImmSetOpenStatus, 'ImmSetOpenStatus'

 include 'api\wsock32.inc'

; library CustomSQL, CustomSQLDll.dll
 import CustomSQL, \
        SQLDelCharProcess, '?SQLDelCharProcess@@YAHPAD0@Z', \
        SQLAddCharProcess, '?SQLAddCharProcess@@YAHPAD0@Z', \
        SQLLoginProcess, '?SQLLoginProcess@@YAHPAD@Z', \
        SQLLogoutProcess, '?SQLLogoutProcess@@YAHPAD000KH@Z'    
I stripped some large comment blocks.

data.inc
Code:
section '.data' data readable writeable
...
...
...
;lots more dd, dw, db etc
...
...
...
include 'undefined.inc'    


undefined.inc
Code:
...
...
...
;lost of labels with db    xxx    DUP   (?)
...
...
...    


It's probably a matter of mixed case... I'll go back over the official includes and check the case they use.

EDIT---
Yes... case, and putting single quotes around the DLL names in "library" definition seem to do the trick.

I will port to FASM yet. ^_^ Thanks baldr.
Post 09 Jun 2010, 19:50
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.