Tool Introduction
apktool , compile and decompile apk, extract images and layout resources from apk
dex2jar , decompile the executable file classes.dex into a jar source file
jd-gui , view the jar source file
decompile
apktool install
Windows system:
1. First make sure that the system has Java installed
2. Download the apktool.bat script
3. Download the latest version of apktool.jar and rename it to apktool.jar
4. Put apktool.bat and apktool.jar in the same directory, and then they can be used in the command line window.
5. For other systems, please refer to the link
usage
You can directly execute apktool.bat on the command line to view the help. Here are the two most commonly used ones:
decompile
apktool.bat d [-s] -f <apkPath> -o <folderPath>
![](https://img-blog.csdnimg.cn/img_convert/29d4fb073b384a2c9ae65bcb4d38e0e2.png)
![](https://img-blog.csdnimg.cn/img_convert/e66922109af1401d866e1418fa096ae3.webp?x-oss-process=image/format,png)
Note: If you do not select the folder path and enter directly: apktool.bat d -f 1.apk -o 1 will be generated in the system directory C:\Users\Administrator by default;
1. Two other tools are needed here, download dex2jar and decompress it. Download jd-gui , an application with UI.
2. Change the suffix of the apk that needs to be decompiled to .zip or .rar, and then decompress it to a folder to get the classes.dex file in it.
![](https://img-blog.csdnimg.cn/img_convert/3b9b3d7ac0ad447d80f314620edcbda9.png)
3. Copy classes.dex to the decompressed dex2jar-2.0 folder. Enter the directory from the command line, execute
d2j-dex2jar.bat classes.dex
会生成由classes.dex反编译得到的jar文件,classes-dex2jar.jar。
![](https://img-blog.csdnimg.cn/img_convert/d2d929de47544704ae5892264cc29073.png)
四. 然后使用jd-gui打开classes-dex2jar.jar,就可以查看源码了。
![](https://img-blog.csdnimg.cn/img_convert/9884a8c279eb42fda784244f50258dff.png)
如果apk在发布的时候加过混淆处理,那么我们也只能得到混淆后的版本。想通过阅读源码来破解别人的apk,难度较大,不过有兴趣可以网上去研究。
修改代码
如果只修改apk相应的资源,那么只要在res文件夹下找到相应的文件替换。
修改代码比较麻烦,因为反编译出来的结果中只有smali文件,即Java虚拟机支持的汇编语言。
如果确实需要修改代码,就得对照smali文件和从classes.dex反编译出来的源码了,按照smali的规范来改动即可。相当于写汇编,难度较大。
五.签名apk文件:
(如何查看签名信息:将签名后的apk文件后缀名改为zip,然后将里面的META-INF文件夹解压出来:输入命令:keytool -printcert –file <签名文件RSA的路径>)
![](https://img-blog.csdnimg.cn/img_convert/c11d07077ff24ceab35f39bd0ed100cd.png)
签名文件需要用到keytool.exe和jarsigner.exe,这两个文件都在Java jdk的bin目录下:
1,打开命令行输入以下命令然后回车:
keytool -genkey -alias key.keystore -keyalg RSA -validity 30000 -keystore key.keystore
-genkey 产生证书文件
-alias 产生别名
-keystore 指定密钥库的.keystore文件中
-keyalg 指定密钥的算法,这里指定为RSA(非对称密钥算法)
-validity 为证书有效天数,这里我们写的是30000天
出现如下图所示随便照着填填
![](https://img-blog.csdnimg.cn/img_convert/86877a608ec6459dbdbc65899da4f5bd.webp?x-oss-process=image/format,png)
2,生成出来的keystore要与apk在同一目录下(一般都默认在系统目录没有修改路径的话C:\Users\Administrator)
命令行再输入以下命令然后回车:
jarsigner -verbose -keystore key.keystore -signedjar xxx-signed.apk xxx-unsigned.apk key.keystore
![](https://img-blog.csdnimg.cn/img_convert/f74d5b8364a749aa9e16951e64c6224c.png)
xxx-signed.apk 指签名后的apk文件名
xxx-unsigned.apk 原来的apk文件名
-verbose 指定生成详细输出
-keystore 指定数字证书存储路径
这样,就完成了对一个apk的签名过程,然后就可以安装使用了。注意如果你的手机上原来就有这个apk,需先卸载,不然无法安装。