!369 Execute abc in safe memory

Merge pull request !369 from xliu/secure_mem
This commit is contained in:
openharmony_ci 2023-05-15 02:57:49 +00:00 committed by Gitee
commit 90acfc21cc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 31 additions and 0 deletions

View File

@ -298,6 +298,23 @@ std::unique_ptr<const File> OpenPandaFileFromMemory(const void *buffer, size_t s
return panda_file::File::OpenFromMemory(std::move(ptr), std::to_string(hash(mem)));
}
std::unique_ptr<const File> OpenPandaFileFromSecureMemory(uint8_t *buffer, size_t size)
{
if (buffer == nullptr) {
return nullptr;
}
std::byte *mem = reinterpret_cast<std::byte *>(buffer);
os::mem::ConstBytePtr ptr(mem, size, nullptr);
if (ptr.Get() == nullptr) {
PLOG(ERROR, PANDAFILE) << "Failed to open panda file from secure memory'";
return nullptr;
}
std::hash<std::byte *> hash;
return panda_file::File::OpenFromMemory(std::move(ptr), std::to_string(hash(mem)));
}
class ClassIdxIterator {
public:
using value_type = const uint8_t *;

View File

@ -479,6 +479,11 @@ std::unique_ptr<const File> OpenPandaFileOrZip(std::string_view location,
*/
std::unique_ptr<const File> OpenPandaFileFromMemory(const void *buffer, size_t size);
/*
* OpenPandaFileFromMemory from secure buffer.
*/
std::unique_ptr<const File> OpenPandaFileFromSecureMemory(uint8_t *buffer, size_t size);
/*
* OpenPandaFile from location which specicify the name.
*/

View File

@ -166,6 +166,15 @@ HWTEST(File, OpenPandaFileFromMemory, testing::ext::TestSize.Level0)
EXPECT_EQ(pf, nullptr);
}
HWTEST(File, OpenPandaFileFromSecureMemory, testing::ext::TestSize.Level0)
{
auto pf = OpenPandaFileFromSecureMemory(nullptr, -1);
EXPECT_EQ(pf, nullptr);
pf = OpenPandaFileFromSecureMemory(nullptr, 1U);
EXPECT_EQ(pf, nullptr);
}
HWTEST(File, OpenPandaFileFromZipNameAnonMem, testing::ext::TestSize.Level0)
{
// Create ZIP