Mac查看文件內(nèi)容常用的命令小結(jié)

前言

最近蘋果的熱更新和私有庫問題檢查的更嚴(yán)了,如果應(yīng)用被拒,蘋果在拒絕信中會說到使用strings/otool/nm命令進(jìn)行自查,所以總結(jié)了一些命令,方便查找和定位文件內(nèi)容相關(guān)信息。

1、grep

  • 作用:判斷是否包含字符串

  • 使用示例:

    grep -r "xxx” path

檢查是否包含(weixin)字符串:

grep -r "xxx” path.png

matches 表示包含。

2、strings

  • 作用:find the printable strings in a object, or other binary, file

  • 使用示例:

    strings a.out | grep hello //檢查 a.out 文件中含有 hello 字符串的字節(jié)序列

  • 檢查二進(jìn)制是否含有關(guān)鍵詞的庫(比如檢查私有庫):


    strings a.out | grep hello.png
  • 更多使用說明 man strings

3、otool

  • 作用: object file displaying tool. (針對目標(biāo)文件的展示工具,用來發(fā)現(xiàn)應(yīng)用中使用到了哪些系統(tǒng)庫,調(diào)用了其中哪些方法,使用了庫中哪些對象及屬性)

  • 使用示例:
    otool -L path //查看可執(zhí)行程序都鏈接了那些庫

    otool -L path | grep "xxx" //篩選是否鏈接了xxx庫

    otool -D path //查看支持的架構(gòu)

    otool -ov path //output the Objective-C class structures and their defined methods.(輸出Object-C類結(jié)構(gòu)以及定義的方法)

  • 查看該應(yīng)用是否砸殼:
    otool -l path | grep crypt //cryptid 0(砸殼) 1(未砸殼)

    otool -l path | grep crypt.png

  • 更多用法 man otool

4、nm

  • 作用:display name list (symbol table). (顯示符號表)

  • 使用示例:
    nm path //得到Mach-O中的程序符號表

    nm -nm path//目標(biāo)文件的所有符號

    nm -nm path.png

    符號表中標(biāo)示為 undefined,意思是目標(biāo)文件引用了類_XXX(XXX庫),不過這并沒有實(shí)現(xiàn)它。

  • 更多用法 man nm

5、file

  • 作用:determine file type. (判斷文件類型)

  • 使用示例:
    file path

    判斷.a/framework是靜態(tài)庫還是動態(tài)庫:
    靜態(tài)庫:


    file path - static Lib.png

    動態(tài)庫:


    file path - dynamically Lib.png

6、lipo

  • 作用:create or operate on universal files(創(chuàng)建或處理通用文件的工具)

  • 使用示例:
    lipo -info 'file path' // 判斷靜態(tài)庫所支持的平臺 - i386 armv7 armv7s x86_64 arm64

    lipo -remove i386 origin_xxx.a -output op_xxx.a // 刪除靜態(tài)庫包括的i386平臺

    lipo -thin i386 origin_xxx.a -output op_xxx.a // 拆分靜態(tài)庫,只保留i386 CPU架構(gòu)

    lipo -create device_xxx.a simulator_xxx.a -output universal_xxx.a //對真機(jī)或者模擬器分別打出 .a 文件合并

參考閱讀


注:本文首發(fā)于 iHTCboy's blog,如若轉(zhuǎn)載,請注明來源。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容