Recent

Author Topic: Library name in PE executable exports directory  (Read 542 times)

440bx

  • Sr. Member
  • ****
  • Posts: 382
Library name in PE executable exports directory
« on: July 12, 2018, 06:36:36 am »
Hello,

Though rare, an executable can export functions and/or data.  Borland/Embarcadero executables are known for that. 

When FPC finds an "exports" clause, it adds ".dll" to the executable's name, resulting in a mismatch between the name of the executable and the library name in the PE file's export directory.  This can cause problems.

For instance, if you have a program named "myprogram" which results in an executable named "myprogram.exe" and, it exports one or more of its functions, the library name in the exports directory will be "myprogram.dll" instead of what it should be: "myprogram.exe"  (without quotes, of course.)

If FPC is explicitly told the extension to use using the {$EXTENSION 'exe'} directive, then the library name ends up being "myprogram.exe.dll".  No matter what, it insists on appending a ".dll".    A mismatch in the library name and the actual filename can cause problems when using GetProcAddress to retrieve the addresses of the exported functions/data.

It shouldn't blindly append ".dll" to the name and, if an extension is specifically stated then it should definitely respect that.

Fortunately, the number of people affected will be few and far between but still, the library/executable name should be set correctly.

As Borland figured out long ago, exporting a few key items from an executable can be invaluable for a debugger that knows what to do with those imported "items".

« Last Edit: July 12, 2018, 06:38:50 am by 440bx »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6614
Re: Library name in PE executable exports directory
« Reply #1 on: July 12, 2018, 10:55:14 am »
Please file a bug.

440bx

  • Sr. Member
  • ****
  • Posts: 382
Re: Library name in PE executable exports directory
« Reply #2 on: July 12, 2018, 11:32:54 am »