当前位置:网站首页>apktool 工具使用文档
apktool 工具使用文档
2022-06-26 05:05:00 【浅墨cgz】
apktool 工具使用文档
安装说明
apktool 是 java 语言开发的,提供的是一个 jar 包,需要在 java 运行环境在1.8以上
在终端输入 java -version 在查看本机 java 版本
Mac OS X:
- 下载Mac 包装脚本(右键单击,将链接另存为 apktool ),注意文件没有后缀名
- 下载 apktool-2( 在这里找到最新的 )
- 将下载的jar重命名为 apktool.jar
- 将两个文件( apktool.jar&apktool )移动到 /usr/local/bin( 需要 root )
- 确保两个文件都是可执行的(chmod +x)
- 尝试通过 CLI ( 命令行 )运行 apktool
介绍
首先让我们学习 apk 文件,它是一个包含资源和 java 汇编代码的 zip 文件。既然是 zip 文件,那么我们解压 apk 文件会看到什么呢。可以尝试一下会看到
classes.dex 和其他的资源文件
$ unzip testapp.apk
Archive: testapp.apk
inflating: AndroidManifest.xml
inflating: classes.dex
extracting: res/drawable-hdpi/ic_launcher.png
inflating: res/xml/literals.xml
inflating: res/xml/references.xml
extracting: resources.arsc
你可以尝试查看 AndroidManifest.xml 文件,显示是一堆,加密的乱码。
P4F0\fnversionCodeversionNameandroid*http://schemas.android.com/apk/res/androidpackageplatformBuildVersionCodeplatformBuildVersionNamemanifestbrut.apktool.testapp1.021APKTOOL
显然,我们想编辑或查看编译文件是不行滴。那我们想修改其中的内容改怎么弄呢?
那这就是 apktool 发挥作用的地方了。
$ apktool d testapp.apk
I: Using Apktool 2.0.0 on testapp.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...
$
AndroidManifest.xml 再次查看,是不是很熟悉。这不就是在 AS 里面显示的一样嘛!
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="brut.apktool.testapp" platformBuildVersionCode="21" platformBuildVersionName="APKTOOL" />
除了 XML 之外,诸如 9.PNG,布局文件,字符串等资源,也都正确解码为可读格式。
decode (反编译)
apktool 除了可以解码 apk 外,还能解码 jar 文件,使用参数 d 或 decode 的,具体使用方式如下所示。
// 将foo.jar 解码到 foo.jar.out 文件夹
$ apktool d foo.jar
// 执行结果和上一条命令一样
$ apktool decode foo.jar
// 反编译 apk 文件,生成的文件在当前文件夹的 bar 目录
$ apktool d bar.apk
// -o 参数可以指定生成的文件夹目录名
$ apktool d bar.apk -o baz
操作实例:

build(编译)
可以从下面显示的 b 或 build 如下所示 调用构建选项
// 将 foo.jar.out 文件夹构建到 foo.jar.out/dist/foo.jar 文件中
// 注意查看生成的 jar 文件路径
$ apktool b foo.jar.out
$ apktool build foo.jar.out
// 将bar文件夹构建apk到 bar/dist/bar.apk 文件中
$ apktool b bar
// 将当前目录构建到 ./dist 中
$ apktool b .
// 将 bar 文件夹构建到 new_bar.apk 中 ,-o 选项
$ apktool b bar -o new_bar.apk
// 如果使用错了文件,会出现如下错误提示。
$ apktool b bar.apk
// WRONG: brut.androlib.AndrolibException: brut.directory.PathNotExist: apktool.yml
// Must use folder, not apk/jar file

回编完的 apk,不能直接安装运行。需要重新签名,具体参考 Android 开发文档
我们执行验证命令,查看刚才上例中的 apk,显示应用未签名。

从命令行手动签名应用
这里是已经有现成的 apk 文件,对于在 AndroidStudio 使用命令行构建 apk,参考从命令行构建您的应用。
从命令行签名应用有两种选择方式 jarsigner 和 apksigner。
这里介绍 google 推荐的方式。
签名 APK ,参考下面步骤使用 zipalign 和 apksigner。
- 打开命令行( 在 Android Studio 中,选择 View > Tool Windows > Terminal ),然后导航至未签署 APK 所在的目录。
- 使用 zipalign 对齐未签名的 APK
zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk
zipalign 可以确保所有未压缩的数据首先相对于文件开头部分对齐特定字节,这里指定4字节对齐。这样可减少应用占用的内存量。

- 使用 apksigner 通过您的私钥签署您的 APK:
apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk
- 在本例中,使用单密钥库文件 my-release-key.jks 中存储的私钥和证书签署 APK 后,以 my-app-release.apk形式输出签署的 APK 。
apksigner 工具支持其他签名选项,包括使用单独的私钥和证书文件签署 APK 文件,以及通过多个签署人签署 APK。 如需了解详细信息,请参阅 apksigner 参考。
注:要使用 apksigner 工具,必须安装 Android SDK 构建工具的修订版 24.0.3 或更高版本。 您可以使用 SDK 管理器更新此软件包。

执行完命令输入签名文件对应的密码,再次检查是否签名成功。
- 验证 APK 是否已签名成功,执行如下命令:
apksigner verify my-app-release.apk
参考:
apktool 官方文档
边栏推荐
- 6.1 - 6.2 公鑰密碼學簡介
- [latex] error type summary (hold the change)
- 2022.1.23
- AD教程系列 | 4 - 创建集成库文件
- dijkstra
- Genius makers: lone Rangers, technology giants and AI | ten years of the rise of in-depth learning
- 0622 horse palm fell 9%
- How MySQL deletes all redundant duplicate data
- Datetime data type - min() get the earliest date and date_ Range() creates a date range, timestamp() creates a timestamp, and tz() changes the time zone
- The beautiful scenery is natural, and the wonderful pen is obtained by chance -- how is the "wonderful pen" refined?
猜你喜欢

ROS notes (07) - Implementation of client and server

What is UWB in ultra-high precision positioning system

Ai+ remote sensing: releasing the value of each pixel

Machine learning final exercises

localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。

Differences between TCP and UDP

一个从坟墓里爬出的公司
![C# 39. string类型和byte[]类型相互转换(实测)](/img/33/046aef4e0c1d7c0c0d60c28e707546.png)
C# 39. string类型和byte[]类型相互转换(实测)

UWB ultra high precision positioning system architecture

A method of quickly transplanting library function code to register code by single chip microcomputer
随机推荐
Condition query
Floyd
Multipass Chinese document - remove instance
[greedy college] Figure neural network advanced training camp
[unity3d] human computer interaction input
Genius makers: lone Rangers, technology giants and AI | ten years of the rise of in-depth learning
Learn from small samples and run to the sea of stars
2.22.2.14
LSTM in tensorflow_ Layers actual combat
Multipass Chinese document - use multipass service to authorize the client
Hash problem
超高精度定位系统中的UWB是什么
Using requests library and re library to crawl web pages
6.1 - 6.2 introduction to public key cryptography
Create a binary response variable using the cut sub box operation
localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。
图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译
The first gift of the project, the flying oar contract!
Tensorflow and deep learning day 3
关于支付接口回调地址参数字段是“notify_url”,签名过后的特殊字符url编码以后再解码后出现错误(¬ , ¢, ¤, £)