apktool反编译,重打包

来源:互联网 发布:mac添加微软雅黑字体 编辑:程序博客网 时间:2024/06/05 19:14

apktool 安卓逆向工程的工具,能解码apk文件到源文件,也能在做出修改后重新打包。

官方下载地址 https://ibotpeaches.github.io/Apktool/install/


apk其实跟一般的zip包差别不大,如果我们将apk包解压出来,我们也能看到源文件,但是如果打开文件比如:AndroidManifest.xml,并看不了



我们用apktool 反编译

$ apktool d testapp.apkI: Using Apktool 2.0.0 on testapp.apkI: Loading resource table...I: Decoding AndroidManifest.xml with resources...I: Loading resource table from file: 1.apkI: Regular manifest package...I: Decoding file-resources...I: Decoding values */* XMLs...I: Baksmaling classes.dex...I: Copying assets and libs...$


再打开AndroidManifest.xml就看得懂了

清单文件,资源文件,这些都能很方便得修改,比如改个logo,改个应用名啥的。还有一个重要的文件夹叫smali,里面都是反编译java文件后产生的代码,相当于JVM的class文件,介个有点汇编语言的感觉,但是简单了很多很多,所以要改代码执行的走向,还是得好好研究一下smali的语法。


解码命令:

$ apktool d foo.jar// decodes foo.jar to foo.jar.out folder$ apktool decode foo.jar// decodes foo.jar to foo.jar.out folder$ apktool d bar.apk// decodes bar.apk to bar folder$ apktool decode bar.apk// decodes bar.apk to bar folder$ apktool d bar.apk -o baz// decodes bar.apk to baz folder


构建命令:

$ apktool b foo.jar.out// builds foo.jar.out folder into foo.jar.out/dist/foo.jar file$ apktool build foo.jar.out// builds foo.jar.out folder into foo.jar.out/dist/foo.jar file$ apktool b bar// builds bar folder into bar/dist/bar.apk file$ apktool b .// builds current directory into ./dist$ apktool b bar -o new_bar.apk// builds bar folder into new_bar.apk$ apktool b bar.apk// WRONG: brut.androlib.AndrolibException: brut.directory.PathNotExist: apktool.yml// Must use folder, not apk/jar file

构建命令建议带上输出目录,否则可能会找不到构建出来的apk文件在哪儿。

然后,重新构建后的apk是没有签名的,安装不到手机上。我们需要使用apksigner来签名,apksigner在Android SDK Build Tools 24.0.3以上版本目录下会有,


签名命令如下:

apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk


完。