Author Topic: Creating a DLL without Dependencies  (Read 5784 times)

x64Core

  • Member
  • **
  • Posts: 80
Creating a DLL without Dependencies
« on: May 29, 2012, 01:45:52 PM »
Hello all guys, fine, I'm trying create a DLL without dependencies :P
but, it adds MSVCRT.DLL:


then, exist a way to create it without MSVCRT.DLL?
the DLL is right, has a size of 3kb wow!

any words, thanks !  :biggrin:


Code: [Select]
code:

include masm32rt.inc

.data
mymsg db "Hello world from DLL :D",0
.code
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
    invoke MessageBox,NULL,addr mymsg,addr mymsg,MB_OK
    ret
DllEntry Endp


End DllEntry


P1

  • Global Moderator
  • Member
  • *****
  • Posts: 63
Re: Creating a DLL without Dependencies
« Reply #1 on: May 29, 2012, 02:43:37 PM »
Hello all guys, fine, I'm trying create a DLL without dependencies :P
but, it adds MSVCRT.DLL:


then, exist a way to create it without MSVCRT.DLL?
the DLL is right, has a size of 3kb wow!

any words, thanks !  :biggrin:


Code: [Select]
code:

include masm32rt.inc

.data
mymsg db "Hello world from DLL :D",0
.code
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
    invoke MessageBox,NULL,addr mymsg,addr mymsg,MB_OK
    ret
DllEntry Endp


End DllEntry
That is easy, just don't use ANY Windows API functions or procedures, including MessageBox.

Regards,  P1   8)

x64Core

  • Member
  • **
  • Posts: 80
Re: Creating a DLL without Dependencies
« Reply #2 on: May 29, 2012, 02:53:40 PM »
but why? in a Portable Executable I can do the same,
and it does not require of MSVCRT.DLL.... :(

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Creating a DLL without Dependencies
« Reply #3 on: May 29, 2012, 02:56:43 PM »
well - msvcrt should not be getting pulled in
it looks as though you have a call to the "wait_key" macro or something
i build it here - and the only dependency is user32.dll

what ML and LINK command lines are you using ?
Code: [Select]
ml /c /coff dll.asm
link /dll /subsystem:windows dll.obj
is what i used
if there were any exported functions, you'd also want a DEF file and use...
Code: [Select]
link /dll /def:dll.def /subsystem:windows dll.obj
Bill Cravener has a nice little example
\masm32\examples\Bill_Cravener\mvolume

what program are you using to see the dependencies ?

x64Core

  • Member
  • **
  • Posts: 80
Re: Creating a DLL without Dependencies
« Reply #4 on: May 29, 2012, 03:11:33 PM »
Hello Dave  :biggrin:
thanks bro, yeah that's right!  :shock: I'm using CFF explorer, it's very good :P


is rare... only I deleted the invoke line of menssagebox, assemble, and look at the exe, then came back to write the line
and gave me this result  :icon_eek:

but now:



is created the export table :|
why?, I'm not export any function...



x64Core

  • Member
  • **
  • Posts: 80
Re: Creating a DLL without Dependencies
« Reply #5 on: May 29, 2012, 03:19:32 PM »
surely, it are  in the newer versions of MASM, because I do not have them :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4814
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Creating a DLL without Dependencies
« Reply #6 on: May 29, 2012, 03:21:25 PM »
RHL,

The reason why you are getting MSVCRT included is because it is contained in the MASM32RT include file. The way to avoid this is to include specific include file AFTER windows.inc.

Code: [Select]
Include \masm32\include\windows.inc  ; always first
Include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
etc etc ....
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Creating a DLL without Dependencies
« Reply #7 on: May 29, 2012, 03:27:06 PM »
i am afraid that Hutch and i are not on the same page, here - lol
i don't think any libs are imported unless a function is used

as for the export table...
i guess it assumes you are going to have an exported function
maybe if you create a DEF file that has no exports - only the DLL name

x64Core

  • Member
  • **
  • Posts: 80
Re: Creating a DLL without Dependencies
« Reply #8 on: May 29, 2012, 03:43:05 PM »
yeah, that's right  :icon_redface:
thanks a lot guys, really I appreciate your help

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4814
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Creating a DLL without Dependencies
« Reply #9 on: May 29, 2012, 05:08:33 PM »
This is the catch, if your DLL does not call the OS at all, then you have no imports but as soon as it does you need the import library for any API function that you call. You can try risky and unreliable methods but you live dangerously doing so.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Vortex

  • Member
  • *****
  • Posts: 1704
Re: Creating a DLL without Dependencies
« Reply #10 on: May 30, 2012, 03:55:56 AM »
Hi RHL,

Here is a quick example for you. The DLL in the attachment does not import any function. It exports only one function named StrLen.