aboutsummaryrefslogtreecommitdiff
path: root/zucchini_gen.cc
AgeCommit message (Collapse)Author
2021-07-25[Zucchini] ARM Support: Add arm_utils.* with tests.Samuel Huang
This CL adds new files for ARM support. The code is not yet integrated into Zucchini, but are only used by the added tests. The high-level goal is to support rel32 reference read / write via: (data bytes) <-> |code| <-> |disp| <-> |target_rva|, where |code| is ARM machine code value (read-write), and |disp| is a PC-relative displacement. Details: * Add template class ArmAddrTraits as API to process rel32 references. It is specialized for each rel32 address type, and aggregates selected low-level static functions from an ARM *Translator class. * Add class Arm32Rel32Translator for 32-bit ARM (ARM32) * ArmAddrTraits is specialized to {A24} encoding for ARM mode, and {T8, T11, T21, T24} encodings for THUMB2 mode. * Complication: |code| can affect |disp| <-> |target_rva|, since the the BLX instruction dictates whether |target_rva| should be 2-byte or 4-byte aligned! * The BLX special case makes |disp| <-> |target_rva| unsuitable for ArmAddrTraits. This led to the API to be defined as: * Fetch() for (data bytes) -> |code|. * Store() for |code| -> (data bytes). * Decode() for |code| -> |disp| & alignment spec (ArmAlign). * Encode() for |disp| -> |code|: Modifies existing |code|. * Read() for |code| -> |target_rva|: Needs |instr_rva|. * Write() for |target_rva| -> |code|. * Needs |instr_rva|; modifies existing |code|. * Add class AArch64Rel32Translator for 64-bit ARM (AArch64). * ArmAddrTraits is specialized to {Immd14, Immd19, Immd26} encodings. Bug: 918867 Change-Id: Ie20935e391ed0ac85c408aa9c8959305dc8bba42 Reviewed-on: https://chromium-review.googlesource.com/c/1394397 Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#622115} NOKEYCHECK=True GitOrigin-RevId: 398b188eab96c3b198b6a4eb8788bba77202aef8
2021-07-25[Zucchini]: Fix OffsetMapper implicit conversion.Etienne Pierre-doray
Fix compile error with -Wshorten-64-to-32. Image size is new stored as an offset_t to avoid implicit conversion. Bug: 881008 Change-Id: I82b12ce17d8368f05d6a5537fd1734ee32b37dbe Reviewed-on: https://chromium-review.googlesource.com/1213549 Reviewed-by: Samuel Huang <huangs@chromium.org> Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Cr-Commit-Position: refs/heads/master@{#589938} NOKEYCHECK=True GitOrigin-RevId: 5946dbfa3f684d8f4960bb413b5e8322ebddcee3
2021-07-25[Zucchini]: Remove IndirectReference.Etienne Pierre-doray
IndirectReference brings complexity conceptually. The purpose of IndirectReference was to speed-up look-ups. Turns out that there is no significant impact on patching time when using direct references. Furthermore, this reduces coupling between TargetPool and ReferenceSet. Change-Id: Ic50dbf59e483a7fa1480c8eb37f4b1d01a53401a Reviewed-on: https://chromium-review.googlesource.com/1136578 Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#582653} NOKEYCHECK=True GitOrigin-RevId: 0434f5b4a564c6295e62a3996826f8627b8aa617
2021-07-25[Zucchini] Fix underflow / overflow for extended forward-projection.Samuel Huang
Forward-projection is how Zucchini uses the equivalence map to create estimated "new" targets from "old" targets. Extended forward-projection is defined to transform non-covered offsets: Given an offset, it finds the equivalence unit with nearest "old" block, then applies the "old"-to-"new" displacement to the offset. However, this makes it possible to map an "old" offset to an offset outside "new" image. Another issue is that Zucchini uses "dangling targets" that use "fake offsets" outside the image file to represent .bss data. These targets also undergo forward-projection, and should be properly handled. This CL fixes the existing behavior, where underflow / overflow go unchecked (although these values are rendered benign downstream, since the nearest actual "new" target is found). The updated extended forward-projection specifies: - For "old" targets with real offsets: Take nearest equivalence unit, clamp output to be inside [0, "new" image size). - For "old" dangling targets with fake offsets: Use difference in file size as displacement. The main impact w.r.t. patch is to reduce possible variance in patch sizes -- dangling targets are now handled better. Extensive unit tests are also added. Bug: 832572 Change-Id: I41fea175e4c13585d14a97a712a191afc2fcc6d6 Reviewed-on: https://chromium-review.googlesource.com/1111467 Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#570401} NOKEYCHECK=True GitOrigin-RevId: ad7a5c086f00de62997714b84d6d6b5817ccc9d8
2021-07-25[Zucchini] Refactor Zucchini-gen in zucchini_io layer.Samuel Huang
This CL moves Zucchini-gen invocation code from zucchini_commands.cc (in target zucchini) to zucchini_integration.cc (in target zucchini_io) to clean up layering in Zucchini API, i.e.: - zucchini_lib: Operates on buffers only. - zucchini_io: Adds files interface, uses memory-mapped I/O. - zucchini: Stand-alone executable that parses command-line arguments. Other changes: - Rename zucchini_lib functions (zuchcini.h), to dedup names and emphasize that these functions operate on buffers: - GenerateEnsemble() -> GenerateBuffer(), - GenerateEnsembleWithImposedMatches() -> GenerateBufferImposed(), - GenerateRaw() -> GenerateBufferRaw(), - Apply() -> ApplyBuffer(). These renames only affect Zucchini and various tests. - Variable renames and parameter reordering in zucchini_integration.cc. - Remove '-dd' param in help text of Zucchini-detect (was never ported from Trunk, and has been recently deleted there as well). - Replace all base::File&& with base::File. - Miscellaneous cleanup for header include. - Update README.md. Change-Id: I835b80d4d3d7b291fa822a7a89dab225bf9171e9 Reviewed-on: https://chromium-review.googlesource.com/1105625 Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#569274} NOKEYCHECK=True GitOrigin-RevId: 9f0f325d6e2595deb8d50c77e0464946f3bf1ec1
2021-07-23[Zucchini] Introduce Imposed Ensemble Matcher.Samuel Huang
Previously Zucchini-gen uses built-in heuristics to perform element matching for ensemble patch generation. This CL adds an option (accessible via the -impose parameter) to specify elements in "old" and "new", and how they match. This allows the default heuristics to be overridden, and enables external applications (who perhaps have better ideas of element matching, e.g., have access to archiving programs) to better use Zucchini to patch archives. Zucchini-match is updated to prints the -impose command line to repeat its results. Also, ElementMatch::ToString() is added. Change-Id: I541b64722904c2fcd19ed75246d87e0268fbf86c Reviewed-on: https://chromium-review.googlesource.com/1027191 Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#554909} NOKEYCHECK=True GitOrigin-RevId: 73a64ffde3f3b64df576aa1f2b5baebf7ec964ba
2021-07-23[Zucchini] Introduce ReferenceBytesMixer.Samuel Huang
Some architectures (e.g., ARM) have references that mix operation bits with payload bits. ReferenceBytesMixer is a class to isloate operation bit changes to Layer 1 patching. This CL introduces only the stub for ReferenceBytesMixer (the remainder would require ARM support). Having this now brings Zucchini-gen closer to trunk code, and sets up upcoming work for a mock disassembler. Change-Id: I2e1aa56bf265e4b61b33d323be2ed9a456e14f3b Reviewed-on: https://chromium-review.googlesource.com/1021650 Commit-Queue: Samuel Huang <huangs@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Cr-Commit-Position: refs/heads/master@{#552373} NOKEYCHECK=True GitOrigin-RevId: fdb4806d8d03c52ffe4ca7b14076f483384eedfb
2021-07-23[Zucchini] Format change: Remove PatchType.Samuel Huang
Previously, Zucchini patches store a uint32_t PatchType enum that distinguishes among (0) raw patch, (1) single executable patch, and (2) ensemble patch. However, ever since every element (and gap) stores ExecutableType, this PatchType field has become a vestige. This CL simplifies Zucchini by removing PatchType, including in README.md and tests. This CL alters Zucchini patch format (removes 4 bytes); patches created across this change are incompatible. Bug: 729154 Change-Id: Ia5f467ba5e01720f5085ce87a5de88f678a64930 Reviewed-on: https://chromium-review.googlesource.com/981789 Commit-Queue: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Cr-Commit-Position: refs/heads/master@{#546621} NOKEYCHECK=True GitOrigin-RevId: 325bcee07f3eb9e3604c8aa0367ae7145025ddb6
2021-07-23[Zucchini] Delete Label Manager.Etienne Pierre-Doray
This CL deletes Label Manager sources and unittests since it is not used anymore. Bug: 729154 Change-Id: Ic8e9cc8dbebd4317d53c0b48ac683b44de99593b Reviewed-on: https://chromium-review.googlesource.com/967051 Reviewed-by: Samuel Huang <huangs@chromium.org> Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Cr-Commit-Position: refs/heads/master@{#544016} NOKEYCHECK=True GitOrigin-RevId: bdbf3919914f79fb3c6a941d458e9cbd22d7056a
2021-07-23[Zucchini] Zucchini-gen: Make number of CreateEquivalenceMap() generations ↵Samuel Huang
depend on Disassembler. The number of CreateEquivalenceMap() iterations used be constant kNumIteraitons = 2. This CL makes the value depend on architecture. Current assignment: - DisassemblerNoOp: 1, since no pointers are identified (though in this case, CreateEquivalenceMap() should not be called). - DisassemblerWin32: 2. Upcoming DisassemblerDex will use 4. Also applying generic cleanups on headers and comments. Bug: 729154 Change-Id: Ia12d98fcba500e4c81c8a5d356ce4cadf424ffde Reviewed-on: https://chromium-review.googlesource.com/961273 Reviewed-by: agrieve <agrieve@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#542919} NOKEYCHECK=True GitOrigin-RevId: 55aea0a875b80e614464fdd157d9717471f9d64f
2021-07-23[Zucchini] Move Zucchini from /chrome/installer/ to /components/.Samuel Huang
(Use "git log --follow" to see older revisions of files). /components/ is the most logical place to put Zucchini, which only depends on /base and /testing/gtest. This move also enables Zucchini to be used by the Component Updater. Details: - Move all files; run the following to change deps and guards: sed 's/chrome\/installer/components/' *.cc *.h -i sed 's/CHROME_INSTALLER/COMPONENTS/' *.cc *.h -i - Sorting works out pretty well! - Change all 'chrome/installer/zucchini' to 'components/zucchini' throughout other parts of the repo; sort if necessary. - Fix 6 'git cl lint' errors. - Change 1 Bind() usage to BindRepeated(). - Update OWNER. Bug: 729154 Change-Id: I50c5a7d411ea85f707b5994ab319dfb2a1acccf7 Reviewed-on: https://chromium-review.googlesource.com/954923 Reviewed-by: Greg Thompson <grt@chromium.org> Reviewed-by: Jochen Eisinger <jochen@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#542857} NOKEYCHECK=True GitOrigin-RevId: 577ef6c435e8d43be6e3e60ccbcbd1881780f4ec