如何将数据嵌入到Mac OS X mach-o二进制文件的TEXT部分?

sch*_*hwa 11 macos linker mach-o

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

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

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

Ken*_*Ken 12

链接器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.
Run Code Online (Sandbox Code Playgroud)

GCC还有一个section属性,可以应用于变量,表示它属于非标准部分.