• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         std::string uri (reinterpret_cast<const char*>(data), size);
107         bundleMgrProxy.QueryExtensionAbilityInfoByUri(uri, reinterpret_cast<uintptr_t>(data), extensionInfo);
108         bundleMgrProxy.ImplicitQueryInfoByPriority(want, reinterpret_cast<uintptr_t>(data),
109             reinterpret_cast<uintptr_t>(data), abilityInfo, extensionInfo);
110 
111         abilityInfo.name = bundleName;
112         std::vector<AbilityInfo> abilityInfos;
113         abilityInfos.push_back(abilityInfo);
114         bundleMgrProxy.ImplicitQueryInfos(want, reinterpret_cast<uintptr_t>(data),
115             reinterpret_cast<uintptr_t>(data), true, abilityInfos, extensionInfos);
116 
117         std::string abilityName (reinterpret_cast<const char*>(data), size);
118         bundleMgrProxy.GetAbilityInfo(bundleName, abilityName, abilityInfo);
119         bundleMgrProxy.GetAbilityInfo(bundleName, moduleName, abilityName, abilityInfo);
120         BundleInfo info;
121         bundleMgrProxy.GetSandboxBundleInfo(bundleName, reinterpret_cast<uintptr_t>(data),
122             reinterpret_cast<uintptr_t>(data), info);
123         bundleMgrProxy.IsModuleRemovable(bundleName, moduleName, isEnable);
124         bundleMgrProxy.SetModuleRemovable(bundleName, moduleName, isEnable);
125         std::vector<std::string> dependentModuleNames;
126         dependentModuleNames.push_back(bundleName);
127         bundleMgrProxy.GetAllDependentModuleNames(bundleName, moduleName, dependentModuleNames);
128         bundleMgrProxy.GetModuleUpgradeFlag(bundleName, moduleName);
129         bundleMgrProxy.SetModuleUpgradeFlag(bundleName, moduleName, reinterpret_cast<uintptr_t>(data));
130         bundleMgrProxy.ObtainCallingBundleName(bundleName);
131         std::vector<int64_t> bundleStats;
132         bundleStats.push_back(reinterpret_cast<intptr_t>(data));
133         bundleMgrProxy.GetBundleStats(bundleName, reinterpret_cast<uintptr_t>(data), bundleStats);
134         sptr<IRemoteObject> callback;
135         bundleMgrProxy.CheckAbilityEnableInstall(want, reinterpret_cast<uintptr_t>(data),
136             reinterpret_cast<uintptr_t>(data), callback);
137         std::unique_ptr<uint8_t[]> mediaDataPtr;
138         bundleMgrProxy.GetMediaData(bundleName, moduleName, abilityName, mediaDataPtr,
139             size, reinterpret_cast<uintptr_t>(data));
140         bundleMgrProxy.GetStringById(bundleName, moduleName, reinterpret_cast<uintptr_t>(data),
141             reinterpret_cast<uintptr_t>(data));
142         bundleMgrProxy.GetIconById(bundleName, moduleName, reinterpret_cast<uintptr_t>(data),
143             reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data));
144         std::string udid (reinterpret_cast<const char*>(data), size);
145         bundleMgrProxy.GetSandboxAbilityInfo(want, reinterpret_cast<uintptr_t>(data),
146             reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data), abilityInfo);
147         bundleMgrProxy.GetSandboxExtAbilityInfos(want, reinterpret_cast<uintptr_t>(data),
148             reinterpret_cast<uintptr_t>(data), reinterpret_cast<uintptr_t>(data), extensionInfos);
149         HapModuleInfo hapModuleInfo;
150         bundleMgrProxy.GetSandboxHapModuleInfo(abilityInfo, reinterpret_cast<uintptr_t>(data),
151             reinterpret_cast<uintptr_t>(data), hapModuleInfo);
152         bundleMgrProxy.UnregisterBundleStatusCallback();
153         bundleMgrProxy.GetBundleInstaller();
154         bundleMgrProxy.GetBundleUserMgr();
155         bundleMgrProxy.GetQuickFixManagerProxy();
156         bundleMgrProxy.GetAppControlProxy();
157         return true;
158     }
159 }
160 
161 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)162 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
163 {
164     // Run your code on data.
165     OHOS::DoSomethingInterestingWithMyAPI(data, size);
166     return 0;
167 }