flat assembler
Message board for the users of flat assembler.

Index > Windows > About creating a DLL

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
hopcode, if you need to force relocations because the DLL uses no external functions and all addresses happen to be relative, then you can use this:
Code:
section '.reloc' fixups data readable discardable
if ~ $-$$ 
        dd      0,8 ;empty fixups section iff no other fixups 
end if    
In your example, you could save some bytes by using just "dd ExitProcess" since the code is not reachable anyway. However, I think the correct way to have both, the import and relocations, is to use either mine or JohnFound's referencing method and the code block of this post.
Post 09 Jul 2012, 20:48
View user's profile Send private message Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
LocoDelAssembly wrote:
...the code block of this post.
it's ok, a bit safer. nevertheless i dont use this code nor the other above,
because on conditional compilation some references to exp/imp functions may be skipped. one safer workaround could be using something always known as here:
Code:
DllEntryPoint:
 mov eax,DllEntryPoint
 mov eax,1
 ret
    

Cheers

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 10 Jul 2012, 10:44
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
hopcode, although your last code works in 32-bit code, on 64-bit code "mov eax,DllEntryPoint" would use RIP-relative encoding so as a general solution using the complicated reloc section or "dd/dq ExitProcess" (or an internal label if you only want to force relocation) is safer.
Post 10 Jul 2012, 15:57
View user's profile Send private message Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
LocoDelAssembly wrote:
on 64-bit code "mov eax,DllEntryPoint" would use RIP-relative encoding
Wink touché!
it works perfectly, and not RIP
Code:
L_00401000:mov rax, 0x401000
L_0040100A:mov eax, 0x1
L_0040100F:ret     

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 10 Jul 2012, 17:00
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Ups, sorry, I made a terrible mistake! There is no RIP-relative encoding here (as it would happen with LEA), not even if using EAX.
Post 10 Jul 2012, 23:12
View user's profile Send private message Reply with quote
questlima



Joined: 27 Aug 2014
Posts: 37
questlima
This is nice now i know how to write a DLL in FASM:D thanks
Post 27 Aug 2014, 13:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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.