开发者

How do I embed data into a Mac OS X mach-o binary file's TEXT Section?

开发者 https://www.devze.com 2022-12-08 22:48 出处:网络
I have a Mac OS X command-line tool that would benefit from having some data embedded in the binary file itself.

I have a Mac OS X command-line tool that would benefit from having some data embedded in the binary file itself.

I know mach-o files support multiple segments, some of which can be used for storing arbitrary data. But I can't find a command-line tool to do that.

While I know there are other, probably simpler ways (e.g. convert the data file into C source code and have it get linked in by gcc) to get the data into my bina开发者_运维百科ry this problem has piqued my interest. Anyone know the magic?


The linker, ld, takes an argument -sectcreate.

From the man page,

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

GCC also has a section attribute that can be applied to a variable to say that it belongs in a non-standard section.

0

精彩评论

暂无评论...
验证码 换一张
取 消