[fpc-pascal] Embedding DLL into EXE for Windows 32 bit?

Bo Berglund bo.berglund at gmail.com
Sat Jul 7 11:01:41 CEST 2018


On Sat, 07 Jul 2018 03:04:21 -0500, "Zoe Peterson"
<zoe at scootersoftware.com> wrote:

>> Since this maker does not have an OBJ file to link with I thought I
>> would ask if it is possible to embed the DLL functionality directly
>> into the exe?
>
>There are a few options:
>
>1) Include the DLL as a resource and extract it to a temp location 
>before loading it

I have seen these suggestions but the comments indicated that writing
a binary file to the filesystem on startup and then calling stuff
inside likely will trigger antivirus detection...
See: http://www.delphipages.com/forum/showthread.php?t=216147

What the pages I found suggest as a solution is to extract the DLL
from the resource to memory in the same place where it would be put
using LoadLibrary. Then it could be called as if loaded from disk but
the disk would not be touched.
Digging down this route makes me hesitant since it involves using a
number of rather big source files to handle the operations. Too big
and involved for me to understand...


>2) Load it directly from memory using a third party unit like this: 
>https://github.com/Fr0sT-Brutal/Delphi_MemoryModule

This I don't understand, it does not look like they have embedded the
dll into the application at all...

In the example both tests use the same code to load the dll from the
file system:
      ms := TMemoryStream.Create;
      ms.LoadFromFile(ParamStr(1));
(Paramstr(1) is the required DLL path)

I found another MemoryModule at GitHub named BTMemoryModule:
https://github.com/nedich/memorymodule
But it too looks rather involved, and is pretty old...

>3) Codesign the DLL and executable and verify that they haven't been 
>modified. There's code to do that on Stack Overflow, though it wasn't 
>tested on Lazarus: 
>https://stackoverflow.com/questions/5993877/checking-digital-
>signature-programmatically-from-delphi

Right, but this is just verification of the integrity of the file(s),
which of course could be a good thing. And I have no sources to the
DLL, just the working binary.

Conversion tool?
----------------
Is there some tool that can take a DLL as input and create an OBJ
file, which then can be linked into the application?
That would be the best solution at least for me.

I have found objconv: http://www.agner.org/optimize/#objconv
But it does not have an option to use a DLL as input file...
Maybe it is not possible to do such a conversion I am after?


-- 
Bo Berglund
Developer in Sweden




More information about the fpc-pascal mailing list