flat assembler
Message board for the users of flat assembler.

Index > Windows > how to make a dll for dummies in fasm?? :-p

Author
Thread Post new topic Reply to topic
jhoan100



Joined: 19 Aug 2009
Posts: 1
jhoan100
Is there a basic tutorial to create a dll whit fasm? Question
Post 19 Aug 2009, 04:53
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
Welcome to the FASM board! Always nice to see new people here.

This particular question would go better in the Windows forum, as DLL's are a Windows thing and not macros.

Have you checked the example directory of FASM? There is a DLL example in there.

Hmm, I've done a search of the boards and can't find a DLL tutorial, but maybe someone else can.

You should check out the iczelion windows assembly tutorials. There's FASM versions of the code in there floating around on the forums somewhere, maybe someone else can help you find them.

_________________
----> * <---- My star, won HERE
Post 19 Aug 2009, 05:16
View user's profile Send private message Reply with quote
Pirata Derek



Joined: 31 Oct 2008
Posts: 259
Location: Italy
Pirata Derek
This is a simple DLL and you can use it for your code:
Code:
Format PE GUI 5.0 DLL
include 'Flat32\win32a.inc' ; select your include files for win32
entry DllStart

; Insert your codes and procs here
section '.code' code readable executable

; This proc must be the entry of a dll
proc DllStart DllHandle,Reason,Reserved

     ; insert your personal inizialization library code

     mov eax,TRUE ; this proc MUST have TRUE return value
     ret ; to let kernel loads the requested library
endp

; You can add more procs you want
proc Procedure_1 param_1
     ; insert your code
     ret
endp

proc Procedure_2 param_1,param_2
     ; ....
     ret
endp

; Insert all your data here
section '.data' data readable writeable

var_1 db 'generic variable',0
var_2 dd TRUE
var_3 rd 4

; here there're the imports your library needs
section '.idata' import readable

; an import example
library kernel,'kernel32.dll'
import kernel,\
     ExitProcess,'ExitProcess'

; Your functions in code section will exported here
section '.edata' export readable

export 'My_Library.dll',\
     Procedure_1,'FirstExport',\
     Procedure_2,'SecondExport'

; For relocations of refers to dinamic code, don't touch
section '.reloc' fixups discardable

; The resource of your library (not important)
section '.rsrc' resource readable discardable

; ... resources blah, blah ... add what you want    

To make a DLL you have to know how it works:
1) Evrytime the kernel load the library, it executes a DLL_???_ATTACH to the DllStart proc and after a DLL_???_DETACH. (this is the Reason parameter value)
2) Kernel uses the reloc section to find the virtual reallocated functions offsets in RAM.
3) A library is a special PE executable and can also invoke another library
4) For more detailed informations, tell me....
Post 26 Aug 2009, 08:35
View user's profile Send private message Send e-mail Reply with quote
sacio



Joined: 06 Oct 2009
Posts: 2
Location: Norway
sacio
Sorry for hijacking your thread jhoan100, but my question is so related that making a new thread would be flooding.

I'm new to FASM, and assembly in general (only coded a little for 8 bit AVRs) and want to make simple dll to play with.

I've looked at the DLL example which came with FASM, and understands most of the important code. But say I want to pass 2 integers to a proc, do some calculation and then return the result. How can I return something from a proc in a DLL?

Newb alert, be kind and thanks in advance!

Great forum by the way Smile
Post 07 Oct 2009, 16:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
Normally return values are passed in EAX.

Just use:
Code:
mov eax,my_return_value
retn 8    
The 'retn 8' is to pop off the two parameters you passed (assumes 32bit STDCALL convention).
Post 07 Oct 2009, 16:29
View user's profile Send private message Visit poster's website Reply with quote
sacio



Joined: 06 Oct 2009
Posts: 2
Location: Norway
sacio
Alright! That cleared things up a bit. Thanks revolution!
Post 07 Oct 2009, 17:08
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 YouTube, Twitter.

Website powered by rwasa.