• 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 "ohosadapterhelperimpl_fuzzer.h"
17 
18 #include <fuzzer/FuzzedDataProvider.h>
19 #include <cstring>
20 
21 #include "ohos_adapter_helper_impl.h"
22 
23 using namespace OHOS::NWeb;
24 
25 namespace OHOS {
26 constexpr uint8_t MAX_STRING_LENGTH = 64;
27 
OhosAdapterHelperImpl001Test(const uint8_t * data,size_t size)28 bool OhosAdapterHelperImpl001Test(const uint8_t* data, size_t size)
29 {
30     if ((data == nullptr) || (size == 0)) {
31         return false;
32     }
33     auto& helperImpl = OhosAdapterHelperImpl::GetInstance();
34     helperImpl.CreateAafwkAdapter();
35     helperImpl.CreateBatteryClientAdapter();
36     helperImpl.CreateAudioCapturerAdapter();
37     helperImpl.GetWebPermissionDataBaseInstance();
38     helperImpl.GetSystemPropertiesInstance();
39     helperImpl.GetVSyncAdapter();
40     helperImpl.GetInitWebAdapter();
41     helperImpl.GetKeystoreAdapterInstance();
42     helperImpl.GetEnterpriseDeviceManagementInstance();
43     helperImpl.GetDatashareInstance();
44     helperImpl.CreateIMFAdapter();
45     helperImpl.GetRootCertDataAdapter();
46     helperImpl.GetAccessTokenAdapterInstance();
47     helperImpl.GetEventHandlerAdapter();
48     helperImpl.GetPrintManagerInstance();
49     helperImpl.CreatePlayerAdapter();
50     helperImpl.GetWindowAdapterInstance();
51     helperImpl.GetHiSysEventAdapterInstance();
52     helperImpl.GetHiTraceAdapterInstance();
53     helperImpl.GetNetProxyInstance();
54     helperImpl.CreateScreenCaptureAdapter();
55     helperImpl.CreateDateTimeFormatAdapter();
56     helperImpl.CreateMediaCodecDecoderAdapter();
57     helperImpl.CreateMediaCodecEncoderAdapter();
58     helperImpl.GetMediaCodecListAdapter();
59     helperImpl.CreateMediaAVSessionAdapter();
60     helperImpl.CreateSensorAdapter();
61     helperImpl.GetOhosNativeBufferAdapter();
62     helperImpl.CreateMigrationMgrAdapter();
63     helperImpl.GetOhosDrawingTextFontAdapter();
64     helperImpl.GetOhosDrawingTextTypographyAdapter();
65     return true;
66 }
67 
OhosAdapterHelperImpl002Test(const uint8_t * data,size_t size)68 bool OhosAdapterHelperImpl002Test(const uint8_t* data, size_t size)
69 {
70     if ((data == nullptr) || (size == 0)) {
71         return false;
72     }
73     auto& helperImpl = OhosAdapterHelperImpl::GetInstance();
74     FuzzedDataProvider dataProvider(data, size);
75     std::string hapPath = dataProvider.ConsumeRandomLengthString(MAX_STRING_LENGTH);
76     std::string hapPath1 = dataProvider.ConsumeRandomLengthString(MAX_STRING_LENGTH);
77     helperImpl.GetResourceAdapter(hapPath);
78     helperImpl.SetArkWebCoreHapPathOverride(hapPath1);
79 
80     return true;
81 }
82 
83 } // namespace OHOS
84 
85 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)86 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
87 {
88     /* Run your code on data */
89     OHOS::OhosAdapterHelperImpl001Test(data, size);
90     OHOS::OhosAdapterHelperImpl002Test(data, size);
91     return 0;
92 }
93