Disable C ++ Builder to export unit names?

Whenever I create Win32 EXE in release mode with C ++ Builder (version XE4, but previous versions do it as well), it always creates an export directory and exports an Initialize / Finalize entry for each module in my project. This leads to thousands of unnecessary exports. A similar problem occurs with Win64 assemblies, but the generated export is not so much.

A quick check with the dumpbin tool gives the following (abbreviated) output:

Section contains the following exports for PROJECTX.exe 00000000 characteristics 0 time date stamp Thu Jan 01 00:00:00 1970 0.00 version 1 ordinal base 1205 number of functions 1205 number of names ordinal hint RVA name 1046 0 003ECF44 @ $xp$13Gdipapi@INT16 1077 1 003ED64C @ $xp$13Gdipapi@PARGB 1053 2 003ED0D4 @ $xp$13Gdipapi@Unit _ 1047 3 003ECF5C @ $xp$14Gdipapi@UINT16 1049 4 003ECF88 @ $xp$14Gdipapi@UINT32 ... 261 E0 000BD758 @@ Find@Finalize 260 E1 000BD748 @@ Find@Initialize 153 E2 0007EE70 @@ Flags@Finalize 152 E3 0007EE60 @@ Flags@Initialize ... 

My problem is that in addition to adding the PE file size and load time, these export entries provide metadata that can help reverse engineer my binary, and therefore I would like to exclude them.

The hacker solution is to manually delete the export directory for PE images after creating it, however, you need a solution for this from the IDE / C ++ compiler.

Why does C ++ Builder do this and how can I disable the creation of these entries in the export directory?

Update: Building an empty VCL Forms application in Win32 release mode creates the following export data by default ...

  Section contains the following exports for Project1.exe 00000000 characteristics 0 time date stamp Thu Jan 01 00:00:00 1970 0.00 version 1 ordinal base 5 number of functions 5 number of names ordinal hint RVA name 3 0 000036C8 @@ Unit1@Finalize 2 1 000036B8 @@ Unit1@Initialize 5 2 00006974 _Form1 1 3 00001F59 __GetExceptDLLinfo 4 4 000060AC ___CPPdebugHook 
+4
source share
1 answer

If you delete automatically generated

 #pragma package(smart_init) 

at the top of your .cpp file, then C ++ Builder will not export methods per Initialize and Finalize unit.

I think #pragma package(smart_init) only needed if you plan to place your .cpp files in a package (and not directly in exe). Therefore, I find it safe to delete in your case, docwiki has more detailed information.

With that said, I don't think it's worth worrying about:

  • If you have not determined that they have a noticeable effect on your file size and / or download time, there are more important things to worry about. ("Premature optimization is the root of all evil", "always measure performance" before optimization, etc.).
  • The design of Delphi and C ++ Builder already consoles a lot of information for reverse engineering. Delphi RTTI means that any __ published properties are embedded in the executable file, and there are utilities for extracting DFM from executable files. Unit name leaks from exported Initialize and Finalize methods are relatively minor compared to this.
  • Reverse engineering is probably not as big as programmers often do; The consensus is that (a) a sufficiently motivated and experienced hacker can redesign everything he wants, and (b) your knowledge and knowledge of your company, customer relationships and support cost much more than any algorithms in your code.
+7
source

Source: https://habr.com/ru/post/1481181/


All Articles