Android反编译apk并重新打包签名(Mac环境)
Posted Zachary46
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android反编译apk并重新打包签名(Mac环境)相关的知识,希望对你有一定的参考价值。
工具下载
- apktool :https://ibotpeaches.github.io/Apktool/install
- dex2jar:https://github.com/pxb1988/dex2jar
- jd-gui:http://jd.benow.ca
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-472568f76dbaeeba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-6a916d157a26100d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-f764dff03566f2f8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-1848cd2bf1aa3949.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
这样环境就配好啦,打开终端,输入
apktool
命令,看到以下输出说明apktool配置成功![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-1dbaff995b1934e3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-1dadc1252d09d075.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
反编译
终端输入cd /Users/zachary/zachary/MyTest
进入到测试apk所在目录,输入apktool d test.apk
开始反编译
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-76ffa386bc0e0448.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-b135ba45ea1cfe60.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
下载完dex2jar和 jd-gui解压一下就可以了,复制到MyTest目录方便操作
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-51096231d3ab2c69.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
sh dex2jar-2.0/d2j-dex2jar.sh test.apk
(如果提示Permission Deny权限问题,先输入命令chmod +x dex2jar-2.0/d2j-dex2jar.sh
改一下权限就好了)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-cdcc251093a43600.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
运行结束,在MyTest目录会生成文件test-dex2jar.jar,就是我们需要的java代码压缩文件
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-1c0efc36f3060050.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
回编译
刚才我们执行apktool d test.apk
反编译得到了test目录
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-b54c48a020289f79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
apktool b test
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-72fd8c414f0cad5e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
成功之后,test目录下会生成build和dist目录
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-0e323421648aa96a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
build目录下存放的是打包后的dex文件和资源文件(和apk解压后一样一样的)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-03280b9c7f58d794.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
image.png
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-f89cf157691c609d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
重新签名
复制签名文件到dist目录下方便操作
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-4a00ef6fd99b80d0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
jarsigner -verbose -keystore [your_key_store_path] -signedjar [signed_apk_name] [usigned_apk_name] [your_key_store_alias] -digestalg SHA1 -sigalg MD5withRSA
字段说明:
- [your_key_store_path]:密钥所在位置的绝对路径
- [signed_apk_name]:签名后安装包名称
- [usigned_apk_name]:未签名的安装包名称
- [your_key_store_alias]:密钥的别名
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-ea94e5867a0f2fc3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-762f46f7ee6fd17b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
签完名后,在dist目录下就可以看到签完名后的apk了
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-b88f3bc31b190296.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
后话
反编译的时候,也可以把test.apk的拓展名改成test.zip解压出来
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-2522bb46273e4f07.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
把classes.dex复制到dex2jar-2.0路径下
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-668ed8be3f41cc07.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
./d2j-dex2jar.sh classes.dex
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-e75986e1d89310d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
同样可以得到classes-dex2jar.jar
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-26d8d1fe11135bb5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
反编译,再回编译,同样可以得到classes.dex,就在这个路径下
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-dace54b8597b60c8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
![技术分享图片](http://upload-images.jianshu.io/upload_images/6544996-831e2b5a9a8c61f9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/180)
收工.png
以上是关于Android反编译apk并重新打包签名(Mac环境)的主要内容,如果未能解决你的问题,请参考以下文章