• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <set>
19 #include <fuzzer/FuzzedDataProvider.h>
20 
21 #include "bundle_mgr_proxy.h"
22 
23 #include "bmsbundlemgrproxypartfour_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         std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
38         std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
39         int32_t userId = GenerateRandomUser(fdp);
40         int32_t appIndex = fdp.ConsumeIntegral<int32_t>();
41         int32_t flags = fdp.ConsumeIntegral<int32_t>();
42         int32_t triggerMode = fdp.ConsumeIntegral<int32_t>();
43 
44         bundleMgrProxy.ResetAOTCompileStatus(bundleName, moduleName, triggerMode);
45         std::string profile;
46         ProfileType profileType = static_cast<ProfileType>(fdp.ConsumeIntegralInRange<uint8_t>(1, 7));
47         bundleMgrProxy.GetJsonProfile(profileType, bundleName, moduleName, profile);
48         bundleMgrProxy.GetBundleResourceProxy();
49         std::vector<RecoverableApplicationInfo> recoverableApplications;
50         bundleMgrProxy.GetRecoverableApplicationInfo(recoverableApplications);
51         BundleInfo bundleInfo;
52         bundleMgrProxy.GetUninstalledBundleInfo(bundleName, bundleInfo);
53         std::string additionalInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
54         bundleMgrProxy.SetAdditionalInfo(bundleName, additionalInfo);
55         bundleMgrProxy.CreateBundleDataDir(userId);
56         std::string odid;
57         bundleMgrProxy.GetOdid(odid);
58         std::string developerId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
59         std::vector<BundleInfo> bundleInfos;
60         bundleMgrProxy.GetAllBundleInfoByDeveloperId(developerId, bundleInfos, userId);
61         std::string appDistributionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
62         std::vector<std::string> developerIdList;
63         bundleMgrProxy.GetDeveloperIds(appDistributionType, developerIdList);
64         std::vector<std::string> results;
65         std::string compileMode = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
66         bool isAllBundle = fdp.ConsumeBool();
67         bundleMgrProxy.CompileProcessAOT(bundleName, compileMode, isAllBundle, results);
68         bundleMgrProxy.ResetAOTCompileStatus(bundleName, moduleName, triggerMode);
69         bundleMgrProxy.CopyAp(bundleName, isAllBundle, results);
70         std::string link = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
71         bool canOpen = fdp.ConsumeBool();
72         bundleMgrProxy.CanOpenLink(link, canOpen);
73         std::vector<PreinstalledApplicationInfo> preinstalledApplicationInfos;
74         bundleMgrProxy.GetAllPreinstalledApplicationInfos(preinstalledApplicationInfos);
75         bool state = fdp.ConsumeBool();
76         bool isNeedSendNotify = fdp.ConsumeBool();
77         bundleMgrProxy.SwitchUninstallState(bundleName, state, isNeedSendNotify);
78 
79         std::string continueType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
80         AbilityInfo abilityInfo;
81         bundleMgrProxy.QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo);
82         ElementName element;
83         bundleMgrProxy.QueryCloneAbilityInfo(element, flags, appIndex, abilityInfo, reinterpret_cast<uintptr_t>(data));
84         bundleMgrProxy.GetCloneBundleInfo(bundleName, flags, appIndex, bundleInfo);
85         element.SetAbilityName(abilityName);
86         element.SetBundleName(bundleName);
87         SignatureInfo sinfo;
88         bundleMgrProxy.GetSignatureInfoByBundleName(bundleName, sinfo);
89         ShortcutInfo shortcutInfo;
90         bundleMgrProxy.AddDesktopShortcutInfo(shortcutInfo, userId);
91         bundleMgrProxy.DeleteDesktopShortcutInfo(shortcutInfo, userId);
92         std::vector<ShortcutInfo> shortcutInfos;
93         bundleMgrProxy.GetAllDesktopShortcutInfo(userId, shortcutInfos);
94         bundleMgrProxy.GetOdidByBundleName(bundleName, odid);
95         bundleMgrProxy.GetBundleInfosForContinuation(flags, bundleInfos, userId);
96         std::string deviceType;
97         bundleMgrProxy.GetCompatibleDeviceType(bundleName, deviceType);
98         std::string queryBundleName;
99         std::string appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
100         bundleMgrProxy.GetBundleNameByAppId(appId, queryBundleName);
101         std::string dataDir;
102         bundleMgrProxy.GetDirByBundleNameAndAppIndex(bundleName, appIndex, dataDir);
103         std::vector<BundleDir> bundleDirs;
104         bundleMgrProxy.GetAllBundleDirs(userId, bundleDirs);
105         std::set<AppDistributionTypeEnum> appDistributionTypeEnums{
106             AppDistributionTypeEnum::APP_DISTRIBUTION_TYPE_APP_GALLERY};
107         bundleMgrProxy.SetAppDistributionTypes(appDistributionTypeEnums);
108         return true;
109     }
110 }
111 
112 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)113 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
114 {
115     // Run your code on data.
116     OHOS::DoSomethingInterestingWithMyAPI(data, size);
117     return 0;
118 }