c++ - 从 rtti 中剥离类名

标签 c++ c++11

假设我正在编写一些 C++ 程序,但我不希望有关程序工作方式的二进制泄漏信息。我知道我们可能可以从二进制文件中删除符号,但类名仍然存储并可通过 RTTI 信息检索。那么我该如何避免呢?如果我需要禁用 RTTI,哪些 C++ 功能将不再可用?

最佳答案

禁用 RTTI 时的损失取决于您的编译器(和编译器版本)。

对于 gcc 4.5,您可以阅读:

-fno-rtti Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (dynamic_cast' andtypeid'). If you don't use those parts of the language, you can save some space by using this flag. Note that exception handling uses the same information, but it will generate it as needed. The `dynamic_cast' operator can still be used for casts that do not require runtime type information, i.e. casts to void * or to unambiguous base classes.

对于 Visual Studio 2013:

Use /GR if the compiler cannot statically resolve an object type in your code. You usually need the /GR option when your code uses dynamic_cast Operator or typeid. However, /GR increases the size of the .rdata sections of your image. If your code does not use dynamic_cast or typeid, /GR- may produce a smaller image

因此,实际上,在这些情况下,它仅禁用 dynamic_casttypeid

但是,如果目标是隐藏有关可执行文件的行为和一些信息,我认为 strip 和禁用 RTTI 不是最佳解决方案。这可能是一个好的开始,但要获得真正的二进制保护,您必须看到打包程序/可执行文件保护程序/混淆工具 (http://en.wikipedia.org/wiki/Executable_compression)。

关于c++ - 从 rtti 中剥离类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23304820/

相关文章:

c++ - 搜索哈里斯角时索贝尔尺度的意义

c++ - 分支预测是免费的吗?

c++ - 如何创建模板参数为 std::vector 时使用的此方法的模板版本

c++ - 为什么 std::array 临时 constexpr 的 operator[] 不是?

c++ - qt creator 项目更改目录

c++ - 糟糕的 3d 三角形渲染

c++ - Pcrecpp 比赛

c++ - 为什么可以通过使用指向对象成员的指针的 const 成员函数来修改对象状态?

c++ - 是否可以将模板专门用于语言链接?

c++ - Eigen::AutoDiff 的 Eigen::Spline 的错误模板参数