1 /*
2 * Copyright (c) 2024 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 #define private public
16 #include <cstddef>
17 #include <cstdint>
18
19 #include "bms_extension_client.h"
20
21 #include "bmsextensionclient_fuzzer.h"
22
23 using Want = OHOS::AAFwk::Want;
24
25 using namespace OHOS::AppExecFwk;
26 namespace OHOS {
27 constexpr uint8_t ENABLE = 2;
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)28 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
29 {
30 Want want;
31 std::string bundleName (reinterpret_cast<const char*>(data), size);
32 bool boolParam = *data % ENABLE;
33 want.SetAction(bundleName);
34 std::vector<AbilityInfo> abilityInfos;
35 AbilityInfo abilityInfo;
36 std::vector<Want> wants;
37 const std::vector<std::string> bundleNames;
38 std::vector<BundleInfo> bundleInfos;
39 std::vector<int64_t> bundleStats;
40 sptr<IRemoteObject> callback;
41 BmsExtensionClient bmsExtensionClient;
42 BundleInfo bundleInfo;
43 bmsExtensionClient.QueryLauncherAbility(want, reinterpret_cast<uintptr_t>(data),
44 abilityInfos);
45 bmsExtensionClient.QueryAbilityInfos(want, reinterpret_cast<uintptr_t>(data),
46 reinterpret_cast<uintptr_t>(data), abilityInfos);
47 bmsExtensionClient.BatchQueryAbilityInfos(wants, reinterpret_cast<uintptr_t>(data),
48 reinterpret_cast<uintptr_t>(data),
49 abilityInfos);
50 bmsExtensionClient.QueryAbilityInfo(want, reinterpret_cast<uintptr_t>(data),
51 reinterpret_cast<uintptr_t>(data), abilityInfo);
52 bmsExtensionClient.GetBundleInfos(reinterpret_cast<uintptr_t>(data), bundleInfos,
53 reinterpret_cast<uintptr_t>(data));
54 bmsExtensionClient.GetBundleInfo(bundleName, reinterpret_cast<uintptr_t>(data), bundleInfo,
55 reinterpret_cast<uintptr_t>(data), boolParam);
56 bmsExtensionClient.BatchGetBundleInfo(bundleNames, reinterpret_cast<uintptr_t>(data),
57 bundleInfos, reinterpret_cast<uintptr_t>(data));
58 bmsExtensionClient.ImplicitQueryAbilityInfos(want, reinterpret_cast<uintptr_t>(data),
59 reinterpret_cast<uintptr_t>(data),
60 abilityInfos, boolParam);
61 bmsExtensionClient.GetBundleStats(bundleName, reinterpret_cast<uintptr_t>(data), bundleStats);
62 bmsExtensionClient.ClearCache(bundleName, callback, reinterpret_cast<uintptr_t>(data));
63 bmsExtensionClient.ClearData(bundleName, reinterpret_cast<uintptr_t>(data));
64 int32_t uid = 3024;
65 bmsExtensionClient.GetUidByBundleName(bundleName, reinterpret_cast<uintptr_t>(data),
66 uid);
67 bmsExtensionClient.GetBundleNameByUid(reinterpret_cast<uintptr_t>(data), bundleName);
68
69 bmsExtensionClient.ModifyLauncherAbilityInfo(abilityInfo);
70 bmsExtensionClient.GetDataMgr();
71 return true;
72 }
73 }
74
75 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)76 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
77 {
78 // Run your code on data.
79 OHOS::DoSomethingInterestingWithMyAPI(data, size);
80 return 0;
81 }