flat assembler
Message board for the users of flat assembler.

Index > Windows > DLL (need help, thanks)

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

hello Razz ,
This code does compile, but does not work
I don't find my mistake ... help ! Crying or Very sad

Code:
format PE GUI 4.0 DLL
entry DllEntryPoint
include 'WIN32a.INC'
section '.code' code readable executable
;-----------------------------------------------------
proc        DllEntryPoint hinstDLL,fdwReason,lpvReserved
                mov     eax,TRUE
            ret
endp 
;-----------------------------------------------------
proc  myF2 varA2:dword
                push    ebx
         mov     ebx,[varA2]
         pop     ebx
         ret
endp
;-----------------------------------------------------
section '.idata' export data readable
export      'my_DLL.dll',myF2,'myF2'
section '.reloc' fixups data discardable
    
Code:
format PE GUI 4.0
entry start
include 'win32a.inc'
section '.text' code readable executable

start: nop
 int3   ;<---- debugger
   nop
        invoke  myF2,0x1234ABCD
        invoke  ExitProcess,0

section  '.idata' import data readable writeable

library        kernel,'KERNEL32.DLL',\
  my_DLL,'my_DLL.dll'

import     kernel,\
   ExitProcess,'ExitProcess'
import   my_DLL,\
   myF2,'myF2'
    



_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 20 Jan 2012, 22:03
View user's profile Send private message Send e-mail Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
http://board.flatassembler.net/topic.php?t=13751

Your code should look like this:
Code:
format PE GUI 4.0 DLL
entry DllEntryPoint
include 'WIN32a.INC'
section '.code' code readable executable
;-----------------------------------------------------
proc    DllEntryPoint hinstDLL,fdwReason,lpvReserved
                mov     eax,TRUE
                ret
endp 
;-----------------------------------------------------
proc    myF2 varA2:dword
                push    ebx
                mov     ebx,[varA2]
                pop     ebx
                ret
endp
;-----------------------------------------------------
section '.idata' export data readable
export  'my_DLL.dll',myF2,'myF2'
section '.reloc' data discardable ; revolution's idea

data fixups
        if ~ $-$$
                dd      0,8 ;empty fixups section iff no other fixups
        end if
end data    
Post 20 Jan 2012, 22:23
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

it works ! (thank you loco) Razz

but i don't understand why it works.

why "dd 0,8" ?


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 20 Jan 2012, 22:35
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

http://board.flatassembler.net/topic.php?p=33087#33087
Quote:
@leo :
... via dd 0,8 it creates valid reloc directory with no real relocs.

@Tomasz Grysztar
You're right, it puts there a dummy block with no actual fixups (haven't noticed that earlier).
If you need such fix, you can just add this dummy entry "dd 0,8" to the fixups data yourself ...
understood.

But why "0,8" and not "0,7" or "x,y" ???

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 21 Jan 2012, 00:24
View user's profile Send private message Send e-mail Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Well, if I understood the PE specs correctly, the 8 must be there because it is the size of both dwords. The first number I'm not sure it is actually needed to be exactly 0, but probably would be safer to just use it since it works (and probably Microsoft's compilers do the same thing when no relocations are needed for DLLs).

The "0,8" is the base relocation block header, and it says that zero must be added to the relocation offsets coming next and 8 is the total size of both the header and the relocation entries (none since 8 eight only covers the header itself)
Post 21 Jan 2012, 04:20
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
EDIT:
sorry, posted mistakely.
Post 21 Jan 2012, 08:38
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

thank you Loco for this clarification!

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 21 Jan 2012, 08:58
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
That ".reloc" section definition can be shortened this way:
Code:
section '.reloc' data discardable fixups
if ~ $-$$ 
        dd      0,8 ;empty fixups section iff no other fixups 
end if     
Using "data fixups" was needed only when no separate ".reloc" section was to be created (to avoid having empty sections, since WinNT loader has problems with them). As in this case section will never be empty anyway (as it is ensured fixups table will not be empty, probably to avoid problems with some Win9x loaders), the shortened variant of declaring separate section for fixups can be used.
Post 23 Jan 2012, 11:41
View user's profile Send private message Visit poster's website Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
Location: Severodvinsk, Russia
SFeLi
Tomasz Grysztar, btw, is it ok that the following code doesn't trigger an error?
Code:
        virtual
        data fixups ; (any data directory entry actually)
        end data
        end virtual
    
Post 23 Jan 2012, 12:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
No, it is not OK - that is probably a bug.
Post 23 Jan 2012, 13:13
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
Tomasz,
This problem is very recurring ultimately. Is there any legitimate reason for using empty relocs? Windows 7 is not accepting empty relocs and this OS is getting more and more popular, so it should be considered if fasm should be adding "dd 0,8" if it detects that the final output will end up with empty relocs (if the user manually added something in the relocs, then fasm should do nothing in that case).
Post 27 Jan 2012, 00:17
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
Windows 7 does accept empty relocations, as any other NT does (I just checked it now on 64-bit Win7 to be sure). It was Windows 9x that had problem with empty relocations directory.

What Windows 7 and other NT-based systems do not accept is an empty section, and the reasons to not include any workaround were discussed here: http://board.flatassembler.net/topic.php?p=33207#33207

We can, however, provide some macro in standard Windows headers, which would generate .reloc section in such a way, that it would work with most of the Windows versions.
Post 27 Jan 2012, 08:34
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
Sorry, you're right, I thought I also had problems with data fixups/end data but it actually works.
Post 27 Jan 2012, 15:12
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.