APK反編譯分析的時候,不免須要對APK進行重打包來輔助反編譯的分析。好比經過重打包給APK添加可調試功能或者添加可抓https包的功能,都須要應用到重打包的技術。android
// 清除framwork,避免framwork過時,拉取最新的framwork資源
apktool empty-framework-dir --force
// 開始反編譯
apktool d -f org.fedorahosted.freeotp.apk
複製代碼
以反編譯的包支持debug和支持charles https抓包爲例git
(1)修改manifestgithub
<application
// 支持debug
android:debuggable="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
// 支持https抓包
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
複製代碼
(2)在res目錄下新建xml文件夾,新建network_security_config.xmlbash
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
複製代碼
(1)apktool編譯:編譯修改後的代碼生成新的apkapp
apktool b org.fedorahosted.freeotp -o new.apk
複製代碼
(3)zipalign對齊:將新生成的apk對齊ide
zipalign -f -v -p 4 new.apk new_zip_align.apk
複製代碼
(4)apksigner簽名:只有簽名後的apk才能夠安裝post
apksigner sign --ks /Users/weishenhong/Desktop/wsh/code/android/android_learning/app/keystore --ks-key-alias key0 --ks-pass pass:112112 --out rebuild_signed.apk new_zip_align.apk
複製代碼
(5)安裝apkui
adb install -r -t rebuild_signed.apk
複製代碼
至此,你重打包的apk就成功安裝了。spa