1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "getaccessibleappcodepaths_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <iostream>
21
22 #include "bundle_mgr_interface.h"
23 #include "if_system_ability_manager.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26
27 using namespace OHOS::AppExecFwk;
28
29 namespace OHOS {
GetBundleMgr()30 sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr()
31 {
32 auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
33 if (systemAbilityManager == nullptr) {
34 std::cout << "GetBundleMgr GetSystemAbilityManager is null";
35 return nullptr;
36 }
37
38 auto bundleMgrSa = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
39 if (bundleMgrSa == nullptr) {
40 std::cout << "[fuzz] GetBundleMgr GetSystemAbility is null";
41 return nullptr;
42 }
43
44 return iface_cast<IBundleMgr>(bundleMgrSa);
45 }
46
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)47 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
48 {
49 if (size != 1) {
50 return false;
51 }
52
53 auto bundleMgr = GetBundleMgr();
54 if (bundleMgr == nullptr) {
55 return false;
56 }
57
58 auto appCodePaths = bundleMgr->GetAccessibleAppCodePaths(reinterpret_cast<uintptr_t>(data));
59 for (auto appCodePath : appCodePaths) {
60 std::cout << "appCodePath" << appCodePath;
61 }
62 return true;
63 }
64 }
65
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69 /* Run your code on data */
70 OHOS::DoSomethingInterestingWithMyAPI(data, size);
71 return 0;
72 }
73
74