Skip to content

Instantly share code, notes, and snippets.

@cmartinbaughman
Created October 19, 2012 18:30
Show Gist options
  • Save cmartinbaughman/3919833 to your computer and use it in GitHub Desktop.
Save cmartinbaughman/3919833 to your computer and use it in GitHub Desktop.
Creating MIUI OTA patches
(转)creating binary patch files (.p files) with bsdiff
I was looking through a .602 update.zip and noticed the .p files; I opened one up in notepad++ and saw that the file begins with "bsdiff" so did a search and found this tool:
http://www.daemonology.net/bsdiff/
bsdiff takes an original file and a modified file as input and creates a binary patch file.
bspatch takes an original file and a patch file as input and creates a modified file.
usage (windows):
extract bsdiff .zip into a directory like c:\bsdiff
place desired files to be modified in directory
cd to directory in terminal and
bsdiff.exe oldfile newfile patchfile
This may prove useful for creating mod and theme patches to apply to existing apks as opposed to replacing entire apks.
The next step was to check out the updater-script to see how the patches are applied. the updater-script syntax looks like this:
assert(apply_patch_check("/system/app/AccountAndSyncSettings.apk", "bbbe9a298802275198ea056ee77a565b48ae046e", "504e6ba37cdafbfa0c4e4abcc33c85823feb49b2"));
and further down:
apply_patch("/system/app/AccountAndSyncSettings.apk", "-",
bbbe9a298802275198ea056ee77a565b48ae046e, 50286,
504e6ba37cdafbfa0c4e4abcc33c85823feb49b2, package_extract_file("patch/system/app/AccountAndSyncSettings.apk.p"));
where the first hash in both instances is the sha-1 of the file after the patch is applied, and the second hash is the sha-1 of the pre-patched file. what i can't figure out is the middle number between the two sha-1 hashes in the second entry, in the example it's "50286".
It seems like the main benefit of patching instead of replacing entire apks would be reduced file size, but this benefit may be outweighed by the much more complex code required in the updater-script.
Just wanted to throw this out there for anyone who might find it useful
举报 浏览(466) 评论(1) 转载
@zdunex25
Copy link

zdunex25 commented Sep 1, 2013

Big thanks for this.

50286 - seems like the size of the file after the patch is applied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment