天天看點

Mac檢視檔案内容常用的指令小結

前言

最近蘋果的熱更新和私有庫問題檢查的更嚴了,如果應用被拒,蘋果在拒絕信中會說到使用

strings

/

otool

nm

指令進行自查,是以總結了一些指令,友善查找和定位檔案内容相關資訊。

1、grep

  • 作用:判斷是否包含字元串
  • 使用示例:

    grep -r "xxx” path

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

Mac檢視檔案内容常用的指令小結

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 字元串的位元組序列
  • 檢查二進制是否含有關鍵詞的庫(比如檢查私有庫):
    Mac檢視檔案内容常用的指令小結
    strings a.out | grep hello.png
  • 更多使用說明

    man strings

3、otool

  • 作用: object file displaying tool. (針對目标檔案的展示工具,用來發現應用中使用到了哪些系統庫,調用了其中哪些方法,使用了庫中哪些對象及屬性)
  • otool -L path

    //檢視可執行程式都連結了那些庫

    otool -L path | grep "xxx"

    //篩選是否連結了xxx庫

    otool -D path

    //檢視支援的架構

    otool -ov path

    //output the Objective-C class structures and their defined methods.(輸出Object-C類結構以及定義的方法)
  • 檢視該應用是否砸殼:

    otool -l path | grep crypt

    //cryptid 0(砸殼) 1(未砸殼)
    Mac檢視檔案内容常用的指令小結
    otool -l path | grep crypt.png
  • 更多用法

    man otool

4、nm

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

    //得到Mach-O中的程式符号表

    nm -nm path

    //目标檔案的所有符号
    Mac檢視檔案内容常用的指令小結

    nm -nm path.png

    符号表中标示為 undefined,意思是目标檔案引用了類_XXX(XXX庫),不過這并沒有實作它。

  • man nm

5、file

  • 作用:determine file type. (判斷檔案類型)
  • file path

    判斷.a/framework是靜态庫還是動态庫:

    靜态庫:

    Mac檢視檔案内容常用的指令小結

    file path - static Lib.png

    動态庫:

    Mac檢視檔案内容常用的指令小結
    file path - dynamically Lib.png

6、lipo

  • 作用:create or operate on universal files(建立或處理通用檔案的工具)
  • lipo -info 'file path'

    // 判斷靜态庫所支援的平台 - i386 armv7 armv7s x86_64 arm64

    lipo -remove i386 origin_xxx.a -output op_xxx.a

    // 删除靜态庫包括的i386平台

    lipo -thin i386 origin_xxx.a -output op_xxx.a

    // 拆分靜态庫,隻保留i386 CPU架構

    lipo -create device_xxx.a simulator_xxx.a -output universal_xxx.a

    //對真機或者模拟器分别打出 .a 檔案合并

參考閱讀

注:本文首發于 iHTCboy's blog ,如若轉載,請注明來源。

繼續閱讀