从rtti剥离类名称 [英] Strip class name from rtti

查看:140
本文介绍了从rtti剥离类名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在写一些C ++程序,我不想要二进制泄漏信息关于程序如何工作。我知道我们可以从二进制条带符号,但类名仍然存储和可以通过RTTI信息检索。那么我该如何避免呢?

Suppose I am writing some C++ program that I don't want the binary leak information on how the program is working. I know we can probably strip symbols from the binary, but the class names are still stored and retrievable by RTTI information. So how can I avoid that? If I need to disable RTTI, what C++ features will no longer be usable?

推荐答案

禁用RTTI时会丢失什么取决于您的编译器(和编译器版本)。

What you lose when disable RTTI depends on your compiler (and compiler version).

对于gcc 4.5,您可以阅读:

For gcc 4.5, you could read:


-fno-rtti禁止使用虚拟函数生成每个类的信息,以供C ++运行时类型标识
特性(dynamic_cast'andtypeid')使用。如果你不使用
语言的那些部分,你可以使用这个标志保存一些空间。注意
异常处理使用相同的信息,但它会根据需要生成
。 `dynamic_cast'运算符仍然可以用于不需要运行时类型信息的转换
,即转换为void *或
到明确的基类。

-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:

For Visual Studio 2013:


如果编译器无法静态解析对象类型,请使用/ GR在
你的代码。当代码使用
dynamic_cast Operator或typeid时,通常需要/ GR选项。但是,/ GR会增加
的大小,你的图像的.rdata部分。如果你的代码不使用
dynamic_cast或typeid,/ GR-可能会产生一个较小的图像

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_cast typeid

Thus, indeed, in these cases, it disables only dynamic_cast and typeid.

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

However, if the goal is to hide the behavior and some information about your executable, I don't think that strip and disable RTTI are the best solution. It may be a good beginning, but to have a real binary protection, you must see packer / executable protector / obfuscation tool (http://en.wikipedia.org/wiki/Executable_compression).

这篇关于从rtti剥离类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆