一、apk反编译
参考https://ibotpeaches.github.io/Apktool/
应用反编译执行命令:
$ apktool d test.apk
I: Using Apktool 2.2.2 on test.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: 1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
加-o 参数可以指定反编译后的文件夹名称
二、apk重新打包
一般,重新打包之前,对apk反编译后的smali语言进行了修改。
应用重新打包命令:
$ apktool b test
I: Using Apktool 2.2.2 on test
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
I: Copying unknown files/dir...
添加-o参数,可以指定输出的apk名称
三、签名
预备条件:有个密钥库文件。
密钥库文件生成的方法:
keytool -genkey -alias test.keystore -keyalg RSA -validity 20000 -keystore test.keystore
其中,-genkey表示生成密钥,-alias表示密钥别名,-keyalg表示密钥的算法,-validity表示有效期,-keystor表示生成文件的名字
之后会提示输入相应的信息,输入后按Y确认即可。
若最后提示keytool 错误: java.io.FileNotFoundException: android.keystore (拒绝访问。)
是因为-keystore test.keystore指定的路径(即Java路径)是不能写的,需要指定到其他地方,如-keystore d:\test.keystore,将文件保存在d盘。
使用test.keystore签名:
jarsigner -verbose -keystore test.keystore -signedjar testapk_signed.apk testapk.apk test.keystore
其中,
-verbose表示显示出签名详细信息
-keystore表示使用当前目录中的test.keystore签名证书文件。
-signedjar testapk_signed.apk表示签名后生成的APK名称
testapk.apk表示未签名 的APK
test..keystore表示密钥的别名
应用重新打包签名安装后,可能不能正常使用,是因为代码中可能加入了验证证书的相关代码。