如何像 Google Play 在 "Smart app updates" 中那样为 emulator/device 中的应用程序打补丁?
How to patch an application in emulator/device similar to how Google Play is doing with "Smart app updates"?
是否可以在本地(使用 adb
或其他方式)实现 Google Play 在 "Smart app updates" 中所做的事情?
我想做的是在 PC 上创建一个二进制差异(使用一些命令行工具),然后使用 Android 工具(adb,shell, 等等).
我知道
https://android.stackexchange.com/questions/36421/what-is-the-applypatch-tool-and-how-does-one-use-it
它没有提供任何关于如何实际创建和应用补丁的信息,只是 adb shell applypatch
是什么。
我试图快速浏览一下执行修补的 C++ Android 实现代码:https://android.googlesource.com/platform/bootable/recovery/+/master/applypatch/main.cpp#167
到目前为止,我使用 bsdiff 创建了一个二进制 diff,它显然使用与 Google Play 和 Android 正在使用的算法相同的算法。但我不知道如何实际应用该补丁。
编辑:为了澄清,这里有一个很好的例子:
- 我的 PC 上有
com.appv1.apk
,也安装在 device/emulator 上。
- 我的电脑上有
com.appv2.apk
。
- 使用
bsdiff
我创建了 com.appv1.apk
和 com.appv2.apk
之间的二进制差异,假设 diff.bin
现在,我需要 运行 在 device/emulator 上部署 diff.bin
的实际 adb
命令是什么,以便在部署 diff 之后,com.appv1.apk
device/emulator 变为 com.appv2.apk
?
我会说 usage 打印出来:
usage: applypatch [-b <bonus-file>] <src-file> <tgt-file> <tgt-sha1> <tgt-size> [<src-sha1>:<patch> ...]
or applypatch -c <file> [<sha1> ...]
or applypatch -s <bytes>
or applypatch -l
Filenames may be of the form
MTD:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...
to specify reading from or writing to an MTD partition.
和下面的评论:
// This program applies binary patches to files in a way that is safe
// (the original file is not touched until we have the desired
// replacement for it) and idempotent (it's okay to run this program
// multiple times).
//
// - if the sha1 hash of <tgt-file> is <tgt-sha1>, does nothing and exits
// successfully.
//
// - otherwise, if no <src-sha1>:<patch> is provided, flashes <tgt-file> with
// <src-file>. <tgt-file> must be a partition name, while <src-file> must
// be a regular image file. <src-file> will not be deleted on success.
//
// - otherwise, if the sha1 hash of <src-file> is <src-sha1>, applies the
// bsdiff <patch> to <src-file> to produce a new file (the type of patch
// is automatically detected from the file header). If that new
// file has sha1 hash <tgt-sha1>, moves it to replace <tgt-file>, and
// exits successfully. Note that if <src-file> and <tgt-file> are
// not the same, <src-file> is NOT deleted on success. <tgt-file>
// may be the string "-" to mean "the same as src-file".
//
// - otherwise, or if any error is encountered, exits with non-zero
// status.
//
// <src-file> (or <file> in check mode) may refer to an EMMC partition
// to read the source data. See the comments for the
// LoadPartitionContents() function for the format of such a filename.
它非常简单。
所以用 diff.bin
修补 com.appv1.apk
并将结果保存到 com.appv2.apk
的基本命令是:
applypatch com.appv1.apk com.appv2.apk <com.appv2.apk SHA1> <com.appv2.apk size> <com.appv1.apk SHA1>:diff.bin
是否可以在本地(使用 adb
或其他方式)实现 Google Play 在 "Smart app updates" 中所做的事情?
我想做的是在 PC 上创建一个二进制差异(使用一些命令行工具),然后使用 Android 工具(adb,shell, 等等).
我知道
https://android.stackexchange.com/questions/36421/what-is-the-applypatch-tool-and-how-does-one-use-it
它没有提供任何关于如何实际创建和应用补丁的信息,只是 adb shell applypatch
是什么。
我试图快速浏览一下执行修补的 C++ Android 实现代码:https://android.googlesource.com/platform/bootable/recovery/+/master/applypatch/main.cpp#167
到目前为止,我使用 bsdiff 创建了一个二进制 diff,它显然使用与 Google Play 和 Android 正在使用的算法相同的算法。但我不知道如何实际应用该补丁。
编辑:为了澄清,这里有一个很好的例子:
- 我的 PC 上有
com.appv1.apk
,也安装在 device/emulator 上。 - 我的电脑上有
com.appv2.apk
。 - 使用
bsdiff
我创建了com.appv1.apk
和com.appv2.apk
之间的二进制差异,假设diff.bin
现在,我需要 运行 在 device/emulator 上部署 diff.bin
的实际 adb
命令是什么,以便在部署 diff 之后,com.appv1.apk
device/emulator 变为 com.appv2.apk
?
我会说 usage 打印出来:
usage: applypatch [-b <bonus-file>] <src-file> <tgt-file> <tgt-sha1> <tgt-size> [<src-sha1>:<patch> ...]
or applypatch -c <file> [<sha1> ...]
or applypatch -s <bytes>
or applypatch -l
Filenames may be of the form
MTD:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...
to specify reading from or writing to an MTD partition.
和下面的评论:
// This program applies binary patches to files in a way that is safe
// (the original file is not touched until we have the desired
// replacement for it) and idempotent (it's okay to run this program
// multiple times).
//
// - if the sha1 hash of <tgt-file> is <tgt-sha1>, does nothing and exits
// successfully.
//
// - otherwise, if no <src-sha1>:<patch> is provided, flashes <tgt-file> with
// <src-file>. <tgt-file> must be a partition name, while <src-file> must
// be a regular image file. <src-file> will not be deleted on success.
//
// - otherwise, if the sha1 hash of <src-file> is <src-sha1>, applies the
// bsdiff <patch> to <src-file> to produce a new file (the type of patch
// is automatically detected from the file header). If that new
// file has sha1 hash <tgt-sha1>, moves it to replace <tgt-file>, and
// exits successfully. Note that if <src-file> and <tgt-file> are
// not the same, <src-file> is NOT deleted on success. <tgt-file>
// may be the string "-" to mean "the same as src-file".
//
// - otherwise, or if any error is encountered, exits with non-zero
// status.
//
// <src-file> (or <file> in check mode) may refer to an EMMC partition
// to read the source data. See the comments for the
// LoadPartitionContents() function for the format of such a filename.
它非常简单。
所以用 diff.bin
修补 com.appv1.apk
并将结果保存到 com.appv2.apk
的基本命令是:
applypatch com.appv1.apk com.appv2.apk <com.appv2.apk SHA1> <com.appv2.apk size> <com.appv1.apk SHA1>:diff.bin