1be168c0dSopenharmony_cidiff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake
2be168c0dSopenharmony_ciindex f15724f1e5..4175c44c02 100644
3be168c0dSopenharmony_ci--- a/cmake/package_lite.cmake
4be168c0dSopenharmony_ci+++ b/cmake/package_lite.cmake
5be168c0dSopenharmony_ci@@ -458,10 +458,6 @@ if(PLATFORM_ARM64)
6be168c0dSopenharmony_ci                     DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
7be168c0dSopenharmony_ci         endif()
8be168c0dSopenharmony_ci     endif()
9be168c0dSopenharmony_ci-    if(MSLITE_ENABLE_MODEL_OBF)
10be168c0dSopenharmony_ci-        install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch64/libmsdeobfuscator-lite.so
11be168c0dSopenharmony_ci-                DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
12be168c0dSopenharmony_ci-    endif()
13be168c0dSopenharmony_ci     install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
14be168c0dSopenharmony_ci             COMPONENT ${RUNTIME_COMPONENT_NAME})
15be168c0dSopenharmony_ci     install(FILES
16be168c0dSopenharmony_ci@@ -705,10 +701,6 @@ elseif(PLATFORM_ARM32)
17be168c0dSopenharmony_ci                     DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
18be168c0dSopenharmony_ci         endif()
19be168c0dSopenharmony_ci     endif()
20be168c0dSopenharmony_ci-    if(MSLITE_ENABLE_MODEL_OBF)
21be168c0dSopenharmony_ci-        install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch32/libmsdeobfuscator-lite.so
22be168c0dSopenharmony_ci-                DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
23be168c0dSopenharmony_ci-    endif()
24be168c0dSopenharmony_ci     install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
25be168c0dSopenharmony_ci             COMPONENT ${RUNTIME_COMPONENT_NAME})
26be168c0dSopenharmony_ci     install(FILES
27be168c0dSopenharmony_ci@@ -906,13 +898,6 @@ else()
28be168c0dSopenharmony_ci                     DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
29be168c0dSopenharmony_ci         endif()
30be168c0dSopenharmony_ci     endif()
31be168c0dSopenharmony_ci-    if(MSLITE_ENABLE_MODEL_OBF)
32be168c0dSopenharmony_ci-        install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/bin/linux-x64/msobfuscator
33be168c0dSopenharmony_ci-                DESTINATION ${OBFUSCATOR_ROOT_DIR} PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
34be168c0dSopenharmony_ci-                GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT ${RUNTIME_COMPONENT_NAME})
35be168c0dSopenharmony_ci-        install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/linux-x64/libmsdeobfuscator-lite.so
36be168c0dSopenharmony_ci-                DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
37be168c0dSopenharmony_ci-    endif()
38be168c0dSopenharmony_ci     if(MSLITE_ENABLE_RUNTIME_GLOG)
39be168c0dSopenharmony_ci         install(FILES ${glog_LIBPATH}/libmindspore_glog.so.0.4.0 DESTINATION ${GLOG_DIR} RENAME libmindspore_glog.so.0
40be168c0dSopenharmony_ci                 COMPONENT ${RUNTIME_COMPONENT_NAME})
41be168c0dSopenharmony_cidiff --git a/mindspore/lite/include/model.h b/mindspore/lite/include/model.h
42be168c0dSopenharmony_ciindex b96c7e35bf..629978f1bc 100644
43be168c0dSopenharmony_ci--- a/mindspore/lite/include/model.h
44be168c0dSopenharmony_ci+++ b/mindspore/lite/include/model.h
45be168c0dSopenharmony_ci@@ -57,12 +57,6 @@ struct MS_API LiteGraph {
46be168c0dSopenharmony_ci   std::vector<mindspore::schema::Tensor *> all_tensors_;
47be168c0dSopenharmony_ci   std::vector<Node *> all_nodes_;
48be168c0dSopenharmony_ci   std::vector<SubGraph *> sub_graphs_;
49be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
50be168c0dSopenharmony_ci-  std::vector<uint32_t> all_prims_type_;
51be168c0dSopenharmony_ci-  std::vector<uint32_t> all_nodes_stat_;
52be168c0dSopenharmony_ci-  bool model_obfuscated_ = false;
53be168c0dSopenharmony_ci-  std::vector<unsigned char *> deobf_prims_;
54be168c0dSopenharmony_ci-#endif
55be168c0dSopenharmony_ci 
56be168c0dSopenharmony_ci   std::string ToString() const;
57be168c0dSopenharmony_ci };
58be168c0dSopenharmony_ci@@ -72,6 +66,7 @@ struct MS_API Model {
59be168c0dSopenharmony_ci   char *buf = nullptr;
60be168c0dSopenharmony_ci   size_t buf_size_ = 0;
61be168c0dSopenharmony_ci   LiteModelType model_type_ = mindspore::lite::ModelType_MSLite;
62be168c0dSopenharmony_ci+  void *deobf = nullptr;
63be168c0dSopenharmony_ci 
64be168c0dSopenharmony_ci   /// \brief Static method to create a Model pointer.
65be168c0dSopenharmony_ci   static Model *Import(const char *model_buf, size_t size);
66be168c0dSopenharmony_cidiff --git a/mindspore/lite/include/registry/deobf_processor.h b/mindspore/lite/include/registry/deobf_processor.h
67be168c0dSopenharmony_cinew file mode 100644
68be168c0dSopenharmony_ciindex 0000000000..5987233fd7
69be168c0dSopenharmony_ci--- /dev/null
70be168c0dSopenharmony_ci+++ b/mindspore/lite/include/registry/deobf_processor.h
71be168c0dSopenharmony_ci@@ -0,0 +1,77 @@
72be168c0dSopenharmony_ci+/**
73be168c0dSopenharmony_ci+ * Copyright 2021 Huawei Technologies Co., Ltd
74be168c0dSopenharmony_ci+ *
75be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License");
76be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License.
77be168c0dSopenharmony_ci+ * You may obtain a copy of the License at
78be168c0dSopenharmony_ci+ *
79be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0
80be168c0dSopenharmony_ci+ *
81be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software
82be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS,
83be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
84be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and
85be168c0dSopenharmony_ci+ * limitations under the License.
86be168c0dSopenharmony_ci+ */
87be168c0dSopenharmony_ci+
88be168c0dSopenharmony_ci+#ifndef MINDSPORE_LITE_INCLUDE_REGISTRY_DEOBFPROCESSOR_H_
89be168c0dSopenharmony_ci+#define MINDSPORE_LITE_INCLUDE_REGISTRY_DEOBFPROCESSOR_H_
90be168c0dSopenharmony_ci+
91be168c0dSopenharmony_ci+#include <vector>
92be168c0dSopenharmony_ci+#include <string>
93be168c0dSopenharmony_ci+#include <numeric>
94be168c0dSopenharmony_ci+#include "src/common/prim_util.h"
95be168c0dSopenharmony_ci+#include "src/common/log.h"
96be168c0dSopenharmony_ci+#include "include/model.h"
97be168c0dSopenharmony_ci+#include "schema/inner/model_generated.h"
98be168c0dSopenharmony_ci+
99be168c0dSopenharmony_ci+namespace mindspore::lite {
100be168c0dSopenharmony_ci+
101be168c0dSopenharmony_ci+  enum DeObfRet : uint32_t {
102be168c0dSopenharmony_ci+    kDeObfFailed = 0,        ///<Deobfuscator failed
103be168c0dSopenharmony_ci+    kNoObf = 1,               ///<The node has not been obfuscated
104be168c0dSopenharmony_ci+    kDeObfSuccess = 2,        ///<Deobfuscate success
105be168c0dSopenharmony_ci+  };
106be168c0dSopenharmony_ci+
107be168c0dSopenharmony_ci+  class DeObfProcessor {
108be168c0dSopenharmony_ci+    public:
109be168c0dSopenharmony_ci+      DeObfProcessor() = default;
110be168c0dSopenharmony_ci+
111be168c0dSopenharmony_ci+      bool GetModelDeObf(const void *meta_graph, Model *model);
112be168c0dSopenharmony_ci+
113be168c0dSopenharmony_ci+      void DeObfuscate(Model *model);
114be168c0dSopenharmony_ci+
115be168c0dSopenharmony_ci+      DeObfRet CreateDeObfNode(const schema::Primitive *&src_prim, int i, int schema__version);
116be168c0dSopenharmony_ci+
117be168c0dSopenharmony_ci+      std::vector<uint32_t> all_prims_type_;
118be168c0dSopenharmony_ci+      std::vector<uint32_t> all_nodes_stat_;
119be168c0dSopenharmony_ci+      bool model_obfuscated_ = false;
120be168c0dSopenharmony_ci+      void *model_deobf = nullptr;
121be168c0dSopenharmony_ci+  };
122be168c0dSopenharmony_ci+
123be168c0dSopenharmony_ci+  typedef void (*ObfCreateFunc)(Model &model);
124be168c0dSopenharmony_ci+
125be168c0dSopenharmony_ci+  class MS_API DeObfRegister {
126be168c0dSopenharmony_ci+    public:
127be168c0dSopenharmony_ci+      static bool (DeObfProcessor::*GetModelDeObfReg)(const void *meta_graph, Model *model);
128be168c0dSopenharmony_ci+      static void (DeObfProcessor::*DeObfuscateReg)(Model *model);
129be168c0dSopenharmony_ci+      static DeObfRet (DeObfProcessor::*CreateDeObfNodeReg)(const schema::Primitive *&src_prim, int i, int schema__version);
130be168c0dSopenharmony_ci+      static void *deobf_handle;
131be168c0dSopenharmony_ci+
132be168c0dSopenharmony_ci+      DeObfRegister() = default;
133be168c0dSopenharmony_ci+      ~DeObfRegister() = default;
134be168c0dSopenharmony_ci+
135be168c0dSopenharmony_ci+      static ObfCreateFunc NewDeObfProcessor;
136be168c0dSopenharmony_ci+
137be168c0dSopenharmony_ci+      static void Fail(Model &model){MS_LOG(INFO) << "DeObfuscator not registered!";}
138be168c0dSopenharmony_ci+
139be168c0dSopenharmony_ci+      MS_API static void RegisterDeObfuscator(ObfCreateFunc func){
140be168c0dSopenharmony_ci+        if(func == nullptr){
141be168c0dSopenharmony_ci+          MS_LOG(WARNING) << "Register invalid deobfuscator";
142be168c0dSopenharmony_ci+          return;
143be168c0dSopenharmony_ci+        }
144be168c0dSopenharmony_ci+        NewDeObfProcessor = func;
145be168c0dSopenharmony_ci+      }
146be168c0dSopenharmony_ci+  };
147be168c0dSopenharmony_ci+}
148be168c0dSopenharmony_ci+#endif
149be168c0dSopenharmony_cidiff --git a/mindspore/lite/schema/inner/model_generated.h b/mindspore/lite/schema/inner/model_generated.h
150be168c0dSopenharmony_ciindex c3bc5dbfb0..6f4bd14bd6 100644
151be168c0dSopenharmony_ci--- a/mindspore/lite/schema/inner/model_generated.h
152be168c0dSopenharmony_ci+++ b/mindspore/lite/schema/inner/model_generated.h
153be168c0dSopenharmony_ci@@ -2661,7 +2661,9 @@ struct MetaGraphT : public flatbuffers::NativeTable {
154be168c0dSopenharmony_ci   std::vector<std::unique_ptr<mindspore::schema::TensorT>> allTensors{};
155be168c0dSopenharmony_ci   std::vector<std::unique_ptr<mindspore::schema::SubGraphT>> subGraph{};
156be168c0dSopenharmony_ci   bool obfuscate = false;
157be168c0dSopenharmony_ci+  bool encrypt = false;
158be168c0dSopenharmony_ci   std::vector<uint8_t> obfMetaData{};
159be168c0dSopenharmony_ci+  std::vector<uint8_t> decryptTable{};
160be168c0dSopenharmony_ci };
161be168c0dSopenharmony_ci 
162be168c0dSopenharmony_ci struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
163be168c0dSopenharmony_ci@@ -2681,7 +2683,9 @@ struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
164be168c0dSopenharmony_ci     VT_ALLTENSORS = 18,
165be168c0dSopenharmony_ci     VT_SUBGRAPH = 20,
166be168c0dSopenharmony_ci     VT_OBFUSCATE = 22,
167be168c0dSopenharmony_ci-    VT_OBFMETADATA = 24
168be168c0dSopenharmony_ci+    VT_ENCRYPT = 24,
169be168c0dSopenharmony_ci+    VT_OBFMETADATA = 26,
170be168c0dSopenharmony_ci+    VT_DECRYPTTABLE = 28
171be168c0dSopenharmony_ci   };
172be168c0dSopenharmony_ci   const flatbuffers::String *name() const {
173be168c0dSopenharmony_ci     return GetPointer<const flatbuffers::String *>(VT_NAME);
174be168c0dSopenharmony_ci@@ -2743,12 +2747,24 @@ struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
175be168c0dSopenharmony_ci   bool mutate_obfuscate(bool _obfuscate) {
176be168c0dSopenharmony_ci     return SetField<uint8_t>(VT_OBFUSCATE, static_cast<uint8_t>(_obfuscate), 0);
177be168c0dSopenharmony_ci   }
178be168c0dSopenharmony_ci+  bool encrypt() const {
179be168c0dSopenharmony_ci+    return GetField<uint8_t>(VT_ENCRYPT, 0) != 0;
180be168c0dSopenharmony_ci+  }
181be168c0dSopenharmony_ci+  bool mutate_encrypt(bool _encrypt) {
182be168c0dSopenharmony_ci+    return SetField<uint8_t>(VT_ENCRYPT, static_cast<uint8_t>(_encrypt), 0);
183be168c0dSopenharmony_ci+  }
184be168c0dSopenharmony_ci   const flatbuffers::Vector<uint8_t> *obfMetaData() const {
185be168c0dSopenharmony_ci     return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_OBFMETADATA);
186be168c0dSopenharmony_ci   }
187be168c0dSopenharmony_ci   flatbuffers::Vector<uint8_t> *mutable_obfMetaData() {
188be168c0dSopenharmony_ci     return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_OBFMETADATA);
189be168c0dSopenharmony_ci   }
190be168c0dSopenharmony_ci+  const flatbuffers::Vector<uint8_t> *decryptTable() const {
191be168c0dSopenharmony_ci+    return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_DECRYPTTABLE);
192be168c0dSopenharmony_ci+  }
193be168c0dSopenharmony_ci+  flatbuffers::Vector<uint8_t> *mutable_decryptTable() {
194be168c0dSopenharmony_ci+    return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_DECRYPTTABLE);
195be168c0dSopenharmony_ci+  }
196be168c0dSopenharmony_ci   bool Verify(flatbuffers::Verifier &verifier) const {
197be168c0dSopenharmony_ci     return VerifyTableStart(verifier) &&
198be168c0dSopenharmony_ci            VerifyOffset(verifier, VT_NAME) &&
199be168c0dSopenharmony_ci@@ -2771,8 +2787,11 @@ struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
200be168c0dSopenharmony_ci            verifier.VerifyVector(subGraph()) &&
201be168c0dSopenharmony_ci            verifier.VerifyVectorOfTables(subGraph()) &&
202be168c0dSopenharmony_ci            VerifyField<uint8_t>(verifier, VT_OBFUSCATE) &&
203be168c0dSopenharmony_ci+           VerifyField<uint8_t>(verifier, VT_ENCRYPT) &&
204be168c0dSopenharmony_ci            VerifyOffset(verifier, VT_OBFMETADATA) &&
205be168c0dSopenharmony_ci            verifier.VerifyVector(obfMetaData()) &&
206be168c0dSopenharmony_ci+           VerifyOffset(verifier, VT_DECRYPTTABLE) &&
207be168c0dSopenharmony_ci+           verifier.VerifyVector(decryptTable()) &&
208be168c0dSopenharmony_ci            verifier.EndTable();
209be168c0dSopenharmony_ci   }
210be168c0dSopenharmony_ci   MetaGraphT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
211be168c0dSopenharmony_ci@@ -2814,9 +2833,15 @@ struct MetaGraphBuilder {
212be168c0dSopenharmony_ci   void add_obfuscate(bool obfuscate) {
213be168c0dSopenharmony_ci     fbb_.AddElement<uint8_t>(MetaGraph::VT_OBFUSCATE, static_cast<uint8_t>(obfuscate), 0);
214be168c0dSopenharmony_ci   }
215be168c0dSopenharmony_ci+  void add_encrypt(bool encrypt) {
216be168c0dSopenharmony_ci+    fbb_.AddElement<uint8_t>(MetaGraph::VT_OBFUSCATE, static_cast<uint8_t>(encrypt), 0);
217be168c0dSopenharmony_ci+  }
218be168c0dSopenharmony_ci   void add_obfMetaData(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> obfMetaData) {
219be168c0dSopenharmony_ci     fbb_.AddOffset(MetaGraph::VT_OBFMETADATA, obfMetaData);
220be168c0dSopenharmony_ci   }
221be168c0dSopenharmony_ci+  void add_decryptTable(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> decryptTable) {
222be168c0dSopenharmony_ci+    fbb_.AddOffset(MetaGraph::VT_DECRYPTTABLE, decryptTable);
223be168c0dSopenharmony_ci+  }
224be168c0dSopenharmony_ci   explicit MetaGraphBuilder(flatbuffers::FlatBufferBuilder &_fbb)
225be168c0dSopenharmony_ci         : fbb_(_fbb) {
226be168c0dSopenharmony_ci     start_ = fbb_.StartTable();
227be168c0dSopenharmony_ci@@ -2840,8 +2865,11 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraph(
228be168c0dSopenharmony_ci     flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<mindspore::schema::Tensor>>> allTensors = 0,
229be168c0dSopenharmony_ci     flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<mindspore::schema::SubGraph>>> subGraph = 0,
230be168c0dSopenharmony_ci     bool obfuscate = false,
231be168c0dSopenharmony_ci-    flatbuffers::Offset<flatbuffers::Vector<uint8_t>> obfMetaData = 0) {
232be168c0dSopenharmony_ci+    bool encrypt = false,
233be168c0dSopenharmony_ci+    flatbuffers::Offset<flatbuffers::Vector<uint8_t>> obfMetaData = 0,
234be168c0dSopenharmony_ci+    flatbuffers::Offset<flatbuffers::Vector<uint8_t>> decryptTable = 0) {
235be168c0dSopenharmony_ci   MetaGraphBuilder builder_(_fbb);
236be168c0dSopenharmony_ci+  builder_.add_decryptTable(decryptTable);
237be168c0dSopenharmony_ci   builder_.add_obfMetaData(obfMetaData);
238be168c0dSopenharmony_ci   builder_.add_subGraph(subGraph);
239be168c0dSopenharmony_ci   builder_.add_allTensors(allTensors);
240be168c0dSopenharmony_ci@@ -2853,6 +2881,7 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraph(
241be168c0dSopenharmony_ci   builder_.add_version(version);
242be168c0dSopenharmony_ci   builder_.add_name(name);
243be168c0dSopenharmony_ci   builder_.add_obfuscate(obfuscate);
244be168c0dSopenharmony_ci+  builder_.add_encrypt(encrypt);
245be168c0dSopenharmony_ci   return builder_.Finish();
246be168c0dSopenharmony_ci }
247be168c0dSopenharmony_ci 
248be168c0dSopenharmony_ci@@ -2868,7 +2897,9 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraphDirect(
249be168c0dSopenharmony_ci     const std::vector<flatbuffers::Offset<mindspore::schema::Tensor>> *allTensors = nullptr,
250be168c0dSopenharmony_ci     const std::vector<flatbuffers::Offset<mindspore::schema::SubGraph>> *subGraph = nullptr,
251be168c0dSopenharmony_ci     bool obfuscate = false,
252be168c0dSopenharmony_ci-    const std::vector<uint8_t> *obfMetaData = nullptr) {
253be168c0dSopenharmony_ci+    bool encrypt = false,
254be168c0dSopenharmony_ci+    const std::vector<uint8_t> *obfMetaData = nullptr,
255be168c0dSopenharmony_ci+    const std::vector<uint8_t> *decryptTable = nullptr) {
256be168c0dSopenharmony_ci   auto name__ = name ? _fbb.CreateString(name) : 0;
257be168c0dSopenharmony_ci   auto version__ = version ? _fbb.CreateString(version) : 0;
258be168c0dSopenharmony_ci   auto inputIndex__ = inputIndex ? _fbb.CreateVector<uint32_t>(*inputIndex) : 0;
259be168c0dSopenharmony_ci@@ -2877,6 +2908,7 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraphDirect(
260be168c0dSopenharmony_ci   auto allTensors__ = allTensors ? _fbb.CreateVector<flatbuffers::Offset<mindspore::schema::Tensor>>(*allTensors) : 0;
261be168c0dSopenharmony_ci   auto subGraph__ = subGraph ? _fbb.CreateVector<flatbuffers::Offset<mindspore::schema::SubGraph>>(*subGraph) : 0;
262be168c0dSopenharmony_ci   auto obfMetaData__ = obfMetaData ? _fbb.CreateVector<uint8_t>(*obfMetaData) : 0;
263be168c0dSopenharmony_ci+  auto decryptTable__ = decryptTable ? _fbb.CreateVector<uint8_t>(*decryptTable) : 0;
264be168c0dSopenharmony_ci   return mindspore::schema::CreateMetaGraph(
265be168c0dSopenharmony_ci       _fbb,
266be168c0dSopenharmony_ci       name__,
267be168c0dSopenharmony_ci@@ -2889,7 +2921,9 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraphDirect(
268be168c0dSopenharmony_ci       allTensors__,
269be168c0dSopenharmony_ci       subGraph__,
270be168c0dSopenharmony_ci       obfuscate,
271be168c0dSopenharmony_ci-      obfMetaData__);
272be168c0dSopenharmony_ci+      encrypt,
273be168c0dSopenharmony_ci+      obfMetaData__,
274be168c0dSopenharmony_ci+      decryptTable__);
275be168c0dSopenharmony_ci }
276be168c0dSopenharmony_ci 
277be168c0dSopenharmony_ci flatbuffers::Offset<MetaGraph> CreateMetaGraph(flatbuffers::FlatBufferBuilder &_fbb, const MetaGraphT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
278be168c0dSopenharmony_ci@@ -3177,7 +3211,9 @@ inline void MetaGraph::UnPackTo(MetaGraphT *_o, const flatbuffers::resolver_func
279be168c0dSopenharmony_ci   { auto _e = allTensors(); if (_e) { _o->allTensors.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->allTensors[_i] = std::unique_ptr<mindspore::schema::TensorT>(_e->Get(_i)->UnPack(_resolver)); } } }
280be168c0dSopenharmony_ci   { auto _e = subGraph(); if (_e) { _o->subGraph.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->subGraph[_i] = std::unique_ptr<mindspore::schema::SubGraphT>(_e->Get(_i)->UnPack(_resolver)); } } }
281be168c0dSopenharmony_ci   { auto _e = obfuscate(); _o->obfuscate = _e; }
282be168c0dSopenharmony_ci+  { auto _e = encrypt(); _o->encrypt = _e; }
283be168c0dSopenharmony_ci   { auto _e = obfMetaData(); if (_e) { _o->obfMetaData.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->obfMetaData.begin()); } }
284be168c0dSopenharmony_ci+  { auto _e = decryptTable(); if (_e) { _o->decryptTable.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->decryptTable.begin()); } }
285be168c0dSopenharmony_ci }
286be168c0dSopenharmony_ci 
287be168c0dSopenharmony_ci inline flatbuffers::Offset<MetaGraph> MetaGraph::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MetaGraphT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
288be168c0dSopenharmony_ci@@ -3198,7 +3234,9 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraph(flatbuffers::FlatBufferBui
289be168c0dSopenharmony_ci   auto _allTensors = _o->allTensors.size() ? _fbb.CreateVector<flatbuffers::Offset<mindspore::schema::Tensor>> (_o->allTensors.size(), [](size_t i, _VectorArgs *__va) { return CreateTensor(*__va->__fbb, __va->__o->allTensors[i].get(), __va->__rehasher); }, &_va ) : 0;
290be168c0dSopenharmony_ci   auto _subGraph = _o->subGraph.size() ? _fbb.CreateVector<flatbuffers::Offset<mindspore::schema::SubGraph>> (_o->subGraph.size(), [](size_t i, _VectorArgs *__va) { return CreateSubGraph(*__va->__fbb, __va->__o->subGraph[i].get(), __va->__rehasher); }, &_va ) : 0;
291be168c0dSopenharmony_ci   auto _obfuscate = _o->obfuscate;
292be168c0dSopenharmony_ci+  auto _encrypt = _o->encrypt;
293be168c0dSopenharmony_ci   auto _obfMetaData = _o->obfMetaData.size() ? _fbb.CreateVector(_o->obfMetaData) : 0;
294be168c0dSopenharmony_ci+  auto _decryptTable = _o->decryptTable.size() ? _fbb.CreateVector(_o->decryptTable) : 0;
295be168c0dSopenharmony_ci   return mindspore::schema::CreateMetaGraph(
296be168c0dSopenharmony_ci       _fbb,
297be168c0dSopenharmony_ci       _name,
298be168c0dSopenharmony_ci@@ -3211,7 +3249,9 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraph(flatbuffers::FlatBufferBui
299be168c0dSopenharmony_ci       _allTensors,
300be168c0dSopenharmony_ci       _subGraph,
301be168c0dSopenharmony_ci       _obfuscate,
302be168c0dSopenharmony_ci-      _obfMetaData);
303be168c0dSopenharmony_ci+      _encrypt,
304be168c0dSopenharmony_ci+      _obfMetaData,
305be168c0dSopenharmony_ci+      _decryptTable);
306be168c0dSopenharmony_ci }
307be168c0dSopenharmony_ci 
308be168c0dSopenharmony_ci inline const flatbuffers::TypeTable *WeightQuantCompressTypeTypeTable() {
309be168c0dSopenharmony_ci@@ -3374,6 +3414,8 @@ inline const flatbuffers::TypeTable *MetaGraphTypeTable() {
310be168c0dSopenharmony_ci     { flatbuffers::ET_SEQUENCE, 1, 1 },
311be168c0dSopenharmony_ci     { flatbuffers::ET_SEQUENCE, 1, 2 },
312be168c0dSopenharmony_ci     { flatbuffers::ET_BOOL, 0, -1 },
313be168c0dSopenharmony_ci+    { flatbuffers::ET_BOOL, 0, -1 },
314be168c0dSopenharmony_ci+    { flatbuffers::ET_UCHAR, 1, -1 },
315be168c0dSopenharmony_ci     { flatbuffers::ET_UCHAR, 1, -1 }
316be168c0dSopenharmony_ci   };
317be168c0dSopenharmony_ci   static const flatbuffers::TypeFunction type_refs[] = {
318be168c0dSopenharmony_cidiff --git a/mindspore/lite/schema/model.fbs b/mindspore/lite/schema/model.fbs
319be168c0dSopenharmony_ciindex 0b03db5bf1..7a221bdce9 100644
320be168c0dSopenharmony_ci--- a/mindspore/lite/schema/model.fbs
321be168c0dSopenharmony_ci+++ b/mindspore/lite/schema/model.fbs
322be168c0dSopenharmony_ci@@ -116,7 +116,9 @@ table MetaGraph {
323be168c0dSopenharmony_ci     allTensors: [Tensor]; // weight + input + output
324be168c0dSopenharmony_ci     subGraph : [SubGraph];
325be168c0dSopenharmony_ci     obfuscate: bool = false;
326be168c0dSopenharmony_ci+    encrypt : bool = false;
327be168c0dSopenharmony_ci     obfMetaData: [ubyte];
328be168c0dSopenharmony_ci+    decryptTable: [ubyte];
329be168c0dSopenharmony_ci }
330be168c0dSopenharmony_ci 
331be168c0dSopenharmony_ci root_type MetaGraph;
332be168c0dSopenharmony_cidiff --git a/mindspore/lite/schema/model_generated.h b/mindspore/lite/schema/model_generated.h
333be168c0dSopenharmony_ciindex 7692acbe3e..7ef01e863e 100644
334be168c0dSopenharmony_ci--- a/mindspore/lite/schema/model_generated.h
335be168c0dSopenharmony_ci+++ b/mindspore/lite/schema/model_generated.h
336be168c0dSopenharmony_ci@@ -2399,7 +2399,9 @@ struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
337be168c0dSopenharmony_ci     VT_ALLTENSORS = 18,
338be168c0dSopenharmony_ci     VT_SUBGRAPH = 20,
339be168c0dSopenharmony_ci     VT_OBFUSCATE = 22,
340be168c0dSopenharmony_ci-    VT_OBFMETADATA = 24
341be168c0dSopenharmony_ci+    VT_ENCRYPT = 24,
342be168c0dSopenharmony_ci+    VT_OBFMETADATA = 26,
343be168c0dSopenharmony_ci+    VT_DECRYPTTABLE = 28
344be168c0dSopenharmony_ci   };
345be168c0dSopenharmony_ci   const flatbuffers::String *name() const {
346be168c0dSopenharmony_ci     return GetPointer<const flatbuffers::String *>(VT_NAME);
347be168c0dSopenharmony_ci@@ -2431,9 +2433,15 @@ struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
348be168c0dSopenharmony_ci   bool obfuscate() const {
349be168c0dSopenharmony_ci     return GetField<uint8_t>(VT_OBFUSCATE, 0) != 0;
350be168c0dSopenharmony_ci   }
351be168c0dSopenharmony_ci+  bool encrypt() const {
352be168c0dSopenharmony_ci+    return GetField<uint8_t>(VT_ENCRYPT, 0) != 0;
353be168c0dSopenharmony_ci+  }
354be168c0dSopenharmony_ci   const flatbuffers::Vector<uint8_t> *obfMetaData() const {
355be168c0dSopenharmony_ci     return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_OBFMETADATA);
356be168c0dSopenharmony_ci   }
357be168c0dSopenharmony_ci+  const flatbuffers::Vector<uint8_t> *decryptTable() const {
358be168c0dSopenharmony_ci+    return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_DECRYPTTABLE);
359be168c0dSopenharmony_ci+  }
360be168c0dSopenharmony_ci   bool Verify(flatbuffers::Verifier &verifier) const {
361be168c0dSopenharmony_ci     return VerifyTableStart(verifier) &&
362be168c0dSopenharmony_ci            VerifyOffset(verifier, VT_NAME) &&
363be168c0dSopenharmony_ci@@ -2456,8 +2464,11 @@ struct MetaGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
364be168c0dSopenharmony_ci            verifier.VerifyVector(subGraph()) &&
365be168c0dSopenharmony_ci            verifier.VerifyVectorOfTables(subGraph()) &&
366be168c0dSopenharmony_ci            VerifyField<uint8_t>(verifier, VT_OBFUSCATE) &&
367be168c0dSopenharmony_ci+           VerifyField<uint8_t>(verifier, VT_ENCRYPT) &&
368be168c0dSopenharmony_ci            VerifyOffset(verifier, VT_OBFMETADATA) &&
369be168c0dSopenharmony_ci            verifier.VerifyVector(obfMetaData()) &&
370be168c0dSopenharmony_ci+           VerifyOffset(verifier, VT_DECRYPTTABLE) &&
371be168c0dSopenharmony_ci+           verifier.VerifyVector(decryptTable()) &&
372be168c0dSopenharmony_ci            verifier.EndTable();
373be168c0dSopenharmony_ci   }
374be168c0dSopenharmony_ci };
375be168c0dSopenharmony_ci@@ -2496,9 +2507,15 @@ struct MetaGraphBuilder {
376be168c0dSopenharmony_ci   void add_obfuscate(bool obfuscate) {
377be168c0dSopenharmony_ci     fbb_.AddElement<uint8_t>(MetaGraph::VT_OBFUSCATE, static_cast<uint8_t>(obfuscate), 0);
378be168c0dSopenharmony_ci   }
379be168c0dSopenharmony_ci+  void add_encrypt(bool encrypt) {
380be168c0dSopenharmony_ci+    fbb_.AddElement<uint8_t>(MetaGraph::VT_ENCRYPT, static_cast<uint8_t>(encrypt), 0);
381be168c0dSopenharmony_ci+  }
382be168c0dSopenharmony_ci   void add_obfMetaData(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> obfMetaData) {
383be168c0dSopenharmony_ci     fbb_.AddOffset(MetaGraph::VT_OBFMETADATA, obfMetaData);
384be168c0dSopenharmony_ci   }
385be168c0dSopenharmony_ci+  void add_decryptTable(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> decryptTable) {
386be168c0dSopenharmony_ci+    fbb_.AddOffset(MetaGraph::VT_DECRYPTTABLE, decryptTable);
387be168c0dSopenharmony_ci+  }
388be168c0dSopenharmony_ci   explicit MetaGraphBuilder(flatbuffers::FlatBufferBuilder &_fbb)
389be168c0dSopenharmony_ci         : fbb_(_fbb) {
390be168c0dSopenharmony_ci     start_ = fbb_.StartTable();
391be168c0dSopenharmony_ci@@ -2522,8 +2539,11 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraph(
392be168c0dSopenharmony_ci     flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<mindspore::schema::Tensor>>> allTensors = 0,
393be168c0dSopenharmony_ci     flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<mindspore::schema::SubGraph>>> subGraph = 0,
394be168c0dSopenharmony_ci     bool obfuscate = false,
395be168c0dSopenharmony_ci-    flatbuffers::Offset<flatbuffers::Vector<uint8_t>> obfMetaData = 0) {
396be168c0dSopenharmony_ci+    bool encrypt = false,
397be168c0dSopenharmony_ci+    flatbuffers::Offset<flatbuffers::Vector<uint8_t>> obfMetaData = 0,
398be168c0dSopenharmony_ci+    flatbuffers::Offset<flatbuffers::Vector<uint8_t>> decryptTable = 0) {
399be168c0dSopenharmony_ci   MetaGraphBuilder builder_(_fbb);
400be168c0dSopenharmony_ci+  builder_.add_decryptTable(decryptTable);
401be168c0dSopenharmony_ci   builder_.add_obfMetaData(obfMetaData);
402be168c0dSopenharmony_ci   builder_.add_subGraph(subGraph);
403be168c0dSopenharmony_ci   builder_.add_allTensors(allTensors);
404be168c0dSopenharmony_ci@@ -2534,6 +2554,7 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraph(
405be168c0dSopenharmony_ci   builder_.add_fmkType(fmkType);
406be168c0dSopenharmony_ci   builder_.add_version(version);
407be168c0dSopenharmony_ci   builder_.add_name(name);
408be168c0dSopenharmony_ci+  builder_.add_encrypt(encrypt);
409be168c0dSopenharmony_ci   builder_.add_obfuscate(obfuscate);
410be168c0dSopenharmony_ci   return builder_.Finish();
411be168c0dSopenharmony_ci }
412be168c0dSopenharmony_ci@@ -2550,7 +2571,9 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraphDirect(
413be168c0dSopenharmony_ci     const std::vector<flatbuffers::Offset<mindspore::schema::Tensor>> *allTensors = nullptr,
414be168c0dSopenharmony_ci     const std::vector<flatbuffers::Offset<mindspore::schema::SubGraph>> *subGraph = nullptr,
415be168c0dSopenharmony_ci     bool obfuscate = false,
416be168c0dSopenharmony_ci-    const std::vector<uint8_t> *obfMetaData = nullptr) {
417be168c0dSopenharmony_ci+    bool encrypt = false,
418be168c0dSopenharmony_ci+    const std::vector<uint8_t> *obfMetaData = nullptr,
419be168c0dSopenharmony_ci+    const std::vector<uint8_t> *decryptTable = nullptr) {
420be168c0dSopenharmony_ci   auto name__ = name ? _fbb.CreateString(name) : 0;
421be168c0dSopenharmony_ci   auto version__ = version ? _fbb.CreateString(version) : 0;
422be168c0dSopenharmony_ci   auto inputIndex__ = inputIndex ? _fbb.CreateVector<uint32_t>(*inputIndex) : 0;
423be168c0dSopenharmony_ci@@ -2559,6 +2582,7 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraphDirect(
424be168c0dSopenharmony_ci   auto allTensors__ = allTensors ? _fbb.CreateVector<flatbuffers::Offset<mindspore::schema::Tensor>>(*allTensors) : 0;
425be168c0dSopenharmony_ci   auto subGraph__ = subGraph ? _fbb.CreateVector<flatbuffers::Offset<mindspore::schema::SubGraph>>(*subGraph) : 0;
426be168c0dSopenharmony_ci   auto obfMetaData__ = obfMetaData ? _fbb.CreateVector<uint8_t>(*obfMetaData) : 0;
427be168c0dSopenharmony_ci+  auto decryptTable__ = decryptTable ? _fbb.CreateVector<uint8_t>(*decryptTable) : 0;
428be168c0dSopenharmony_ci   return mindspore::schema::CreateMetaGraph(
429be168c0dSopenharmony_ci       _fbb,
430be168c0dSopenharmony_ci       name__,
431be168c0dSopenharmony_ci@@ -2571,7 +2595,9 @@ inline flatbuffers::Offset<MetaGraph> CreateMetaGraphDirect(
432be168c0dSopenharmony_ci       allTensors__,
433be168c0dSopenharmony_ci       subGraph__,
434be168c0dSopenharmony_ci       obfuscate,
435be168c0dSopenharmony_ci-      obfMetaData__);
436be168c0dSopenharmony_ci+      encrypt,
437be168c0dSopenharmony_ci+      obfMetaData__,
438be168c0dSopenharmony_ci+      decryptTable__);
439be168c0dSopenharmony_ci }
440be168c0dSopenharmony_ci 
441be168c0dSopenharmony_ci inline const mindspore::schema::MetaGraph *GetMetaGraph(const void *buf) {
442be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt
443be168c0dSopenharmony_ciindex 470334730f..4293918967 100644
444be168c0dSopenharmony_ci--- a/mindspore/lite/src/CMakeLists.txt
445be168c0dSopenharmony_ci+++ b/mindspore/lite/src/CMakeLists.txt
446be168c0dSopenharmony_ci@@ -633,11 +633,6 @@ if(NOT WIN32)
447be168c0dSopenharmony_ci     target_link_libraries(mindspore-lite dl)
448be168c0dSopenharmony_ci endif()
449be168c0dSopenharmony_ci 
450be168c0dSopenharmony_ci-if(MSLITE_ENABLE_MODEL_OBF)
451be168c0dSopenharmony_ci-    target_link_libraries(mindspore-lite ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
452be168c0dSopenharmony_ci-    target_link_libraries(mindspore-lite_static ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
453be168c0dSopenharmony_ci-endif()
454be168c0dSopenharmony_ci-
455be168c0dSopenharmony_ci if(MSLITE_ENABLE_KERNEL_EXECUTOR)
456be168c0dSopenharmony_ci     target_link_libraries(mindspore-lite mindspore_core)
457be168c0dSopenharmony_ci     target_link_libraries(mindspore-lite_static mindspore_core)
458be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/executor/CMakeLists.txt b/mindspore/lite/src/executor/CMakeLists.txt
459be168c0dSopenharmony_ciindex deadda8e36..5ccea72dfb 100644
460be168c0dSopenharmony_ci--- a/mindspore/lite/src/executor/CMakeLists.txt
461be168c0dSopenharmony_ci+++ b/mindspore/lite/src/executor/CMakeLists.txt
462be168c0dSopenharmony_ci@@ -289,6 +289,3 @@ if(NOT WIN32)
463be168c0dSopenharmony_ci     target_link_libraries(lite-unified-executor dl)
464be168c0dSopenharmony_ci endif()
465be168c0dSopenharmony_ci 
466be168c0dSopenharmony_ci-if(ENABLE_MODEL_OBF)
467be168c0dSopenharmony_ci-    target_link_libraries(lite-unified-executor ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
468be168c0dSopenharmony_ci-endif()
469be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt
470be168c0dSopenharmony_ciindex 6dc3a944ef..6b92bfcd74 100644
471be168c0dSopenharmony_ci--- a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt
472be168c0dSopenharmony_ci+++ b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt
473be168c0dSopenharmony_ci@@ -301,6 +301,3 @@ if(NOT WIN32)
474be168c0dSopenharmony_ci     target_link_libraries(msplugin-ge-litert dl)
475be168c0dSopenharmony_ci endif()
476be168c0dSopenharmony_ci 
477be168c0dSopenharmony_ci-if(ENABLE_MODEL_OBF)
478be168c0dSopenharmony_ci-    target_link_libraries(msplugin-ge-litert ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
479be168c0dSopenharmony_ci-endif()
480be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/lite_model.cc b/mindspore/lite/src/litert/lite_model.cc
481be168c0dSopenharmony_ciindex 13652633b8..b038831b1f 100644
482be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/lite_model.cc
483be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/lite_model.cc
484be168c0dSopenharmony_ci@@ -32,6 +32,7 @@
485be168c0dSopenharmony_ci #include "src/tensor.h"
486be168c0dSopenharmony_ci #include "extendrt/mindir_loader/model_loader.h"
487be168c0dSopenharmony_ci #include "src/common/mmap_utils.h"
488be168c0dSopenharmony_ci+#include <dlfcn.h>
489be168c0dSopenharmony_ci 
490be168c0dSopenharmony_ci namespace mindspore::lite {
491be168c0dSopenharmony_ci namespace {
492be168c0dSopenharmony_ci@@ -69,12 +70,9 @@ void LiteModel::Free() {
493be168c0dSopenharmony_ci   }
494be168c0dSopenharmony_ci   inner_all_tensors_.clear();
495be168c0dSopenharmony_ci 
496be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
497be168c0dSopenharmony_ci-  for (auto &prim : graph_.deobf_prims_) {
498be168c0dSopenharmony_ci-    free(prim);
499be168c0dSopenharmony_ci+  if(this->deobf != nullptr){
500be168c0dSopenharmony_ci+    delete(reinterpret_cast<DeObfProcessor *>(this->deobf));
501be168c0dSopenharmony_ci   }
502be168c0dSopenharmony_ci-  graph_.deobf_prims_.resize(0);
503be168c0dSopenharmony_ci-#endif
504be168c0dSopenharmony_ci }
505be168c0dSopenharmony_ci 
506be168c0dSopenharmony_ci void LiteModel::Destroy() {
507be168c0dSopenharmony_ci@@ -385,6 +383,12 @@ bool LiteModel::ModelVerify() const {
508be168c0dSopenharmony_ci 
509be168c0dSopenharmony_ci   return NodeVerify() == RET_OK && SubGraphVerify() == RET_OK;
510be168c0dSopenharmony_ci }
511be168c0dSopenharmony_ci+//static variable used for deobfuscator
512be168c0dSopenharmony_ci+ObfCreateFunc DeObfRegister::NewDeObfProcessor = DeObfRegister::Fail;
513be168c0dSopenharmony_ci+bool (DeObfProcessor::*DeObfRegister::GetModelDeObfReg)(const void *meta_graph, Model *model);
514be168c0dSopenharmony_ci+void (DeObfProcessor::*DeObfRegister::DeObfuscateReg)(Model *model);
515be168c0dSopenharmony_ci+DeObfRet (DeObfProcessor::*DeObfRegister::CreateDeObfNodeReg)(const schema::Primitive *&src_prim, int i, int schema__version);
516be168c0dSopenharmony_ci+void *DeObfRegister::deobf_handle = nullptr;
517be168c0dSopenharmony_ci 
518be168c0dSopenharmony_ci int LiteModel::GenerateModelByVersion() {
519be168c0dSopenharmony_ci   if (this->buf == nullptr) {
520be168c0dSopenharmony_ci@@ -397,33 +401,37 @@ int LiteModel::GenerateModelByVersion() {
521be168c0dSopenharmony_ci   }
522be168c0dSopenharmony_ci   MS_ASSERT(meta_graph != nullptr);
523be168c0dSopenharmony_ci   int status = RET_ERROR;
524be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
525be168c0dSopenharmony_ci-  DeObfuscator *model_deobf = nullptr;
526be168c0dSopenharmony_ci-#endif
527be168c0dSopenharmony_ci+  if(dlopen("libdeobfuscator_lib.z.so", RTLD_NOLOAD) == nullptr) {
528be168c0dSopenharmony_ci+    DeObfRegister::deobf_handle = dlopen("libdeobfuscator_lib.z.so", RTLD_NOW | RTLD_GLOBAL);
529be168c0dSopenharmony_ci+  }
530be168c0dSopenharmony_ci+  if(DeObfRegister::deobf_handle == nullptr) {
531be168c0dSopenharmony_ci+    MS_LOG(WARNING) << "Deobfuscate ability is disabled, so obfuscated models can not be executed.";
532be168c0dSopenharmony_ci+  } else {
533be168c0dSopenharmony_ci+    auto CreateDeObfFunc = reinterpret_cast<ObfCreateFunc>(dlsym(DeObfRegister::deobf_handle, "CreateDeObfFunc"));
534be168c0dSopenharmony_ci+    if (CreateDeObfFunc == nullptr) {
535be168c0dSopenharmony_ci+      MS_LOG(WARNING) << "cannot fetch CreateDeObfFunc";
536be168c0dSopenharmony_ci+    } else {
537be168c0dSopenharmony_ci+      DeObfRegister::RegisterDeObfuscator(CreateDeObfFunc);
538be168c0dSopenharmony_ci+      DeObfRegister::NewDeObfProcessor(*this);
539be168c0dSopenharmony_ci+    }
540be168c0dSopenharmony_ci+  }
541be168c0dSopenharmony_ci   if (schema_version_ == SCHEMA_VERSION::SCHEMA_CUR) {
542be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
543be168c0dSopenharmony_ci-    if (IsMetaGraphObfuscated<schema::MetaGraph>(*reinterpret_cast<const schema::MetaGraph *>(meta_graph))) {
544be168c0dSopenharmony_ci-      model_deobf = GetModelDeObfuscator<schema::MetaGraph>(*reinterpret_cast<const schema::MetaGraph *>(meta_graph),
545be168c0dSopenharmony_ci-                                                            this, this->buf_size_);
546be168c0dSopenharmony_ci-      this->graph_.model_obfuscated_ = true;
547be168c0dSopenharmony_ci-      if (model_deobf == nullptr) {
548be168c0dSopenharmony_ci+    if(this->deobf != nullptr) {
549be168c0dSopenharmony_ci+      auto deobf_ptr = reinterpret_cast<DeObfProcessor *>(this->deobf);
550be168c0dSopenharmony_ci+      auto ret = (deobf_ptr->*DeObfRegister::GetModelDeObfReg)(meta_graph, this);
551be168c0dSopenharmony_ci+      if(!ret){
552be168c0dSopenharmony_ci         return RET_ERROR;
553be168c0dSopenharmony_ci       }
554be168c0dSopenharmony_ci     }
555be168c0dSopenharmony_ci-#endif
556be168c0dSopenharmony_ci     status = GenerateModel<schema::MetaGraph, schema::CNode>(*reinterpret_cast<const schema::MetaGraph *>(meta_graph));
557be168c0dSopenharmony_ci   }
558be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
559be168c0dSopenharmony_ci-  if (this->graph_.model_obfuscated_) {
560be168c0dSopenharmony_ci-    MS_ASSERT(model_deobf != nullptr);
561be168c0dSopenharmony_ci-    status = DeObfuscateModel(this, model_deobf);
562be168c0dSopenharmony_ci-    if (status != RET_OK) {
563be168c0dSopenharmony_ci-      MS_LOG(ERROR) << "deobfuscate model wrong.";
564be168c0dSopenharmony_ci-      std::cerr << "deobfuscate model wrong." << std::endl;
565be168c0dSopenharmony_ci-    }
566be168c0dSopenharmony_ci-    delete (model_deobf);
567be168c0dSopenharmony_ci+  if(this->deobf != nullptr) {
568be168c0dSopenharmony_ci+    auto deobf_ptr = reinterpret_cast<DeObfProcessor *>(this->deobf);
569be168c0dSopenharmony_ci+    (deobf_ptr->*DeObfRegister::DeObfuscateReg)(this);
570be168c0dSopenharmony_ci+  }
571be168c0dSopenharmony_ci+  if(DeObfRegister::deobf_handle != nullptr) {
572be168c0dSopenharmony_ci+    dlclose(DeObfRegister::deobf_handle);
573be168c0dSopenharmony_ci   }
574be168c0dSopenharmony_ci-#endif
575be168c0dSopenharmony_ci   if (this->graph_.version_ != Version()) {
576be168c0dSopenharmony_ci     MS_LOG(INFO) << "model version is " << this->graph_.version_ << ", inference version is " << Version()
577be168c0dSopenharmony_ci                  << " not equal";
578be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/lite_model.h b/mindspore/lite/src/litert/lite_model.h
579be168c0dSopenharmony_ciindex 635b529a5f..647746a23a 100644
580be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/lite_model.h
581be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/lite_model.h
582be168c0dSopenharmony_ci@@ -29,13 +29,11 @@
583be168c0dSopenharmony_ci #include "src/litert/schema_tensor_wrapper.h"
584be168c0dSopenharmony_ci #include "nnacl/op_base.h"
585be168c0dSopenharmony_ci #include "src/common/prim_util.h"
586be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
587be168c0dSopenharmony_ci-#include "tools/obfuscator/include/deobfuscator.h"
588be168c0dSopenharmony_ci-#endif
589be168c0dSopenharmony_ci #include "include/api/types.h"
590be168c0dSopenharmony_ci #ifdef ENABLE_LITE_HELPER
591be168c0dSopenharmony_ci #include "src/common/helper/infer_helpers.h"
592be168c0dSopenharmony_ci #endif
593be168c0dSopenharmony_ci+#include "include/registry/deobf_processor.h"
594be168c0dSopenharmony_ci 
595be168c0dSopenharmony_ci namespace mindspore {
596be168c0dSopenharmony_ci namespace lite {
597be168c0dSopenharmony_ci@@ -147,38 +145,23 @@ class MS_API LiteModel : public Model {
598be168c0dSopenharmony_ci       auto c_node = meta_graph.nodes()->template GetAs<U>(i);
599be168c0dSopenharmony_ci       MS_CHECK_TRUE_MSG(c_node != nullptr, false, "get as cnode fail!");
600be168c0dSopenharmony_ci       node->node_type_ = GetPrimitiveType(c_node->primitive(), schema_version_);
601be168c0dSopenharmony_ci-#ifdef ENABLE_MODEL_OBF
602be168c0dSopenharmony_ci-      auto src_prim = reinterpret_cast<const schema::Primitive *>(c_node->primitive());
603be168c0dSopenharmony_ci-      if (src_prim == nullptr) {
604be168c0dSopenharmony_ci-        delete node;
605be168c0dSopenharmony_ci-        return false;
606be168c0dSopenharmony_ci-      }
607be168c0dSopenharmony_ci-      auto src_prim_type = src_prim->value_type();
608be168c0dSopenharmony_ci-      unsigned char *dst_prim = nullptr;
609be168c0dSopenharmony_ci-      if (src_prim_type == schema::PrimitiveType_GenOP) {
610be168c0dSopenharmony_ci-        if (i >= this->graph_.all_nodes_stat_.size() || i >= this->graph_.all_prims_type_.size()) {
611be168c0dSopenharmony_ci+      if(this->deobf != nullptr){
612be168c0dSopenharmony_ci+        auto src_prim = reinterpret_cast<const schema::Primitive *>(c_node->primitive());
613be168c0dSopenharmony_ci+        auto deobf_ptr = reinterpret_cast<DeObfProcessor *>(this->deobf);
614be168c0dSopenharmony_ci+        DeObfRet ret = (deobf_ptr->*DeObfRegister::CreateDeObfNodeReg)(src_prim,i,schema_version_);
615be168c0dSopenharmony_ci+        if(ret == kDeObfFailed){
616be168c0dSopenharmony_ci           delete node;
617be168c0dSopenharmony_ci           return false;
618be168c0dSopenharmony_ci         }
619be168c0dSopenharmony_ci-        auto src_node_stat = this->graph_.all_nodes_stat_[i];
620be168c0dSopenharmony_ci-        auto dst_prim_type = this->graph_.all_prims_type_[i];
621be168c0dSopenharmony_ci-        auto ret = DeObfuscatePrimitive(src_prim, src_node_stat, &dst_prim, schema::PrimitiveType(dst_prim_type));
622be168c0dSopenharmony_ci-        if (!ret) {
623be168c0dSopenharmony_ci-          MS_LOG(ERROR) << "Deobfuscate primitive failed!";
624be168c0dSopenharmony_ci-          delete node;
625be168c0dSopenharmony_ci-          return false;
626be168c0dSopenharmony_ci-        }
627be168c0dSopenharmony_ci-        if (dst_prim == nullptr) {
628be168c0dSopenharmony_ci+        if(ret == kNoObf){
629be168c0dSopenharmony_ci           this->graph_.all_nodes_.push_back(node);
630be168c0dSopenharmony_ci           continue;
631be168c0dSopenharmony_ci         }
632be168c0dSopenharmony_ci-        this->graph_.deobf_prims_.push_back(dst_prim);
633be168c0dSopenharmony_ci-        src_prim = reinterpret_cast<const schema::Primitive *>(flatbuffers::GetRoot<schema::Primitive>(dst_prim));
634be168c0dSopenharmony_ci+        node->primitive_ = const_cast<schema::Primitive *>(src_prim);
635be168c0dSopenharmony_ci+      }
636be168c0dSopenharmony_ci+      else{
637be168c0dSopenharmony_ci+        node->primitive_ = c_node->primitive();
638be168c0dSopenharmony_ci       }
639be168c0dSopenharmony_ci-      node->primitive_ = const_cast<schema::Primitive *>(src_prim);
640be168c0dSopenharmony_ci-#else
641be168c0dSopenharmony_ci-      node->primitive_ = c_node->primitive();
642be168c0dSopenharmony_ci-#endif
643be168c0dSopenharmony_ci       auto status = SetQuantType(meta_graph, c_node, node);
644be168c0dSopenharmony_ci       if (status == RET_ERROR) {
645be168c0dSopenharmony_ci         return false;
646be168c0dSopenharmony_cidiff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt
647be168c0dSopenharmony_ciindex 78dab536e6..3f12ec807b 100644
648be168c0dSopenharmony_ci--- a/mindspore/lite/test/CMakeLists.txt
649be168c0dSopenharmony_ci+++ b/mindspore/lite/test/CMakeLists.txt
650be168c0dSopenharmony_ci@@ -240,10 +240,6 @@ if(MSLITE_ENABLE_CONVERTER)
651be168c0dSopenharmony_ci                                     onnx_parser_mid tf_parser_mid third_party_parser_mid)
652be168c0dSopenharmony_ci endif()
653be168c0dSopenharmony_ci 
654be168c0dSopenharmony_ci-if(MSLITE_ENABLE_MODEL_OBF)
655be168c0dSopenharmony_ci-    target_link_libraries(lite-test ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
656be168c0dSopenharmony_ci-endif()
657be168c0dSopenharmony_ci-
658be168c0dSopenharmony_ci if(MSLITE_ENABLE_KERNEL_EXECUTOR)
659be168c0dSopenharmony_ci     target_link_libraries(lite-test kernel_executor)
660be168c0dSopenharmony_ci endif()
661be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/obfuscator/include/deobf_creator.h b/mindspore/lite/tools/obfuscator/include/deobf_creator.h
662be168c0dSopenharmony_cinew file mode 100644
663be168c0dSopenharmony_ciindex 0000000000..506eccd8d1
664be168c0dSopenharmony_ci--- /dev/null
665be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/obfuscator/include/deobf_creator.h
666be168c0dSopenharmony_ci@@ -0,0 +1,7 @@
667be168c0dSopenharmony_ci+#include "include/registry/deobf_processor.h"
668be168c0dSopenharmony_ci+
669be168c0dSopenharmony_ci+namespace mindspore::lite{
670be168c0dSopenharmony_ci+
671be168c0dSopenharmony_ci+    extern "C" void CreateDeObfFunc(Model &model);
672be168c0dSopenharmony_ci+
673be168c0dSopenharmony_ci+}//mindspore::lite
674be168c0dSopenharmony_ci\ No newline at end of file
675