美文网首页iOS逆向工程
iOS 使用openssl 生成静态包

iOS 使用openssl 生成静态包

作者: 居然是村长 | 来源:发表于2016-07-14 21:01 被阅读141次

搞了也有大半天,赶紧记录下,免得再坑。

下载源文件

注:建议使用tag里面较新的正常版本,我这里用的是 OpenSSL_1_0_2
https://github.com/openssl/openssl

  • 将下载文件放在了桌面,方便使用,前往文件夹
cd /Users/juyiwei/Desktop/openssl-OpenSSL_1_0_2 
  • 新建几个用于存放不同指令包的文件夹
mkdir openssl_arm64 openssl_armv7 openssl_armv7s openssl_i386

循环使用:

  • 配置文件夹
    注:选择一个,下面对应修改,只是指令不同
    注2:表示 i386的模拟器版本一直不成功,还指望会的同学教一下!
./configure BSD-generic32 --openssldir=/Users/juyiwei/Desktop/openssl-OpenSSL_1_0_2/openssl_arm64
./configure BSD-generic32 --openssldir=/Users/juyiwei/Desktop/openssl-OpenSSL_1_0_2/openssl_armv7
./configure BSD-generic32 --openssldir=/Users/juyiwei/Desktop/openssl-OpenSSL_1_0_2/openssl_armv7s
./configure BSD-generic32 --openssldir=/Users/juyiwei/Desktop/openssl-OpenSSL_1_0_2/openssl_i386

// 成功提示 make[1]: Nothing to be done for `generate'.
  • 修改编译使用的gcc:打开Makefile 文件
替换文件中的 CC=gcc:将 gcc 替换成 
/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch arm64
/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch armv7
/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch armv7s
/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch i386
注:是自己本地电脑的 gcc,并且附带指定指令集
  • 添加指定SDK
    CFLAG= (也就是 CC=的下一行) 在其末尾添加下面内容
    注:1_0_2是 -Wall
// 模拟器版本
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk

// 真机版本
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk 
  • 编译
make
// 编译成功会提示 make[1]: Nothing to be done for `all'.

make install
// 编译成功之后,在之前创建的 arm64 文件夹下生成完整的文件(lib中有2个.a文件,include中包含头文件)
// 建议将arm64 文件夹整体拖走

make clean
// 清空编译内容,在开始循环内容编译 armv7,armv7s,i386

生成了多套数据包,可以合并.a,导入工程使用

同时导入 openssl 头文件
Enable Bitcode ->NO
header Search -> $(inherited) $(PROJECT_DIR)/productName

相关文章

网友评论

本文标题:iOS 使用openssl 生成静态包

本文链接:https://www.haomeiwen.com/subject/xrmsjttx.html