一、反编译
使用工具:apktool
apktool 下载地址及安装教程:
Apktool - How to Install
步骤:
1、打开命令行(CMD) ,输入
java-jar apktool.jar d test.apk -o test
注1:因为我这边不需要使用到res文件,所以使用命令:apktool -r d xxx.apk -o 输出路径
注2:
然后我们能获取到这样的一个目录:
另:反编译的话直接解压Apk,然后用jadx打开dex文件就可以了(未加固的APK,加固后的表示不清楚咋脱壳)
二、修改代码
因为我这边的需求,需要修改一下APP里面的一个简单的跳转功能,首先,我们先用当前Activity找到跳转前的activity。然后通过jadx找出该activity在哪个解压出来的smail文件夹里面。根据代码里面的部分关键字定位到是StartActivity$2.smali后,使用Notepad++修改完代码。。具体的就不写了,第一次弄,也是摸索着改的。不过成功了。。
三、回编译
回到CMD,输入:apktool b D:\workspace\test(文件夹路径)
回编译成功,回编译后的APK目录为D:\workspace\test\dist 目录dist为自动生成的文件
这时候如果直接装进手机的话,会出现:解析包错误。出现这个问题的时候就是因为该APP未签名
签名步骤:
jarsigner -verbose -keystore test.jks -signedjar signtest.apk test.apk demo
1)jarsigner是工具名称,-verbose表示将签名过程中的详细信息打印出来,显示在dos窗口中;
2)-keystore test.jks 表示签名所使用的数字证书所在位置,这里没有写路径,表示在当前目录下;
3)-signedjar signtest.apk test.apk 表示给test.apk文件签名,签名后的文件名称为signtest.apk;
4)最后面的demo表示证书的别名,对应于生成数字证书时-alias参数后面的名称,详情见下图:
(中文没显示出来,中间那个中文是请输入签名秘钥的密码的了。)
签名成功后,Apk去到了C盘user目录下,别问我咋找到的,我用everything全局搜索才翻回出来,想重新签名一次就提示
压根不知道是啥意思。。
重新签名完就可以愉快的装进手机了。。
四、回编译时遇到的一些坑。。
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\ufly_a6\AppData\Local\Temp\brut_util_Jar_2796158853984888863.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 28, --version-code, 1, --version-name, 1.0.4, --no-version-vectors, -F, C:\Users\ufly_a6\AppData\Local\Temp\APKTOOL2784034858670977982.tmp, -0, arsc, -0, META-INF/android.arch.core_runtime.version, -0, META-INF/android.arch.lifecycle_extensions.version, -0, META-INF/android.arch.lifecycle_livedata-core.version, -0, META-INF/android.arch.lifecycle_livedata.version, -0, META-INF/android.arch.lifecycle_runtime.version, -0, META-INF/android.arch.lifecycle_viewmodel.version, -0, META-INF/androidx.appcompat_appcompat.version, -0, META-INF/androidx.asynclayoutinflater_asynclayoutinflater.version, -0, META-INF/androidx.cardview_cardview.version, -0, META-INF/androidx.coordinatorlayout_coordinatorlayout.version, -0, META-INF/androidx.core_core.version, -0, META-INF/androidx.cursoradapter_cursoradapter.version, -0, META-INF/androidx.customview_customview.version, -0, META-INF/androidx.documentfile_documentfile.version, -0, META-INF/androidx.drawerlayout_drawerlayout.version, -0, META-INF/androidx.fragment_fragment.version, -0, META-INF/androidx.interpolator_interpolator.version, -0, META-INF/androidx.legacy_legacy-support-core-ui.version, -0, META-INF/androidx.legacy_legacy-support-core-utils.version, -0, META-INF/androidx.legacy_legacy-support-v4.version, -0, META-INF/androidx.loader_loader.version, -0, META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version, -0, META-INF/androidx.media_media.version, -0, META-INF/androidx.print_print.version, -0, META-INF/androidx.recyclerview_recyclerview.version, -0, META-INF/androidx.slidingpanelayout_slidingpanelayout.version, -0, META-INF/androidx.swiperefreshlayout_swiperefreshlayout.version, -0, META-INF/androidx.vectordrawable_vectordrawable-animated.version, -0, META-INF/androidx.vectordrawable_vectordrawable.version, -0, META-INF/androidx.versionedparcelable_versionedparcelable.version, -0, META-INF/androidx.viewpager_viewpager.version, -0, data, -0, assets/flysafe/dji.nfzdb.confumix, -0, assets/flysafe/dji.nfzdb.sig, -0, db, -0, h264, -0, properties, -0, arsc, -I, C:\Users\ufly_a6\AppData\Local\apktool\framework\1.apk, -S, D:\workspace\SomeDemo\xxx\res, -M, D:\workspace\SomeDemo\xxx\AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:496)
at brut.androlib.Androlib.buildResources(Androlib.java:430)
at brut.androlib.Androlib.build(Androlib.java:329)
at brut.androlib.Androlib.build(Androlib.java:267)
at brut.apktool.Main.cmdBuild(Main.java:230)
at brut.apktool.Main.main(Main.java:83)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\ufly_a6\AppData\Local\Temp\brut_util_Jar_2796158853984888863.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 28, --version-code, 1, --version-name, 1.0.4, --no-version-vectors, -F, C:\Users\ufly_a6\AppData\Local\Temp\APKTOOL2784034858670977982.tmp, -0, arsc, -0, META-INF/android.arch.core_runtime.version, -0, META-INF/android.arch.lifecycle_extensions.version, -0, META-INF/android.arch.lifecycle_livedata-core.version, -0, META-INF/android.arch.lifecycle_livedata.version, -0, META-INF/android.arch.lifecycle_runtime.version, -0, META-INF/android.arch.lifecycle_viewmodel.version, -0, META-INF/androidx.appcompat_appcompat.version, -0, META-INF/androidx.asynclayoutinflater_asynclayoutinflater.version, -0, META-INF/androidx.cardview_cardview.version, -0, META-INF/androidx.coordinatorlayout_coordinatorlayout.version, -0, META-INF/androidx.core_core.version, -0, META-INF/androidx.cursoradapter_cursoradapter.version, -0, META-INF/androidx.customview_customview.version, -0, META-INF/androidx.documentfile_documentfile.version, -0, META-INF/androidx.drawerlayout_drawerlayout.version, -0, META-INF/androidx.fragment_fragment.version, -0, META-INF/androidx.interpolator_interpolator.version, -0, META-INF/androidx.legacy_legacy-support-core-ui.version, -0, META-INF/androidx.legacy_legacy-support-core-utils.version, -0, META-INF/androidx.legacy_legacy-support-v4.version, -0, META-INF/androidx.loader_loader.version, -0, META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version, -0, META-INF/androidx.media_media.version, -0, META-INF/androidx.print_print.version, -0, META-INF/androidx.recyclerview_recyclerview.version, -0, META-INF/androidx.slidingpanelayout_slidingpanelayout.version, -0, META-INF/androidx.swiperefreshlayout_swiperefreshlayout.version, -0, META-INF/androidx.vectordrawable_vectordrawable-animated.version, -0, META-INF/androidx.vectordrawable_vectordrawable.version, -0, META-INF/androidx.versionedparcelable_versionedparcelable.version, -0, META-INF/androidx.viewpager_viewpager.version, -0, data, -0, assets/flysafe/dji.nfzdb.confumix, -0, assets/flysafe/dji.nfzdb.sig, -0, db, -0, h264, -0, properties, -0, arsc, -I, C:\Users\ufly_a6\AppData\Local\apktool\framework\1.apk, -S, D:\workspace\SomeDemo\xxx\res, -M, D:\workspace\SomeDemo\xxx\AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:441)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:482)
... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\ufly_a6\AppData\Local\Temp\brut_util_Jar_2796158853984888863.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 28, --version-code, 1, --version-name, 1.0.4, --no-version-vectors, -F, C:\Users\ufly_a6\AppData\Local\Temp\APKTOOL2784034858670977982.tmp, -0, arsc, -0, META-INF/android.arch.core_runtime.version, -0, META-INF/android.arch.lifecycle_extensions.version, -0, META-INF/android.arch.lifecycle_livedata-core.version, -0, META-INF/android.arch.lifecycle_livedata.version, -0, META-INF/android.arch.lifecycle_runtime.version, -0, META-INF/android.arch.lifecycle_viewmodel.version, -0, META-INF/androidx.appcompat_appcompat.version, -0, META-INF/androidx.asynclayoutinflater_asynclayoutinflater.version, -0, META-INF/androidx.cardview_cardview.version, -0, META-INF/androidx.coordinatorlayout_coordinatorlayout.version, -0, META-INF/androidx.core_core.version, -0, META-INF/androidx.cursoradapter_cursoradapter.version, -0, META-INF/androidx.customview_customview.version, -0, META-INF/androidx.documentfile_documentfile.version, -0, META-INF/androidx.drawerlayout_drawerlayout.version, -0, META-INF/androidx.fragment_fragment.version, -0, META-INF/androidx.interpolator_interpolator.version, -0, META-INF/androidx.legacy_legacy-support-core-ui.version, -0, META-INF/androidx.legacy_legacy-support-core-utils.version, -0, META-INF/androidx.legacy_legacy-support-v4.version, -0, META-INF/androidx.loader_loader.version, -0, META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version, -0, META-INF/androidx.media_media.version, -0, META-INF/androidx.print_print.version, -0, META-INF/androidx.recyclerview_recyclerview.version, -0, META-INF/androidx.slidingpanelayout_slidingpanelayout.version, -0, META-INF/androidx.swiperefreshlayout_swiperefreshlayout.version, -0, META-INF/androidx.vectordrawable_vectordrawable-animated.version, -0, META-INF/androidx.vectordrawable_vectordrawable.version, -0, META-INF/androidx.versionedparcelable_versionedparcelable.version, -0, META-INF/androidx.viewpager_viewpager.version, -0, data, -0, assets/flysafe/dji.nfzdb.confumix, -0, assets/flysafe/dji.nfzdb.sig, -0, db, -0, h264, -0, properties, -0, arsc, -I, C:\Users\ufly_a6\AppData\Local\apktool\framework\1.apk, -S, D:\workspace\SomeDemo\xxx\res, -M, D:\workspace\SomeDemo\xxx\AndroidManifest.xml]
at brut.util.OS.exec(OS.java:95)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:435)
... 6 more
弄了很久都没办法解决,然后网上翻资料的提示说换一个Apktools ,然后不解析res文件,后来接着做就没再出现这个问题了