flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > .code and .end macros

Author
Thread Post new topic Reply to topic
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 15 Aug 2006, 04:33
hello:
i have found the .code and .end macros very usefull,
i just have to put them in the sorce and i forget about
usin the import and library macros, but what if i want to
add the functions of another dll, let us say: i already have
the name of the dll and the name of the functions, my question
is: what modifications, in what files must i make to add these
functions? so wen i use the .code and .end macros the import
section gets automatically generated using all the
standard import tables plus the one i have add.

well i believe i have to create a file with the

Code:
 import DLL_label,\
                 function_label1,'functionname',\
                 function_label2,'functionname2',\
                 ............
                 ............     
    

and put it in the apia or apiw folder but, what else?

thanks.
Post 15 Aug 2006, 04:33
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4623
Location: Argentina
LocoDelAssembly 15 Aug 2006, 06:37
http://board.flatassembler.net/topic.php?t=5658 <- The same problem but the solution does not rely on .ends though
Post 15 Aug 2006, 06:37
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7103
Location: Slovakia
vid 15 Aug 2006, 07:09
sorry, when using "win32[a/w]xp.inc", you just can't add imports youself.
Post 15 Aug 2006, 07:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Xanfa



Joined: 03 Aug 2006
Posts: 29
Xanfa 15 Aug 2006, 13:31
Oh I've look at .end macro once or twice (not remember) and what it does (in my memory) is import DLLs that come with Fasm package. Now I can't write here what step to do this, but this a suggestion to modify this macro more useful: Using match directive to modify the .end macro so it have its arguments, such as:

.end 'MyDll1.dll',function1,function2,'Dll2.dll',function1,function2...

and what to do is add these library and its function to library and import macro (modify the win32a/wx.inc)...

and if you type:
.end
it will generate the orginal .end macro as it is...

I'll try make this modify, and if perfect, i'll post it !
Post 15 Aug 2006, 13:31
View user's profile Send private message Yahoo Messenger Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 16 Aug 2006, 06:15
greetings:
i've encounter a solution for what i wanted:

first this is the code for an example dll from which we want
to use the functions:
Code:

format PE GUI 4.0 DLL

include 'win32ax.inc'

section '.code' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        invoke MessageBox,0,content,title,MB_OK
        mov     eax,TRUE
        ret
endp
ReturnString:   ;this function has no parameters
                      ;and return in edi a pointer to a
                      ;string contained in the data section
                      ;of this dll
        mov edi,string
        ret
ShowBox:    ;this function has no parameters  (in the stack i mean)
                  ;expects in esi a pointer to a string in the program
                  ;that calls this DLL and shows it in a messagebox
            invoke MessageBox,0,esi,title2,MB_OK
            ret
Exit:       ;this just calls the ExitProcess function
            invoke ExitProcess,0
;-------------------------------------
.end DllEntryPoint  ;the beloved macro
;-------------------------------------
section 'data' data readable writeable
title db 'Hello from DLL',0
title2 db 'the below string is in the exe file',0
content db 'DLL loaded successfully',0
string db 'this string is in the dll data section',0
;-------------------------------------
section '.edata' export data readable

  export 'CUSTOM.DLL',\
         ReturnString,'ReturnString',\
         ShowBox,'ShowBox',\
         Exit,'Exit'
;--------------------------------------
section '.reloc' fixups data discardable
    


then i create a file CUSTOM.INC with:

Code:
import custom,\
       ReturnString,'ReturnString',\
       ShowBox,'ShowBox',\
       Exit,'Exit'

    

and copy it to the include\apia folder
then i modifie the win32ax.inc adding the commented parts:

Code:
macro import lib,[functions]
{ common macro import_#lib \{ import lib,functions \} }

include 'apia/kernel32.inc'
include 'apia/user32.inc'
include 'apia/gdi32.inc'
include 'apia/advapi32.inc'
include 'apia/comctl32.inc'
include 'apia/comdlg32.inc'
include 'apia/shell32.inc'
include 'apia/wsock32.inc'
include 'apia/CUSTOM.inc'  ;<---added

purge import

macro .data { section '.data' data readable writeable }

macro .code { section '.text' code readable executable }

macro .end label
{
   entry label

   section '.idata' import data readable writeable

     library kernel32,'KERNEL32.DLL',\
             user32,'USER32.DLL',\
             gdi32,'GDI32.DLL',\
             advapi32,'ADVAPI32.DLL',\
             comctl32,'COMCTL32.DLL',\
             comdlg32,'COMDLG32.DLL',\
             shell32,'SHELL32.DLL',\
             wsock32,'WSOCK32.DLL',\
             custom,'CUSTOM.DLL'     ;<---added
     import_kernel32
     import_user32
     import_gdi32
     import_advapi32
     import_comctl32
     import_comdlg32
     import_shell32
     import_wsock32
     import_custom   ;<---added
}

    


and now i can assemble the program below that uses this
functions:

Code:
format pe gui
include 'win32ax.inc'
section 'code' code readable executable
start:
        invoke ReturnString    ;returns in edi a pointer to
                               ;string contained in the data
                               ;section of the dll
        invoke MessageBox,0,edi,title,MB_OK

        mov esi,msg

        invoke ShowBox

        invoke Exit


;-------------------------------------
section 'data' data readable writeable

title db 'the below string comes from the dll',0
msg db 'hello from exe data section',0
;-------------------------------------
.end start

    


i have only encountered one problem:
when i assembled the dll, the win32ax.inc file was not
modified so everything was ok, then i modifie the win32ax.inc
file and assemble the program that uses the dll and again
everything works, but if i assemble the dll again with the
win32ax.inc modified it gives a error:symbol already defined


well, what do you think?
vid: do you think is safe to use this method?
or maybe can lead up to any other error apart from
the "error: symbol already defined" error.

thanks to all.
Post 16 Aug 2006, 06:15
View user's profile Send private message Reply with quote
Xanfa



Joined: 03 Aug 2006
Posts: 29
Xanfa 16 Aug 2006, 12:56
ReturnString, ShowBox and Exit already defined in the custom.inc file (modified), so U can't use it in your DLL when U assemble it again. Try rename the label in your DLL file, the problem may be fix. Example:

export 'CUSTOM.DLL',\
ReturnStringxx,'ReturnString',\
ShowBoxxx,'ShowBox',\
Exitxx,'Exit'
Post 16 Aug 2006, 12:56
View user's profile Send private message Yahoo Messenger Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 17 Aug 2006, 04:35
so I get it:
the labels in the dll code and export section
should not be equal to those in the import file
only the quoted strings, and the labels in the
sources that use this functions should match
the labels in the import file.
and in this way everything works.

thanks.
Post 17 Aug 2006, 04:35
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.