Remove C++ class names from binary dll file

懵懂的女人 提交于 2019-12-19 02:52:07

问题


I have a C++ project under Visual Studio 2010 which compiles into a dll. I have several private implementation-specific classes defined in my project, e.g. CMyClass. This class is not exported from the dll or by any interface function. However, when I check generated dll file, there is a string "CMyClass" stored in it. It is a release build, and I don't want this string to appear in the dll file. This dll is shipped to customers, and I want all names I used in my project to be stripped off the dll file, so nobody can get such a simple clue on what algorithms we use in our dll.

I use Release configuration. In project properties, the "Generate Debug Info" option under linker tab is turned off, the "Debug Information Format" under C/C++ tab is set to "Program Database (/Zi)". I tried to set empty string for "Debug Information Format" with no success.

The string found in the dll looks like .?AVCMyClass@@ and is located at the very end of the dll file. It is the only occurrence of the "CMyClass" string in the dll file. However, this string is presented for almost all my internal classes.

How to get rid of these mentions?

Update

Please note, I don't want to obfuscate the source code itself. The provided link is irrelevant. I just see no reason why class names are stored in the dll file. I can always rename my classes prior to build, but it is not very straight solution.

Update2

I don't agree with community on closing this qustion, since this is not a duplicate. And the answer is given in comments by Tyler Gill. Thanks to him and shame on others.


回答1:


As my guess from a comment appears correct, I'm reposting this as an answer.

The string of the class name is a result of having RTTI (Runtime Type Information) enabled for the compiled binaries. When RTTI is enabled, the compiler creates objects that store information about the types compiled into the binary, one of whose properties is the name of the type.

Note that some uses of dynamic_cast and typeid require RTTI, so disabling will cost you those features of C++.

In order to disable RTTI in Visual Studio, use the /GR- switch (see http://msdn.microsoft.com/en-us/library/we6hfdy0(v=vs.100).aspx, as Mikhail posted.)

To disable it in GCC, use the -fno-rtti switch.




回答2:


As Tyler Gill mentioned in the comments, this string was left by compiler due to RTTI since CMyClass actually inherits IMyClass and is polymorphic. My problem can be easily solved by disabling RTTI with /GR- switch. Thanks.



来源:https://stackoverflow.com/questions/14869639/remove-c-class-names-from-binary-dll-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!