1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef UPDATER_FILE_PATCH_H 17 #define UPDATER_FILE_PATCH_H 18 19 #include "pkg_manager.h" 20 #include "script_instruction.h" 21 #include "script_manager.h" 22 #include "diffpatch/diffpatch.h" 23 24 namespace Updater { 25 class USInstrImagePatch : public Uscript::UScriptInstruction { 26 public: 27 struct ImagePatchPara { 28 std::string partName {}; 29 std::string devPath {}; 30 std::string srcSize {}; 31 std::string srcHash {}; 32 std::string destSize {}; 33 std::string destHash {}; 34 std::string patchFile {}; 35 }; USInstrImagePatch()36 USInstrImagePatch() {} ~USInstrImagePatch()37 virtual ~USInstrImagePatch() {} 38 int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; 39 private: 40 int32_t GetParam(Uscript::UScriptContext &context, ImagePatchPara ¶); 41 int32_t CreatePatchStream(Uscript::UScriptEnv &env, const ImagePatchPara ¶, 42 Hpackage::PkgManager::StreamPtr &patchStream); 43 int32_t ExecuteImagePatch(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); 44 std::string GetSourceFile(const ImagePatchPara ¶); 45 int32_t ApplyPatch(const ImagePatchPara ¶, const UpdatePatch::MemMapInfo &srcData, 46 const Hpackage::PkgBuffer &patchData); 47 std::string GetFileHash(const std::string &file); 48 }; 49 50 class USInstrImageShaCheck : public Uscript::UScriptInstruction { 51 public: 52 struct CheckPara { 53 std::string partName {}; 54 std::string devPath {}; 55 std::string srcSize {}; 56 std::string srcHash {}; 57 std::string destSize {}; 58 std::string destHash {}; 59 }; USInstrImageShaCheck()60 USInstrImageShaCheck() {} ~USInstrImageShaCheck()61 virtual ~USInstrImageShaCheck() {} 62 int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; 63 private: 64 int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); 65 int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); 66 int32_t CheckHash(const CheckPara ¶); 67 }; 68 } 69 #endif // UPDATER_FILE_PATCH_H 70