122736c2fSopenharmony_ci/* 222736c2fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 422736c2fSopenharmony_ci * you may not use this file except in compliance with the License. 522736c2fSopenharmony_ci * You may obtain a copy of the License at 622736c2fSopenharmony_ci * 722736c2fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 822736c2fSopenharmony_ci * 922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and 1322736c2fSopenharmony_ci * limitations under the License. 1422736c2fSopenharmony_ci */ 1522736c2fSopenharmony_ci 1622736c2fSopenharmony_ci#define private public 1722736c2fSopenharmony_ci#define protected public 1822736c2fSopenharmony_ci#include "enable_ime_data_parser.h" 1922736c2fSopenharmony_ci#undef private 2022736c2fSopenharmony_ci 2122736c2fSopenharmony_ci#include "enableimedataparse_fuzzer.h" 2222736c2fSopenharmony_ci 2322736c2fSopenharmony_ciusing namespace OHOS::MiscServices; 2422736c2fSopenharmony_cinamespace OHOS { 2522736c2fSopenharmony_ciconstexpr size_t THRESHOLD = 10; 2622736c2fSopenharmony_civoid FuzzInitialize(const int32_t userId) 2722736c2fSopenharmony_ci{ 2822736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->Initialize(userId); 2922736c2fSopenharmony_ci} 3022736c2fSopenharmony_ci 3122736c2fSopenharmony_civoid FuzzOnUserChanged(const int32_t userId) 3222736c2fSopenharmony_ci{ 3322736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->OnUserChanged(userId); 3422736c2fSopenharmony_ci} 3522736c2fSopenharmony_ci 3622736c2fSopenharmony_civoid FuzzCheckNeedSwitch(const std::string &key, SwitchInfo &switchInfo, const int32_t userId) 3722736c2fSopenharmony_ci{ 3822736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->CheckNeedSwitch(key, switchInfo, userId); 3922736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->CheckNeedSwitch(switchInfo, userId); 4022736c2fSopenharmony_ci} 4122736c2fSopenharmony_ci 4222736c2fSopenharmony_civoid FuzzGetEnableData(const std::string &key, std::vector<std::string> &enableVec, const int32_t userId) 4322736c2fSopenharmony_ci{ 4422736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->GetEnableData(key, enableVec, userId); 4522736c2fSopenharmony_ci} 4622736c2fSopenharmony_ci 4722736c2fSopenharmony_civoid FuzzParseEnableIme(const std::string &valueStr, int32_t userId, std::vector<std::string> &enableVec) 4822736c2fSopenharmony_ci{ 4922736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->ParseEnableIme(valueStr, userId, enableVec); 5022736c2fSopenharmony_ci} 5122736c2fSopenharmony_ci 5222736c2fSopenharmony_civoid FuzzParseEnableKeyboard(const std::string &valueStr, int32_t userId, std::vector<std::string> &enableVec) 5322736c2fSopenharmony_ci{ 5422736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->ParseEnableKeyboard(valueStr, userId, enableVec); 5522736c2fSopenharmony_ci} 5622736c2fSopenharmony_ci 5722736c2fSopenharmony_civoid FuzzCheckTargetEnableName(const std::string &key, const std::string &targetName, std::string &nextIme, 5822736c2fSopenharmony_ci const int32_t userId) 5922736c2fSopenharmony_ci{ 6022736c2fSopenharmony_ci EnableImeDataParser::GetInstance()->CheckTargetEnableName(key, targetName, nextIme, userId); 6122736c2fSopenharmony_ci} 6222736c2fSopenharmony_ci} // namespace OHOS 6322736c2fSopenharmony_ci/* Fuzzer entry point */ 6422736c2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 6522736c2fSopenharmony_ci{ 6622736c2fSopenharmony_ci if (size < OHOS::THRESHOLD) { 6722736c2fSopenharmony_ci return 0; 6822736c2fSopenharmony_ci } 6922736c2fSopenharmony_ci /* Run your code on data */ 7022736c2fSopenharmony_ci const int32_t userId = static_cast<int32_t>(size); 7122736c2fSopenharmony_ci std::string fuzzedString(reinterpret_cast<const char *>(data), size); 7222736c2fSopenharmony_ci SwitchInfo switchInfo; 7322736c2fSopenharmony_ci std::vector<std::string> enableVec; 7422736c2fSopenharmony_ci 7522736c2fSopenharmony_ci OHOS::FuzzInitialize(userId); 7622736c2fSopenharmony_ci OHOS::FuzzOnUserChanged(userId); 7722736c2fSopenharmony_ci OHOS::FuzzCheckNeedSwitch(fuzzedString, switchInfo, userId); 7822736c2fSopenharmony_ci OHOS::FuzzGetEnableData(fuzzedString, enableVec, userId); 7922736c2fSopenharmony_ci 8022736c2fSopenharmony_ci OHOS::FuzzParseEnableIme(fuzzedString, userId, enableVec); 8122736c2fSopenharmony_ci OHOS::FuzzParseEnableKeyboard(fuzzedString, userId, enableVec); 8222736c2fSopenharmony_ci OHOS::FuzzCheckTargetEnableName(fuzzedString, fuzzedString, fuzzedString, userId); 8322736c2fSopenharmony_ci return 0; 8422736c2fSopenharmony_ci}