iOS一点通

iOS开发中常用命令工具(xcode-select、lipo、x

2021-05-07  本文已影响0人  双鱼子曰1987

一、xcode-select

当安装多个xcode的版本,使用该工具使用指定的版本。

Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).

-p 或者 --print-path 查看当前开发者目录,也即是xcode的版本目录。print the path of the active developer directory
-s <path>--switch <path> 选择xcode的版本
--install 安装
--version 查看版本
--reset 恢复默认
sudo rm -rf /Library/Developer/CommandLineTools 强制删除安装目录下的文件

二、lipo命令

是管理Fat File的工具, 可以查看cpu架构, 提取特定架构,整合和拆分库文件。

三、otool命令(逆向命令)

Mac OS X下二进制可执行文件的动态链接库是dylib文件。所谓dylib,就是bsd风格的动态库。基本可以认为等价于windows的dll和linux的so。mac基于bsd,所以也使用的是dylib。

Linux下用ldd查看,苹果系统用otool

xxx_execFileName_xxx (architecture armv7):
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 904.4.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 321.1.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.2.0)
       @rpath/ArcSoftFaceEngine.framework/ArcSoftFaceEngine (compatibility version 1.0.0, current version 1.0.0)
        ....

xxx_execFileName_xxx丁 (architecture arm64):
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 904.4.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 321.1.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.2.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
//其中cryptid代表是否加壳,1代表加壳,0代表已脱壳。
    cryptoff 16384
    cryptsize 6651904
      cryptid 0
     cryptoff 16384
    cryptsize 6553600
      cryptid 0

otool命令介绍
MobSF
Mach-O 文件格式解析


三、xcodebuild 与 xcrun

xcodebuild:通过工程文件,生成app文件。
xcrun:通过app文件,来生成ipa文件(包含了签名的过程)。

3.1、xcodebuild

使用xcodebuild生成app的完成命令
xcodebuild -sdk  iphoneos8.1   -target test  -configuration Release  -arch arm64  -arch armv7  CODE_SIGN_IDENTITY="iPhone Distribution: xxxxxxx" clean build

其他

3.2、xcrun

通过app文件生成ipa文件

sudo xcrun -sdk iphoneos PackageApplication    -v build/Release-iphoneos/test.app  -o `pwd`/build/Release-iphoneos/test2.ipa --sign "iPhone Distribution: xxxxxxxxxx"

四、libtool

libtool是一个通用库支持脚本(/usr/bin/libtool),将使用动态库的复杂性隐藏在统一、可移植的接口中。

可以在不同平台上创建并调用动态库,我们可以认为libtool是gcc的一个抽象,也就是说,它包装了gcc或者其他的任何编译器,用户无需知道细节, 只要告诉libtool说我需要要编译哪些库即可,并且,它只与libtool文件打交道,例如lo、la为后缀的文件。
libtool工具的使用

五、ar命令

库是一单独的文件,里面包含了按照特定的结构组织起来的其它的一些文件(称做此库文件的member)。原始文件的内容、模式、时间戳、属主、组等属性都保留在库文件中。
详细命令参见,菜鸟网络-ar命令

应用

可以用来创建、修改库,也可以从库中提出单个模块。

ar: libAFNetworking.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: libAFNetworking.a: Inappropriate file type or format

lipo libAFNetworking.a -thin arm64 -output lib-arm64.a 生成Arm64包

ar -t lib-arm64.a 输出包含的.o文件 和 otool -L libAFNetworking.a 一样。

_.SYMDEF
AFAutoPurgingImageCache.o
AFHTTPSessionManager.o
AFImageDownloader.o
AFNetworkActivityIndicatorManager.o
AFNetworking-dummy.o
AFNetworkReachabilityManager.o
AFSecurityPolicy.o
AFURLRequestSerialization.o
AFURLResponseSerialization.o
AFURLSessionManager.o
UIActivityIndicatorView+AFNetworking.o
UIButton+AFNetworking.o
UIImageView+AFNetworking.o
UIProgressView+AFNetworking.o
UIRefreshControl+AFNetworking.o

ar -x lib-arm64.a 解压出包里面的.o文件

五、nm命令,俗称“纳米”

在iOS开发中,常常用来分析二进制和静态库文件。
列出.o .a .so中的符号信息,包括诸如符号的值,符号类型及符号名称等。所谓符号,通常指定义出的函数,全局变量等等。

nm应用:

iOS开发中,可以用来查看.a静态库所有打包进去的.o文件和函数接口信息,帮助我们定位崩溃信息。
例如:nm -u libAFNetworking.a 列出某个.o文件的接口信息。

3B96890C-0EDD-4CEA-A3B8-482268FF92B1.png

六、xxd 命令

二进制查看命令,将文件显示为16进制字符串表示形式。
例如:xxd libYTKNetwork.a | grep "net" 查看YTKNetwork.a文件里面包含net字符串的,帮助我们分析一些二进制文件。

8FCE6A3D-0D7F-4B84-B02B-7EB7DDF99CAA.png

七、dwarfdump 命令

DWARF文件初探——提取轻量符号表

八、class-dump

九、dumpdecrypted 砸壳命令


其他

参考

Mac系统下lipo, ar, nm等工具的使用简介
美团 iOS 工程 zsource 命令背后的那些事儿
Linux工具参考篇
iOS 静态库冲突 两个不同的.o 文件冲突 ,静态库分离

上一篇 下一篇

猜你喜欢

热点阅读