2009-10-22 16 views
11

我有一個Mac OS X命令行工具,可以從二進制文件本身嵌入一些數據中受益。如何將數據嵌入到Mac OS X機器二進制文件的TEXT部分?

我知道mach-o文件支持多段,其中一些可用於存儲任意數據。但我找不到一個命令行工具來做到這一點。雖然我知道還有其他可能更簡單的方法(例如,將數據文件轉換爲C源代碼並通過gcc鏈接),以將數據導入到我的二進制文件中,但這個問題引起了我的興趣。任何人都知道魔法?

回答

12

鏈接器ld接受一個參數-sectcreate。

從man頁面,

-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還具有可應用於可變地說,它屬於非標準部分中的section屬性。

+0

Doh。回想起來很明顯。謝謝。 – schwa

相關問題