首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在仿真器/设备中修补应用程序,就像Google Play如何处理“智能应用程序更新”一样?

如何在仿真器/设备中修补应用程序,就像Google Play如何处理“智能应用程序更新”一样?
EN

Stack Overflow用户
提问于 2016-09-15 13:59:34
回答 1查看 1.5K关注 0票数 0

谷歌是否有可能在本地(使用adb或其他方式)实现谷歌在“智能应用更新”中所做的工作?

我想做的是在PC上创建一个二进制diff (使用一些命令行工具),然后使用Android工具(亚行、shell等)将diff部署到模拟器/设备上。

我知道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和Android使用的算法相同。但我不知道怎么实际应用补丁。

编辑:为了澄清,下面是一个很好的例子:

  • 我有com.appv1.apk在我的PC上,也安装在设备/模拟器上。
  • 我的电脑上有com.appv2.apk
  • 使用bsdiff,我在com.appv1.apkcom.appv2.apk之间创建了一个名为diff.bin的二进制差异

现在,我需要运行什么实际的adb命令来在设备/模拟器上部署diff.bin,这样在部署了diff之后,设备/模拟器上的com.appv1.apk就变成了com.appv2.apk

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-15 14:35:48

我想说的是,在使用之间打印出来:

代码语言:javascript
运行
复制
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.

以及以下评论:

代码语言:javascript
运行
复制
// 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.

很直截了当。

因此,使用com.appv1.apk修补diff.bin并将结果保存到com.appv2.apk的基本命令是:

代码语言:javascript
运行
复制
applypatch com.appv1.apk com.appv2.apk <com.appv2.apk SHA1> <com.appv2.apk size> <com.appv1.apk SHA1>:diff.bin
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39513048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档