剥离符号的最佳方法
上周我发布了一个应用程序的 Linux 和 Windows 版本。
发布后,我们意识到符号没有被剥离,我的经理认为(我不同意)这可能会让用户理解我们的算法。
不管怎样,现在我必须清理符号并重新发布应用程序。
我的问题是,
- 在 Linux 中去除符号的最佳方法是什么?
- 在 Windows 中去除符号的最佳方法是什么?
Last week I released the Linux and windows version of an application.
And after the release we realized that the symbols were not stripped off, and my manager thinks (and I disagree) that it might allow the user to understand our algorithm.
Anyway, now, I will have to clean-up the symbols and re-release the application.
My question,
- What is the best way to strip symbols in Linux?
- What is the best way to strip symbols in Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 Windows 上的 Visual C++(和其他 Microsoft 编译器),符号不是二进制文件的一部分。相反,它们存储在称为“程序数据库”文件(.pdb 文件)的单独文件中。只是不提供 .pdb 文件。
使用 GNU 工具链,您可以使用
strip
从二进制文件中删除符号。With Visual C++ (and other Microsoft compilers) on Windows, symbols aren't part of the binaries. Instead, they are stored in separate files called "Program Database" files (.pdb files). Just don't provide the .pdb files.
With the GNU toolchain you would use
strip
to remove symbols from the binaries.对于 GNU 工具链,有一个很酷的技巧:
现在你可以压缩程序所在的文件夹(或将其打包到安装程序或其他任何东西中),其中将不再有调试符号。
但是:如果您启动调试器或运行诸如
addr2line
或obdump
之类的工具,该工具将(感谢调试链接信息)自动知道在哪里找到符号并加载它们。这太棒了,因为这意味着您可以享受拥有符号的好处,而无需将它们分发给用户。
For the GNU toolchain, there exists a cool sleight of hand:
Now you can zip the folder your program is in (or pack it into an installer or whatever), there will be no more debug symbols in it.
BUT : If you launch the debugger or if you run a tool like
addr2line
orobdump
, the tool will (thanks to the debuglink info) automagically know where to find the symbols and load them.Which is awesome, because it means you have the benefits of having symbols on your end, without distributing them to the user.
在 Windows 上,没有 PDB 的交付是不够的!
如果 DLL 中有与安全相关的函数,并且 DLL 是使用按名称导出的外部函数构建的,那么这些名称仍将在调用 EXE 的二进制文件中显示为文本字符串。
很容易看到这一点...只需使用“字符串”或任何十六进制编辑器并在 EXE 中搜索一些可能的字符串(如“许可证”等),然后它们就会出现。
在 EXE 上使用 Dependency Walker for Win64 这样的免费实用程序...即使没有 PDB 并且您正在调用的 DLL 无法找到... Dependency Walker 仍将构建一个表,其中包含 DLL 的所有导出函数的名称和序号。
因此,除了不带 PDB 进行交付(当然)之外,您还需要构建不带任何导出名称的 DLL。请参阅: 按序号而不是名称从 DLL 导出函数。基本上,您需要创建一个 .DEF 文件,该文件用于构建 EXE,但就像 PDB 一样,不会发布。还可以按照此处所述使用 NONAME: 使用 DEF 文件从 DLL 导出
完成后,请务必使用字符串等测试传送文件,以验证是否存在有用的符号文本。
===
PS 另请参阅这个旧答案:如何隐藏 DLL 中的导出函数< /a> 但请注意该答案中的旧链接已损坏,请在 2024 年使用此处的链接
On Windows, shipping without PDBs is not good enough!
If you have security-related functions in a DLL, and the DLL is built with externs exported by name, then those names will still appear as text strings inside the binary of the calling EXE.
Easy to see this... just use "strings" or any hex editor and search for some likely strings (like "license" etc) inside the EXE, and up they come.
Using a free utility like Dependency Walker for Win64 on the EXE... even when there are no PDBs and the DLL you are calling is nowhere to be found... Dependency Walker will still build a table with the names and ordinals for all the exported functions of the DLL.
So as well as shipping without PDBs (of course) you also need to build the DLL without any exported names. See: Exporting Functions from a DLL by Ordinal Rather Than by Name. Basically, you need to create a .DEF file which is used to build the EXE but just like the PDBs, does not get shipped. Also use NONAME as described here: Exporting from a DLL Using DEF Files
And once done, be sure to test the shipping files using strings etc to verify no helpful symbol text is present.
===
PS See also this older answer: How to hide the exporting functions in DLL but note the old links in that answer are broken, use links here in 2024