- Before Windows 8, Microsoft’s Windows platform didn’t offer a unified software management tool like Apple’s AppStore or Linux’s package management. So Windows software installation, upgrade, uninstall things are generally responsible for the software itself. As a result, there are many different ways to install, upgrade, and uninstall software under Windows, but generally the methods are similar. There are two main types of installation programs, downloader installation package and offline installation package, which will not be described.
- Today’s focus is on upgrades, which may seem simple, but are a vital lifeline for a client software that wants to stay in business. The development team worked hard to fix bugs and make new features that users would like to experience immediately through the new version.
- In the wild days before the Internet, many software companies would release offline upgrade packages, typically an installer that would install only the parts of the program that needed to be updated, and then make changes to system configurations like registries to accommodate the new version’s features.
- Now with the popularization of the Internet, all PC client software is basically used to upgrade online.
- The simplest online upgrade method is that the client sends a message to the server to check the update. The server returns information such as whether there is a new version, the latest version number, and the download address. The client processes the information according to these information. If there are any updates, go to the address you just obtained to download the latest installer and perform the installer update.
- Later, people decided that it was too troublesome to re-install each time, and the installation package was too large and time-consuming to download. The downloaded program is then replaced with a compressed package containing the files the program needs to update. The upgrade package is downloaded and decompressed to the installation directory to complete the software upgrade.
- With the popularity of agile development, software upgrades are becoming more frequent. When the PC client software is upgraded each time, the main program and some important dynamic libraries may be updated, so the downloaded compressed package will be relatively large. This led to BsDiff, an algorithm for comparing binary differences between files, and Google’s further refinement of Courgette. The addition of these algorithms can make the patch pack smaller by n orders of magnitude. In this way, the compressed package that the client needs to download will be small and the download time will be greatly shortened.
- In addition, it is worth mentioning that as the size of the software upgrade package gets bigger and bigger, the waiting time for users to download the updated files becomes longer and longer, so some software adopts the mode of silent backstage download. This way although rogue, but may be better for the user experience. In this case, the main program is generally still running, and if you want to update the file immediately after the upgrade program is downloaded, you must close the main program and then replace the file, so as not to occupy the file and cause the upgrade failure. So Google’s Chorme has come up with a two-directory update to deal with this situation. The so-called double directory update is to copy the original file to another directory, update the program to update the file directory, after the upgrade is complete, directly from the new directory to start the new version.
- Chrome’s directory structure looks like this:
Chorme +Application +57.0.2987.110 +57.0.2987.88 Chrom.exeCopy the code
- As you can see, he uses the version number as the directory name. In the future, just load the latest version when you start Chrome. exe. Of course, it can do this mainly because Chrome.exe itself is a very small program, it does not need to upgrade itself, it is mainly responsible for checking the version number and then loading the new version of the DLL.
- Of course, the current client upgrade program also involves some grayscale, MD5 integrity detection breakpoint continuation and other technologies are not described here. Let me briefly introduce BsDiff and Courgette.
BsDiff: an open source tool in Linux that aims to quickly and lightly update Linux operating system vulnerabilities (similar to Microsoft security patches). The core idea of BsDiff algorithm is to make approximate matches based on statistical rules, and then improve the compression rate of the “approximate segment” through a series of changes (such as BWT transformation). Courgette: Google Chrome updates the core module of the system, based on BsDiff, but with a series of improvements to incorporate platform-specific information (i.e. x86 assembly instructions) in the hope of more accurate pointer positioning, thus avoiding the error rate of statistical algorithms when differences are significant.
- Google has given an example of a 10-megabyte upgrade package using Bsdiff and several orders of magnitude less using Courgette.
- Using the BSDiff algorithm our upgrade process looks like this:
server:
diff = bsdiff(original, update)
transmit diff
client:
receive diff
update = bspatch(original, diff)
Copy the code
-
This is how it works, using the BSDIff algorithm to compare different versions of binaries to create a patch pack. After downloading the patch pack, the client calls BSPatch to generate a new binary.
-
The upgrade process with Courgette looks like this:
server:
asm_old = disassemble(original)
asm_new = disassemble(update)
asm_new_adjusted = adjust(asm_new, asm_old)
asm_diff = bsdiff(asm_old, asm_new_adjusted)
transmit asm_diff
client:
receive asm_diff
asm_old = disassemble(original)
asm_new_adjusted = bspatch(asm_old, asm_diff)
update = assemble(asm_new_adjusted)
Copy the code
-
Courgette optimized BSDIff mainly at adjust, please refer to the official Courgette instructions for details.
-
Finally, Google has also opened source a set of Windows upgrade protocol, you can also check out Omaha.