mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 01:10:52 +00:00
cherry pick ff82e6a
from https://gitee.com/anluohan/ability_ability_runtime/pulls/10475
Revert "回退 'Pull Request !9388 : worker pac'"
This reverts commit 1d74457c4c
.
Signed-off-by: zhuhan <zhuhan10@huawei.com>
Change-Id: Ie3a95e78ec9b5b8b612d6b915e57e1a414da9768
This commit is contained in:
parent
5101e74947
commit
988f16f67f
@ -1507,15 +1507,15 @@ void JsRuntime::InitWorkerModule(const Options& options)
|
||||
{
|
||||
CHECK_POINTER(jsEnv_);
|
||||
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
|
||||
workerInfo->codePath = options.codePath;
|
||||
workerInfo->codePath = panda::panda_file::StringPacProtect(options.codePath);
|
||||
workerInfo->isDebugVersion = options.isDebugVersion;
|
||||
workerInfo->isBundle = options.isBundle;
|
||||
workerInfo->packagePathStr = options.packagePathStr;
|
||||
workerInfo->assetBasePathStr = options.assetBasePathStr;
|
||||
workerInfo->hapPath = options.hapPath;
|
||||
workerInfo->isStageModel = options.isStageModel;
|
||||
workerInfo->hapPath = panda::panda_file::StringPacProtect(options.hapPath);
|
||||
workerInfo->isStageModel = panda::panda_file::BoolPacProtect(options.isStageModel);
|
||||
workerInfo->moduleName = options.moduleName;
|
||||
workerInfo->apiTargetVersion = options.apiTargetVersion;
|
||||
workerInfo->apiTargetVersion = panda::panda_file::DataProtect(static_cast<uintptr_t>(options.apiTargetVersion));
|
||||
if (options.isJsFramework) {
|
||||
SetJsFramework();
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buf
|
||||
if (uri.find_first_of("/") == 0) {
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with /modulename");
|
||||
realPath = uri.substr(1);
|
||||
} else if (uri.find("../") == 0 && !workerInfo_->isStageModel) {
|
||||
} else if (uri.find("../") == 0 && !GetIsStageModel()) {
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with ../");
|
||||
realPath = uri.substr(PATH_THREE);
|
||||
} else if (uri.find_first_of("@") == 0) {
|
||||
@ -206,10 +206,10 @@ void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buf
|
||||
filePath = NormalizedFileName(realPath);
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "filePath %{private}s", filePath.c_str());
|
||||
|
||||
if (!workerInfo_->isStageModel) {
|
||||
if (!GetIsStageModel()) {
|
||||
GetAmi(ami, filePath);
|
||||
} else {
|
||||
ami = workerInfo_->codePath + filePath;
|
||||
ami = (workerInfo_->codePath).GetOriginString() + filePath;
|
||||
}
|
||||
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
|
||||
@ -250,10 +250,11 @@ void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buf
|
||||
|
||||
filePath = NormalizedFileName(realPath);
|
||||
// for safe reason, filePath must starts with 'abcs/' in restricted env
|
||||
if (isRestricted && filePath.find(RESTRICTED_PREFIX_PATH) && workerInfo_->apiTargetVersion >= API12) {
|
||||
if (isRestricted && filePath.find(RESTRICTED_PREFIX_PATH)
|
||||
&& (static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer())) >= API12) {
|
||||
filePath = RESTRICTED_PREFIX_PATH + filePath;
|
||||
}
|
||||
ami = workerInfo_->codePath + filePath;
|
||||
ami = (workerInfo_->codePath).GetOriginString() + filePath;
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
|
||||
if (ami.find(CACHE_DIRECTORY) != std::string::npos) {
|
||||
if (!ReadAmiData(ami, buff, buffSize, content, useSecureMem, isRestricted)) {
|
||||
@ -314,9 +315,10 @@ bool AssetHelper::ReadAmiData(const std::string& ami, uint8_t** buff, size_t* bu
|
||||
bool& useSecureMem, bool isRestricted)
|
||||
{
|
||||
// Current function is a private, validity of workerInfo_ has been checked by caller.
|
||||
bool apiSatisfy = workerInfo_->apiTargetVersion == 0 || workerInfo_->apiTargetVersion > API8;
|
||||
if (workerInfo_->isStageModel && !isRestricted && apiSatisfy) {
|
||||
if (workerInfo_->apiTargetVersion >= API12) {
|
||||
int32_t apiTargetVersion = static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer());
|
||||
bool apiSatisfy = apiTargetVersion == 0 || apiTargetVersion > API8;
|
||||
if (GetIsStageModel() && !isRestricted && apiSatisfy) {
|
||||
if (apiTargetVersion >= API12) {
|
||||
useSecureMem = true;
|
||||
return GetSafeData(ami, buff, buffSize);
|
||||
} else if (GetSafeData(ami, buff, buffSize)) {
|
||||
@ -380,8 +382,8 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff,
|
||||
|
||||
std::string newHapPath;
|
||||
size_t pos = filePath.find('/');
|
||||
if (!workerInfo_->isStageModel) {
|
||||
newHapPath = workerInfo_->hapPath;
|
||||
if (!GetIsStageModel()) {
|
||||
newHapPath = (workerInfo_->hapPath).GetOriginString();
|
||||
} else {
|
||||
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
|
||||
if (hapModuleInfo.moduleName == filePath.substr(0, pos)) {
|
||||
@ -401,7 +403,7 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff,
|
||||
std::unique_ptr<uint8_t[]> dataPtr = nullptr;
|
||||
std::string realfilePath;
|
||||
size_t fileLen = 0;
|
||||
if (!workerInfo_->isStageModel) {
|
||||
if (!GetIsStageModel()) {
|
||||
bool flag = false;
|
||||
for (const auto& basePath : workerInfo_->assetBasePathStr) {
|
||||
realfilePath = basePath + filePath;
|
||||
@ -418,11 +420,12 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff,
|
||||
} else {
|
||||
realfilePath = filePath.substr(pos + 1);
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "realfilePath: %{private}s", realfilePath.c_str());
|
||||
bool apiSatisfy = workerInfo_->apiTargetVersion == 0 || workerInfo_->apiTargetVersion > API8;
|
||||
if (workerInfo_->isStageModel && !isRestricted && apiSatisfy && !extractor->IsHapCompress(realfilePath)) {
|
||||
int32_t apiTargetVersion = static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer());
|
||||
bool apiSatisfy = apiTargetVersion == 0 || apiTargetVersion > API8;
|
||||
if (GetIsStageModel() && !isRestricted && apiSatisfy && !extractor->IsHapCompress(realfilePath)) {
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "Use secure mem.");
|
||||
auto safeData = extractor->GetSafeData(realfilePath);
|
||||
if (workerInfo_->apiTargetVersion >= API12) {
|
||||
if (apiTargetVersion >= API12) {
|
||||
useSecureMem = true;
|
||||
if (safeData == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "Get secure mem failed, file %{private}s", filePath.c_str());
|
||||
@ -462,7 +465,7 @@ void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
|
||||
std::string fileName = filePath.substr(slashPos + 1);
|
||||
std::string path = filePath.substr(0, slashPos + 1);
|
||||
|
||||
std::string loadPath = ExtractorUtil::GetLoadFilePath(workerInfo_->hapPath);
|
||||
std::string loadPath = ExtractorUtil::GetLoadFilePath((workerInfo_->hapPath).GetOriginString());
|
||||
bool newCreate = false;
|
||||
std::shared_ptr<Extractor> extractor = ExtractorUtil::GetExtractor(loadPath, newCreate);
|
||||
if (extractor == nullptr) {
|
||||
@ -496,7 +499,7 @@ void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
|
||||
}
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "targetFilePath %{public}s", targetFilePath.c_str());
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "targetFilePath %{private}s", targetFilePath.c_str());
|
||||
|
||||
if (!flag) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "get targetFilePath failed");
|
||||
@ -507,12 +510,19 @@ void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
|
||||
std::string filePathName = basePath + targetFilePath;
|
||||
bool hasFile = extractor->HasEntry(filePathName);
|
||||
if (hasFile) {
|
||||
ami = workerInfo_->hapPath + "/" + filePathName;
|
||||
ami = (workerInfo_->hapPath).GetOriginString() + "/" + filePathName;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AssetHelper::GetIsStageModel()
|
||||
{
|
||||
bool stageModule = workerInfo_->isStageModel.GetBool();
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "stagemodule: %{public}d", stageModule);
|
||||
return stageModule;
|
||||
}
|
||||
|
||||
int32_t GetContainerId()
|
||||
{
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
|
@ -35,8 +35,9 @@ class AssetHelper final {
|
||||
public:
|
||||
explicit AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo) : workerInfo_(workerInfo)
|
||||
{
|
||||
if (!(workerInfo_->codePath).empty() && (workerInfo->codePath).back() != '/') {
|
||||
(workerInfo_->codePath).append("/");
|
||||
panda::panda_file::StringPacProtect codePath = panda::panda_file::StringPacProtect(workerInfo_->codePath);
|
||||
if (!(codePath.GetOriginString()).empty() && (codePath.GetOriginString()).back() != '/') {
|
||||
(workerInfo_->codePath).Append('/');
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +58,8 @@ private:
|
||||
void GetAmi(std::string& ami, const std::string& filePath);
|
||||
|
||||
bool GetSafeData(const std::string& ami, uint8_t** buff, size_t* buffSize);
|
||||
|
||||
bool GetIsStageModel();
|
||||
|
||||
std::shared_ptr<JsEnv::WorkerInfo> workerInfo_ = nullptr;
|
||||
int fd_ = -1;
|
||||
|
@ -314,13 +314,13 @@ void NativeRuntimeImpl::InitWorkerModule(const Options& options, const std::shar
|
||||
}
|
||||
|
||||
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
|
||||
workerInfo->codePath = options.codePath;
|
||||
workerInfo->codePath = panda::panda_file::StringPacProtect(options.codePath);
|
||||
workerInfo->isDebugVersion = options.isDebugVersion;
|
||||
workerInfo->isBundle = options.isBundle;
|
||||
workerInfo->packagePathStr = options.packagePathStr;
|
||||
workerInfo->assetBasePathStr = options.assetBasePathStr;
|
||||
workerInfo->hapPath = options.hapPath;
|
||||
workerInfo->isStageModel = options.isStageModel;
|
||||
workerInfo->hapPath = panda::panda_file::StringPacProtect(options.hapPath);
|
||||
workerInfo->isStageModel = panda::panda_file::BoolPacProtect(options.isStageModel);
|
||||
workerInfo->moduleName = options.moduleName;
|
||||
if (options.isJsFramework) {
|
||||
SetJsFramework();
|
||||
|
@ -169,7 +169,7 @@ void OHOSJsEnvironmentImpl::InitWorkerModule(NativeEngine* engine, std::shared_p
|
||||
engine->SetInitWorkerFunc(InitWorkerFunc);
|
||||
engine->SetOffWorkerFunc(OffWorkerFunc);
|
||||
engine->SetGetAssetFunc(AssetHelper(workerInfo));
|
||||
engine->SetApiVersion(workerInfo->apiTargetVersion);
|
||||
engine->SetApiVersion(static_cast<int32_t>(workerInfo->apiTargetVersion.GetOriginPointer()));
|
||||
|
||||
engine->SetGetContainerScopeIdFunc(GetContainerId);
|
||||
engine->SetInitContainerScopeFunc(UpdateContainerScope);
|
||||
|
@ -22,18 +22,20 @@
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
#include "data_protect.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace JsEnv {
|
||||
struct WorkerInfo {
|
||||
std::string codePath;
|
||||
panda::panda_file::StringPacProtect codePath;
|
||||
bool isDebugVersion = false;
|
||||
bool isBundle = true;
|
||||
std::string packagePathStr;
|
||||
std::vector<std::string> assetBasePathStr;
|
||||
std::string hapPath;
|
||||
bool isStageModel = true;
|
||||
panda::panda_file::StringPacProtect hapPath;
|
||||
panda::panda_file::BoolPacProtect isStageModel = panda::panda_file::BoolPacProtect(true);
|
||||
std::string moduleName;
|
||||
int32_t apiTargetVersion = 0;
|
||||
panda::panda_file::DataProtect apiTargetVersion = panda::panda_file::DataProtect();
|
||||
};
|
||||
|
||||
class JsEnvironmentImpl {
|
||||
|
@ -66,9 +66,9 @@ sptr<Token> GetFuzzAbilityToken()
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
|
||||
workerInfo->codePath = "/data/test/codePath";
|
||||
workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath");
|
||||
workerInfo->packagePathStr = "/data/test/packagePath";
|
||||
workerInfo->hapPath = "/data/test/hapPath";
|
||||
workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath");
|
||||
workerInfo->moduleName = "moduleName";
|
||||
AbilityRuntime::AssetHelper helper = AbilityRuntime::AssetHelper(workerInfo);
|
||||
std::string jsonStr(data, size);
|
||||
|
@ -74,9 +74,9 @@ GetAssetFunc JsWorkerTest::TestGetGetAssetFunc() const
|
||||
HWTEST_F(JsWorkerTest, AssetHelper_0100, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
|
||||
workerInfo->codePath = "/data/test/codePath";
|
||||
workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath");
|
||||
workerInfo->packagePathStr = "/data/test/packagePath";
|
||||
workerInfo->hapPath = "/data/test/hapPath";
|
||||
workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath");
|
||||
workerInfo->moduleName = "moduleName";
|
||||
TestSetGetAssetFunc(AssetHelper(workerInfo));
|
||||
|
||||
@ -101,9 +101,9 @@ HWTEST_F(JsWorkerTest, AssetHelper_0100, TestSize.Level1)
|
||||
HWTEST_F(JsWorkerTest, AssetHelper_0200, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
|
||||
workerInfo->codePath = "/data/test/codePath";
|
||||
workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath");
|
||||
workerInfo->packagePathStr = "/data/test/packagePath";
|
||||
workerInfo->hapPath = "/data/test/hapPath";
|
||||
workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath");
|
||||
workerInfo->moduleName = "moduleName";
|
||||
AssetHelper helper = AssetHelper(workerInfo);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user