我有一个Mac OS X命令行工具,可以从二进制文件本身嵌入一些数据中受益。

我知道mach-o文件支持多个段,其中一些段可用于存储任意数据。但我找不到一个命令行工具来做到这一点。

虽然我知道还有其他的,可能更简单的方法(例如将数据文件转换为C源代码并通过gcc链接)以将数据输入到我的二进制文件中,这个问题引起了我的兴趣。有人知道这个魔法吗?

有帮助吗?

解决方案

链接器ld采用参数-sectcreate。

从手册页

 -sectcreate segname sectname file
             The section sectname in the segment segname is created from
             the contents of file file. The combination of segname and 
             sectname must be unique  there cannot already be a 
             section (segname,sectname) from any other input.

海湾合作委员会还有 section 属性,可以应用于变量,表示它属于非标准部分。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top