1 /*
2 * Copyright (c) 2025 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 #include <fuzzer/FuzzedDataProvider.h>
19 #include <set>
20
21 #include "bundle_mgr_proxy.h"
22
23 #include "bmsbundlemgrproxypartthree_fuzzer.h"
24 #include "bms_fuzztest_util.h"
25
26 using Want = OHOS::AAFwk::Want;
27
28 using namespace OHOS::AppExecFwk;
29 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
30 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)31 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
32 {
33 sptr<IRemoteObject> object;
34 BundleMgrProxy bundleMgrProxy(object);
35 FuzzedDataProvider fdp(data, size);
36 std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
37 int32_t userId = GenerateRandomUser(fdp);
38 int32_t appIndex = fdp.ConsumeIntegral<int32_t>();
39 int32_t flags = fdp.ConsumeIntegral<int32_t>();
40 std::string hapFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
41
42 BundleInfo bundleInfo;
43 AbilityInfo abilityInfo;
44 bundleMgrProxy.GetBundleArchiveInfo(hapFilePath, flags, bundleInfo);
45 BundleFlag bundleFlag = GET_BUNDLE_DEFAULT;
46 bundleMgrProxy.GetBundleArchiveInfo(hapFilePath, bundleFlag, bundleInfo);
47 bundleMgrProxy.GetBundleArchiveInfoV9(hapFilePath, flags, bundleInfo);
48 HapModuleInfo hapModuleInfo;
49 bundleMgrProxy.GetHapModuleInfo(abilityInfo, hapModuleInfo);
50 bundleMgrProxy.GetHapModuleInfo(abilityInfo, userId, hapModuleInfo);
51 Want want;
52 bundleMgrProxy.GetLaunchWantForBundle(bundleName, want, userId);
53 PermissionDef permissionDef;
54 std::string permissionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
55 bundleMgrProxy.GetPermissionDef(permissionName, permissionDef);
56
57 uint64_t cacheSize = fdp.ConsumeIntegral<uint64_t>();
58 bundleMgrProxy.CleanBundleCacheFilesAutomatic(cacheSize);
59 sptr<ICleanCacheCallback> cleanCacheCallback;
60 bundleMgrProxy.CleanBundleCacheFiles(bundleName, cleanCacheCallback, userId, appIndex);
61 bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex);
62
63 bundleMgrProxy.GetDependentBundleInfo(bundleName, bundleInfo);
64 int uid = fdp.ConsumeIntegral<int>();
65 bundleMgrProxy.GetNameForUid(uid, bundleName);
66 std::vector<AbilityInfo> abilityInfos;
67 std::vector<Want> wants;
68 bundleMgrProxy.BatchQueryAbilityInfos(wants, flags, userId, abilityInfos);
69 bool isEnable = fdp.ConsumeBool();
70 bundleMgrProxy.IsCloneApplicationEnabled(bundleName, appIndex, isEnable);
71 bundleMgrProxy.SetCloneApplicationEnabled(bundleName, appIndex, isEnable);
72 bundleMgrProxy.IsCloneAbilityEnabled(abilityInfo, appIndex, isEnable);
73 bundleMgrProxy.SetCloneAbilityEnabled(abilityInfo, appIndex, isEnable);
74 bundleMgrProxy.GetVerifyManager();
75 bundleMgrProxy.GetExtendResourceManager();
76 std::vector<int64_t> bundleStats;
77 bundleMgrProxy.GetAllBundleStats(userId, bundleStats);
78 bundleMgrProxy.GetDefaultAppProxy();
79 bundleMgrProxy.GetAppControlProxy();
80 bundleMgrProxy.SetDebugMode(isEnable);
81 bundleMgrProxy.VerifySystemApi();
82 bundleMgrProxy.ProcessPreload(want);
83 bundleMgrProxy.GetOverlayManagerProxy();
84 AppProvisionInfo appProvisionInfo;
85 bundleMgrProxy.GetAppProvisionInfo(bundleName, userId, appProvisionInfo);
86 std::vector<BaseSharedBundleInfo> baseSharedBundleInfos;
87 bundleMgrProxy.GetBaseSharedBundleInfos(bundleName, baseSharedBundleInfos);
88 std::vector<SharedBundleInfo> sharedBundles;
89 bundleMgrProxy.GetAllSharedBundleInfo(sharedBundles);
90 std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
91 bundleMgrProxy.GetSharedBundleInfo(bundleName, moduleName, sharedBundles);
92 SharedBundleInfo sharedBundleInfo;
93 bundleMgrProxy.GetSharedBundleInfoBySelf(bundleName, sharedBundleInfo);
94 std::vector<Dependency> dependencies;
95 bundleMgrProxy.GetSharedDependencies(bundleName, moduleName, dependencies);
96 std::vector<ProxyData> proxyDatas;
97 bundleMgrProxy.GetProxyDataInfos(bundleName, moduleName, proxyDatas);
98 bundleMgrProxy.GetAllProxyDataInfos(proxyDatas);
99 std::string specifiedDistributionType;
100 bundleMgrProxy.GetSpecifiedDistributionType(bundleName, specifiedDistributionType);
101 std::string additionalInfo;
102 bundleMgrProxy.GetAdditionalInfo(bundleName, additionalInfo);
103 bundleMgrProxy.GetAdditionalInfoForAllUser(bundleName, additionalInfo);
104 std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
105 std::string extName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
106 std::string mimeType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
107 bundleMgrProxy.SetExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType);
108 bundleMgrProxy.DelExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType);
109 std::vector<DataGroupInfo> infos;
110 bundleMgrProxy.QueryDataGroupInfos(bundleName, userId, infos);
111 std::string dir;
112 std::string dataGroupId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
113 bundleMgrProxy.GetGroupDir(dataGroupId, dir);
114 bundleMgrProxy.QueryAppGalleryBundleName(bundleName);
115 std::string extensionTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
116 std::vector<ExtensionAbilityInfo> extensionInfos;
117 bundleMgrProxy.QueryExtensionAbilityInfosWithTypeName(want, extensionTypeName, flags, userId, extensionInfos);
118 bundleMgrProxy.QueryExtensionAbilityInfosOnlyWithTypeName(extensionTypeName, flags, userId, extensionInfos);
119 return true;
120 }
121 }
122
123 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)124 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
125 {
126 // Run your code on data.
127 OHOS::DoSomethingInterestingWithMyAPI(data, size);
128 return 0;
129 }