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 <cstddef>
17 #include <cstdint>
18
19 #include "bundle_mgr_proxy.h"
20
21 #include "bundlemgrproxy_fuzzer.h"
22
23 using Want = OHOS::AAFwk::Want;
24
25 using namespace OHOS::AppExecFwk;
26 namespace OHOS {
27 constexpr size_t THRESHOLD = 2;
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)28 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
29 {
30 sptr<IRemoteObject> object;
31 BundleMgrProxy bundleMgrProxy(object);
32 std::string bundleName (reinterpret_cast<const char*>(data), size);
33 BundleInfo bundleInfo;
34 bundleInfo.name = bundleName;
35 std::vector<BundleInfo> bundleInfos;
36 bundleInfos.push_back(bundleInfo);
37 bundleMgrProxy.QueryKeepAliveBundleInfos(bundleInfos);
38
39 sptr<IBundleStatusCallback> bundleStatusCallback;
40 bundleMgrProxy.RegisterBundleStatusCallback(bundleStatusCallback);
41 bundleMgrProxy.ClearBundleStatusCallback(bundleStatusCallback);
42
43 DumpFlag flag = DumpFlag::DUMP_BUNDLE_LIST;
44 std::string result (reinterpret_cast<const char*>(data), size);
45 bundleMgrProxy.DumpInfos(flag, bundleName, reinterpret_cast<uintptr_t>(data), result);
46
47 bool isEnable = false;
48 if (size % THRESHOLD) {
49 isEnable = true;
50 }
51 bundleMgrProxy.IsApplicationEnabled(bundleName, isEnable);
52 bundleMgrProxy.SetApplicationEnabled(bundleName, isEnable, reinterpret_cast<uintptr_t>(data));
53
54 AbilityInfo abilityInfo;
55 bundleMgrProxy.IsAbilityEnabled(abilityInfo, isEnable);
56 bundleMgrProxy.SetAbilityEnabled(abilityInfo, isEnable, reinterpret_cast<uintptr_t>(data));
57
58 FormInfo formInfo;
59 formInfo.bundleName = bundleName;
60 std::vector<FormInfo> formInfos;
61 formInfos.push_back(formInfo);
62 bundleMgrProxy.GetAllFormsInfo(formInfos);
63 bundleMgrProxy.GetFormsInfoByApp(bundleName, formInfos);
64 std::string moduleName (reinterpret_cast<const char*>(data), size);
65 bundleMgrProxy.GetFormsInfoByModule(bundleName, moduleName, formInfos);
66
67 ShortcutInfo shortcutInfo;
68 shortcutInfo.bundleName = bundleName;
69 std::vector<ShortcutInfo> shortcutInfos;
70 shortcutInfos.push_back(shortcutInfo);
71 bundleMgrProxy.GetShortcutInfos(bundleName, shortcutInfos);
72 bundleMgrProxy.GetShortcutInfoV9(bundleName, shortcutInfos);
73
74 std::string eventKey (reinterpret_cast<const char*>(data), size);
75 CommonEventInfo commonEventInfo;
76 commonEventInfo.bundleName = bundleName;
77 std::vector<CommonEventInfo> commonEventInfos;
78 commonEventInfos.push_back(commonEventInfo);
79 bundleMgrProxy.GetAllCommonEventInfo(eventKey, commonEventInfos);
80
81 std::string networkId (reinterpret_cast<const char*>(data), size);
82 DistributedBundleInfo distributedBundleInfo;
83 bundleMgrProxy.GetDistributedBundleInfo(networkId, bundleName, distributedBundleInfo);
84 bundleMgrProxy.GetAppPrivilegeLevel(bundleName, reinterpret_cast<uintptr_t>(data));
85
86 Want want;
87 want.SetAction(bundleName);
88 ExtensionAbilityInfo extensionInfo;
89 extensionInfo.bundleName = bundleName;
90 std::vector<ExtensionAbilityInfo> extensionInfos;
91 extensionInfos.push_back(extensionInfo);
92 bundleMgrProxy.QueryExtensionAbilityInfos(want, reinterpret_cast<uintptr_t>(data),
93 reinterpret_cast<uintptr_t>(data), extensionInfos);
94 bundleMgrProxy.QueryExtensionAbilityInfosV9(want, reinterpret_cast<uintptr_t>(data),
95 reinterpret_cast<uintptr_t>(data), extensionInfos);
96 ExtensionAbilityType extensionType = ExtensionAbilityType::WORK_SCHEDULER;
97 bundleMgrProxy.QueryExtensionAbilityInfos(want, extensionType,
98 reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data), extensionInfos);
99 bundleMgrProxy.QueryExtensionAbilityInfosV9(want, extensionType,
100 reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data), extensionInfos);
101 bundleMgrProxy.QueryExtensionAbilityInfos(extensionType,
102 reinterpret_cast<uintptr_t>(data), extensionInfos);
103
104 std::string permission (reinterpret_cast<const char*>(data), size);
105 bundleMgrProxy.VerifyCallingPermission(permission);
106 bundleMgrProxy.GetAccessibleAppCodePaths(reinterpret_cast<uintptr_t>(data));
107 std::string uri (reinterpret_cast<const char*>(data), size);
108 bundleMgrProxy.QueryExtensionAbilityInfoByUri(uri, reinterpret_cast<uintptr_t>(data), extensionInfo);
109 bundleMgrProxy.ImplicitQueryInfoByPriority(want, reinterpret_cast<uintptr_t>(data),
110 reinterpret_cast<uintptr_t>(data), abilityInfo, extensionInfo);
111
112 abilityInfo.name = bundleName;
113 std::vector<AbilityInfo> abilityInfos;
114 abilityInfos.push_back(abilityInfo);
115 bundleMgrProxy.ImplicitQueryInfos(want, reinterpret_cast<uintptr_t>(data),
116 reinterpret_cast<uintptr_t>(data), abilityInfos, extensionInfos);
117
118 std::string abilityName (reinterpret_cast<const char*>(data), size);
119 bundleMgrProxy.GetAbilityInfo(bundleName, abilityName, abilityInfo);
120 bundleMgrProxy.GetAbilityInfo(bundleName, moduleName, abilityName, abilityInfo);
121 BundleInfo info;
122 bundleMgrProxy.GetSandboxBundleInfo(bundleName, reinterpret_cast<uintptr_t>(data),
123 reinterpret_cast<uintptr_t>(data), info);
124 bundleMgrProxy.IsModuleRemovable(bundleName, moduleName, isEnable);
125 bundleMgrProxy.SetModuleRemovable(bundleName, moduleName, isEnable);
126 std::vector<std::string> dependentModuleNames;
127 dependentModuleNames.push_back(bundleName);
128 bundleMgrProxy.GetAllDependentModuleNames(bundleName, moduleName, dependentModuleNames);
129 bundleMgrProxy.GetModuleUpgradeFlag(bundleName, moduleName);
130 bundleMgrProxy.SetModuleUpgradeFlag(bundleName, moduleName, reinterpret_cast<uintptr_t>(data));
131 bundleMgrProxy.SetDisposedStatus(bundleName, reinterpret_cast<uintptr_t>(data));
132 bundleMgrProxy.GetDisposedStatus(bundleName);
133 bundleMgrProxy.ObtainCallingBundleName(bundleName);
134 std::vector<int64_t> bundleStats;
135 bundleStats.push_back(reinterpret_cast<intptr_t>(data));
136 bundleMgrProxy.GetBundleStats(bundleName, reinterpret_cast<uintptr_t>(data), bundleStats);
137 sptr<IRemoteObject> callback;
138 bundleMgrProxy.CheckAbilityEnableInstall(want, reinterpret_cast<uintptr_t>(data),
139 reinterpret_cast<uintptr_t>(data), callback);
140 std::unique_ptr<uint8_t[]> mediaDataPtr;
141 bundleMgrProxy.GetMediaData(bundleName, moduleName, abilityName, mediaDataPtr,
142 size, reinterpret_cast<uintptr_t>(data));
143 bundleMgrProxy.GetStringById(bundleName, moduleName, reinterpret_cast<uintptr_t>(data),
144 reinterpret_cast<uintptr_t>(data));
145 bundleMgrProxy.GetIconById(bundleName, moduleName, reinterpret_cast<uintptr_t>(data),
146 reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data));
147 std::string udid (reinterpret_cast<const char*>(data), size);
148 bundleMgrProxy.GetUdidByNetworkId(networkId, udid);
149 bundleMgrProxy.GetSandboxAbilityInfo(want, reinterpret_cast<uintptr_t>(data),
150 reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data), abilityInfo);
151 bundleMgrProxy.GetSandboxExtAbilityInfos(want, reinterpret_cast<uintptr_t>(data),
152 reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data), extensionInfos);
153 HapModuleInfo hapModuleInfo;
154 bundleMgrProxy.GetSandboxHapModuleInfo(abilityInfo, reinterpret_cast<uintptr_t>(data),
155 reinterpret_cast<uintptr_t>(data), hapModuleInfo);
156 bundleMgrProxy.IsSafeMode();
157 bundleMgrProxy.UnregisterBundleStatusCallback();
158 bundleMgrProxy.GetBundleInstaller();
159 bundleMgrProxy.GetBundleUserMgr();
160 bundleMgrProxy.GetQuickFixManagerProxy();
161 bundleMgrProxy.GetAppControlProxy();
162 return true;
163 }
164 }
165
166 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)167 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
168 {
169 // Run your code on data.
170 OHOS::DoSomethingInterestingWithMyAPI(data, size);
171 return 0;
172 }