工具:apktool和jdk(个人使用jdk1.8.0_77)
下载地址:
apktool_2.2.2.jar
apktool.bat
Apktool官网
说明:apktool_2.2.2.jar需要JDK7+;
首先是配置apktool环境变量或者进入到apktool所在目录进行操作,记得将apktool_2.2.2.jar改名为apktool.jar
apktool命令:
1,apktool if framework-res.apk 加载框架
路径:C:\Users\Administrator\apktool\framework\1.apk
2,反编译命令:
一般:apktool d -f <file.apk> <dir>
2.2.2反编译命令: apktool d -f <file.apk> -o <dir>
<file.apk>代表了要反编译的apk文件的路径,最好写绝对路径,比如C:\xxx.apk
<dir>代表了反编译后的文件的存储位置,比如C:\xxx
如果你给定的<dir>已经存在, -f 表示强行覆盖已经存在的文件夹
提示信息:Destination directory (e:\\custom_bailaohui_163) already exists. Use -f switch i
f you want to overwrite it.
完整命令:H:\apktool>apktool d -f E:\custom_bailaohui_163.apk -o e:custom_bailaohui_163
----------------------------------------------
apktool d 相关选项详解
usage: apktool d[ecode] [options] <file_apk>
-f,--force Force delete destination directory.
-o,--output <dir> The name of folder that gets written. Default is apk.out
-p,--frame-path <dir> Uses framework files located in <dir>.
-r,--no-res Do not decode resources.
-s,--no-src Do not decode sources.
-t,--frame-tag <tag> Uses framework files tagged by <tag>.
反编译后的目录结构:
3,回编译命令,得到的apk是未签名的apk
回编译命令:
apktool b <dir> apk文件默认在dir/dist目录下
apktool b <dir> -o <file.apk> 自己指定apk位置
比如:
H:\apktool>apktool b e:\custom_bailaohui_163
H:\apktool>apktool b e:\custom_bailaohui_163 -o e:\test\163.apk
apktool b 相关选项详解
usage: apktool b[uild] [options] <app_path>
-f,--force-all Skip changes detection and build all files.
-o,--output <dir> The name of apk that gets written. Default is dist/name
.apk
-p,--frame-path <dir> Uses framework files located in <dir>.
回编译目录结构:
签名:通过java的jarsigner命令
H:\apktool>jarsigner -verbose -keystore d:xxx.keystore -storepass xxx -digestalg SHA1 -sigalg MD5withRSA -signedjar e:666_sign.apk e:666.apk alias_name
-verbose 输出签名时的详细信息
-keystore 密钥库位置
-storepass 签名文件密码
-digestalg 摘要算法的名称
-sigalg 签名算法的名称
-signedjar 签名后的apk路径
e:666.apk 要进行签名的apk路径
alias_name 签名文件的别名
-digestalg -sigalg
这两个命令在jdk1.6和jdk1.8可以不用带,
jdk1.7必须加上否则安装apk时安装失败
原因:JDK1.7默认签名算法改变,需要指定签名算法和密钥算法。
H:\apktool>jarsigner -help
用法: jarsigner [选项] jar-file 别名
jarsigner -verify [选项] jar-file [别名...]
[-keystore <url>] 密钥库位置
[-storepass <口令>] 用于密钥库完整性的口令
[-storetype <类型>] 密钥库类型
[-keypass <口令>] 私有密钥的口令 (如果不同)
[-certchain <文件>] 替代证书链文件的名称
[-sigfile <文件>] .SF/.DSA 文件的名称
[-signedjar <文件>] 已签名的 JAR 文件的名称
[-digestalg <算法>] 摘要算法的名称
[-sigalg <算法>] 签名算法的名称
[-verify] 验证已签名的 JAR 文件
[-verbose[:suboptions]] 签名/验证时输出详细信息。
子选项可以是 all, grouped 或 summary
[-certs] 输出详细信息和验证时显示证书
[-tsa <url>] 时间戳颁发机构的位置
[-tsacert <别名>] 时间戳颁发机构的公共密钥证书
[-tsapolicyid <oid>] 时间戳颁发机构的 TSAPolicyID
[-altsigner <类>] 替代的签名机制的类名
[-altsignerpath <路径列表>] 替代的签名机制的位置
[-internalsf] 在签名块内包含 .SF 文件
[-sectionsonly] 不计算整个清单的散列
[-protected] 密钥库具有受保护验证路径
[-providerName <名称>] 提供方名称
[-providerClass <类> 加密服务提供方的名称
[-providerArg <参数>]]... 主类文件和构造器参数
[-strict] 将警告视为错误
4,使用zipalign优化apk
命令:zipalign -v 4 E:\666_sign.apk e:\666_zipalign.apk
Usage: zipalign [-f] [-v] [-z] <align> infile.zip outfile.zip
zipalign -c [-v] <align> infile.zip
<align>: alignment in bytes, e.g. '4' provides 32-bit alignment
-c: check alignment only (does not modify file)
-f: overwrite existing outfile.zip
-v: verbose output
-z: recompress using Zopfli
-c 检查是否已经执行过Align优化
-f 覆盖优化的apk
-v 详细信息输出
-z 使用Zopfli算法进行再压缩