简体   繁体   English

防止枚举类型数组的调试信息出现在 EXE 中

[英]Prevent debug information for array of enumerated type from appearing in EXE

I open up the Delphi IDE and create a new project.我打开 Delphi IDE 并创建一个新项目。 Here's the whole code for the application:这是应用程序的完整代码:

program EnumSymbolsInExeTest1;

type
  tMyEnum = ( A );

begin
end.

I build the application, and then search the EXE for " tMyEnum ".我构建了应用程序,然后在 EXE 中搜索“ tMyEnum ”。 It is found.找到了。 That's no surprise because I have Debug Information set ON in the Linker options.这并不奇怪,因为我在链接器选项中设置了调试信息。

I turn off Debug Information.我关闭调试信息。 I rebuild.我重建。 I search the EXE again and now there is no mention of tMyEnum .我再次搜索 EXE,现在没有提到tMyEnum So far everything is as expected.到目前为止,一切都如预期的那样。

Then I change the code.然后我更改代码。 I add a variable.我添加了一个变量。

program EnumSymbolsInExeTest1;

type
  tMyEnum = ( A );

var
  Z : tMyEnum;

begin
end.

I rebuild.我重建。 Still no surprises.仍然没有惊喜。 I get a hint for an un-used variable, and the EXE still has no mention of TMyEnum .我得到一个未使用变量的提示,但 EXE 仍然没有提到TMyEnum

Then I make another small change:然后我再做一个小改动:

type
  tMyEnum = ( A );

var
  Z : array of tMyEnum;

begin
end.

I change the variable to an array.我将变量更改为数组。 I rebuild.我重建。 I search the EXE and find that " tMyEnum " now appears in the EXE file.我搜索了 EXE,发现“ tMyEnum ”现在出现在 EXE 文件中。

My questions are: Why?我的问题是:为什么?

And how can I stop it?我怎样才能阻止它? I don't want any of my internal identifiers to appear in the executable file I send to my customers.我不希望我的任何内部标识符出现在我发送给客户的可执行文件中。

I am using Delphi 10.2我正在使用 Delphi 10.2

In response to David Heffernan, I've added these compiler directives.为了回应 David Heffernan,我添加了这些编译器指令。

program EnumSymbolsInExeTest1;

{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}

type
  tMyEnum = ( A );

var
  Z : array of tMyEnum;

begin
end.

My EXE still contains "tMyEnum".我的 EXE 仍然包含“tMyEnum”。

I have a new clue!我有新线索! I changed the array from dynamic to static.我将数组从动态更改为静态。

program EnumSymbolsInExeTest1;

type
  tMyEnum = ( A );

var
  Z : array [1..10] of tMyEnum;

begin
end.

Now the identifier no longer appears in the EXE.现在标识符不再出现在 EXE 中。

So the declaration of the type does not trigger it, adding a variable of that type does not trigger it, adding a static array does not trigger it, but making it a dynamic array does.因此类型的声明不会触发它,添加该类型的变量不会触发它,添加静态数组不会触发它,但使其成为动态数组会。

I'm going to say it's not possible.我会说这是不可能的。


Conclusion from direct experimental observation直接实验观察的结论

Try turning off every option that we can find:尝试关闭我们可以找到的所有选项:

Compiling编译

  • Code inlining control: Off代码内联控制:关闭
  • Emit runtime type information: false发出运行时类型信息:false
  • Optimization: true优化:真
  • Assertions: false断言:错误
  • Debug information: No debug information调试信息:无调试信息
  • Local symbols: false局部符号:false
  • Symbol reference info: None符号参考信息:无
  • Use debug .dcus: false使用调试 .dcus: false
  • Use imported data references: false使用导入的数据引用: false
  • I/O Checking: false I/O 检查: false
  • Overflow checking: false溢出检查:false
  • Range checking: false范围检查:false
  • Assignable typed constants: false可赋值的类型常量:false
  • Complete boolean evaluation: false完整的布尔评估:false
  • Extended syntax: false扩展语法: false
  • Long strings by default: false默认长字符串: false
  • Open parameters: false打开参数: false
  • Strict var-strings: false严格的 var 字符串: false
  • Typed @ operator: false输入@运算符:false

Linking链接

  • Debug information: false调试信息:false
  • Include remote debug symbols: false包括远程调试符号:false
  • Map file: Off地图文件:关闭
  • Output resource string .drc file: false输出资源字符串 .drc 文件:false

And the symbol still appears in the .text section of the final PE module.并且该符号仍然出现在最终 PE 模块的.text部分中。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM