MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / decrypt_memory

Method decrypt_memory

lite/src/parse_model/model_parser.cpp:125–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125std::shared_ptr<void> ModelParser::decrypt_memory(
126 const uint8_t* data, size_t length, const std::string decryption_name,
127 size_t& result_length) const {
128 const uint8_t* memory_ptr = data;
129 if (decryption_name == "NONE") {
130 result_length = length;
131 std::shared_ptr<uint8_t> shptr{
132 new uint8_t[length], [](uint8_t* p) { delete[] p; }};
133 memcpy(shptr.get(), data, length);
134 return shptr;
135 }
136 LITE_LOCK_GUARD(decryption_static_data().map_mutex);
137 auto it = decryption_static_data().decryption_methods.find(decryption_name);
138 if (it == decryption_static_data().decryption_methods.end()) {
139 LITE_THROW(ssprintf(
140 "The decryption method %s is not registed yet.",
141 decryption_name.c_str()));
142 }
143 auto&& func = it->second.first;
144 auto&& key = it->second.second;
145 if (func) {
146 auto model_vector = func(memory_ptr, length, *key);
147 result_length = model_vector.size();
148 auto tmp_model_vector = new std::vector<uint8_t>(std::move(model_vector));
149 return std::shared_ptr<void>(
150 tmp_model_vector->data(),
151 [tmp_model_vector](void*) { delete tmp_model_vector; });
152 } else {
153 LITE_THROW(ssprintf(
154 "No decryption function in %s method.", decryption_name.c_str()));
155 }
156}
157
158// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

Callers

nothing calls this directly

Calls 6

funcFunction · 0.50
getMethod · 0.45
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected