Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _APPLYPATCH_H |
| 18 | #define _APPLYPATCH_H |
| 19 | |
Sen Jiang | 696692a | 2016-02-02 16:01:23 +0800 | [diff] [blame] | 20 | #include <stdint.h> |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 21 | |
Tao Bao | c0e1c46 | 2017-02-01 10:20:10 -0800 | [diff] [blame] | 22 | #include <functional> |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 23 | #include <memory> |
Tianjie Xu | aced5d9 | 2016-10-12 10:55:04 -0700 | [diff] [blame] | 24 | #include <string> |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 27 | #include <openssl/sha.h> |
| 28 | |
Tao Bao | 38d78d1 | 2017-10-09 11:03:38 -0700 | [diff] [blame] | 29 | // Forward declaration to avoid including "edify/expr.h" in the header. |
| 30 | struct Value; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 31 | |
Yabin Cui | d6c93af | 2016-02-10 16:41:10 -0800 | [diff] [blame] | 32 | struct FileContents { |
Sen Jiang | c48cb5e | 2016-02-04 16:23:21 +0800 | [diff] [blame] | 33 | uint8_t sha1[SHA_DIGEST_LENGTH]; |
Yabin Cui | d6c93af | 2016-02-10 16:41:10 -0800 | [diff] [blame] | 34 | std::vector<unsigned char> data; |
Yabin Cui | d6c93af | 2016-02-10 16:41:10 -0800 | [diff] [blame] | 35 | }; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 36 | |
Tao Bao | c0e1c46 | 2017-02-01 10:20:10 -0800 | [diff] [blame] | 37 | using SinkFn = std::function<size_t(const unsigned char*, size_t)>; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 38 | |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 39 | // applypatch.cpp |
Tao Bao | 1e0941f | 2017-11-10 11:49:53 -0800 | [diff] [blame] | 40 | |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 41 | int ShowLicenses(); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 42 | size_t FreeSpaceForFile(const char* filename); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 43 | int CacheSizeCheck(size_t bytes); |
| 44 | int ParseSha1(const char* str, uint8_t* digest); |
| 45 | |
| 46 | int applypatch(const char* source_filename, |
| 47 | const char* target_filename, |
| 48 | const char* target_sha1_str, |
| 49 | size_t target_size, |
Tianjie Xu | aced5d9 | 2016-10-12 10:55:04 -0700 | [diff] [blame] | 50 | const std::vector<std::string>& patch_sha1_str, |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 51 | const std::vector<std::unique_ptr<Value>>& patch_data, |
| 52 | const Value* bonus_data); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 53 | int applypatch_check(const char* filename, |
Tianjie Xu | aced5d9 | 2016-10-12 10:55:04 -0700 | [diff] [blame] | 54 | const std::vector<std::string>& patch_sha1_str); |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 55 | int applypatch_flash(const char* source_filename, const char* target_filename, |
| 56 | const char* target_sha1_str, size_t target_size); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 57 | |
Doug Zongker | a1bc148 | 2014-02-13 15:18:19 -0800 | [diff] [blame] | 58 | int LoadFileContents(const char* filename, FileContents* file); |
Doug Zongker | 1c43c97 | 2012-02-28 11:07:09 -0800 | [diff] [blame] | 59 | int SaveFileContents(const char* filename, const FileContents* file); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 60 | |
Tao Bao | c8e7934 | 2016-12-28 10:11:22 -0800 | [diff] [blame] | 61 | // bspatch.cpp |
Tao Bao | 1e0941f | 2017-11-10 11:49:53 -0800 | [diff] [blame] | 62 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 63 | void ShowBSDiffLicense(); |
Tao Bao | 1e0941f | 2017-11-10 11:49:53 -0800 | [diff] [blame] | 64 | |
| 65 | // Applies the bsdiff-patch given in 'patch' (from offset 'patch_offset' to the end) to the source |
| 66 | // data given by (old_data, old_size). Writes the patched output through the given 'sink', and |
| 67 | // updates the SHA-1 context with the output data. Returns 0 on success. |
| 68 | int ApplyBSDiffPatch(const unsigned char* old_data, size_t old_size, const Value& patch, |
Tao Bao | c0e1c46 | 2017-02-01 10:20:10 -0800 | [diff] [blame] | 69 | size_t patch_offset, SinkFn sink, SHA_CTX* ctx); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 70 | |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 71 | // imgpatch.cpp |
Tao Bao | 1e0941f | 2017-11-10 11:49:53 -0800 | [diff] [blame] | 72 | |
| 73 | // Applies the imgdiff-patch given in 'patch' to the source data given by (old_data, old_size), with |
| 74 | // the optional bonus data. Writes the patched output through the given 'sink', and updates the |
| 75 | // SHA-1 context with the output data. Returns 0 on success. |
| 76 | int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& patch, SinkFn sink, |
Tao Bao | c0e1c46 | 2017-02-01 10:20:10 -0800 | [diff] [blame] | 77 | SHA_CTX* ctx, const Value* bonus_data); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 78 | |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 79 | // freecache.cpp |
Tao Bao | 1e0941f | 2017-11-10 11:49:53 -0800 | [diff] [blame] | 80 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 81 | int MakeFreeSpaceOnCache(size_t bytes_needed); |
| 82 | |
| 83 | #endif |