flat assembler
Message board for the users of flat assembler.

Index > Windows > Dll fails to load

Author
Thread Post new topic Reply to topic
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz
So i compiled a dll and tried to load it with external app by using LoadLibraryA. guess what, pe loader throws me an error about damaged image Surprised i opened that dll in cff explorer - seems to be just fine. i tried to rebuild it using lordPe - it says that exports table is not found. is it problem in my code or...

Code:
format PE64 GUI DLL
entry DllMain

include 'C:\fasm\INCLUDE\win64a.inc'

proc DllMain hinstDLL,fdwReason,lpvReserved
     mov     eax,TRUE
     ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL'

  import kernel,\
        ExitProcess,'ExitProcess', \
     GetCurrentProcess,'GetCurrentProcess',\
  WriteProcessMemory,'WriteProcessMemory'

section '.edata' export data readable
  export 'StackableSub.dll',\
        DllMain,'DllMain'

section '.reloc' fixups data discardable

section '.code' code readable executable    


also loader to test if dll works:
Code:
format PE64 console
entry start
include 'C:\fasm\INCLUDE\win64a.inc'

start:
  lea rcx, [dllName]
  call [LoadLibraryA]
  mov rdx, rax
  lea rcx, [frmt]
  call [printf]
  call [getchar]
  xor rcx, rcx
  call [ExitProcess]

dllName db "StackableSub.dll", 0
frmt db "%d",0

data import
 library kernel32,'KERNEL32.DLL',\
         msvcrt,'MSVCRT.DLL ';, \
         ;ss,'StackableSub.dll'

 import kernel32,\
        ExitProcess,'ExitProcess', \
     LoadLibraryA,'LoadLibraryA'

 import msvcrt,\
      getchar, 'getchar',\
     printf ,'printf'

end data    
Post 28 Jul 2008, 07:03
View user's profile Send private message Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
Try this code:

Code:
format PE64 GUI DLL
entry DllMain

include 'C:\fasm\INCLUDE\win64a.inc'

section '.code' code readable executable

proc DllMain
hinstDLL equ rcx
fdwReasonequ equ edx
lpvReserved equ r8

     mov     eax,TRUE
     ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL'

  import kernel,\
         ExitProcess,'ExitProcess', \
         GetCurrentProcess,'GetCurrentProcess',\
         WriteProcessMemory,'WriteProcessMemory'

section '.edata' export data readable
  export 'StackableSub.dll',\
         DllMain,'DllMain'

section '.reloc' fixups data discardable
    
Post 28 Jul 2008, 07:43
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz
freakin works :O thx.

EDIT:
cool, i forgot code section.. what an idiot...
Post 28 Jul 2008, 07:56
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.