apktool 用法命令详解

工具: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>.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
反编译后的目录结构:


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>.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
回编译目录结构:


签名:通过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]                   将警告视为错误
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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算法进行再压缩
————————————————
版权声明:本文为CSDN博主「huycheaven」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/huyuchaoheaven/article/details/72401427

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值