• 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 #define private public
17 #define protected public
18 #include "ima_hisysevent_reporter.h"
19 #include "imc_hisysevent_reporter.h"
20 #include "imf_hisysevent_info.h"
21 #include "imf_hisysevent_reporter.h"
22 #include "imf_hisysevent_util.h"
23 #include "imsa_hisysevent_reporter.h"
24 #undef private
25 
26 #include <sys/time.h>
27 #include <unistd.h>
28 
29 #include <condition_variable>
30 #include <cstdint>
31 #include <string>
32 
33 #include "imfhisyseventreport_fuzzer.h"
34 #include "global.h"
35 #include "hisysevent_base_manager.h"
36 #include "hisysevent_listener.h"
37 #include "hisysevent_manager.h"
38 #include "hisysevent_query_callback.h"
39 #include "hisysevent_record.h"
40 
41 using namespace OHOS::MiscServices;
42 namespace OHOS {
43 using namespace OHOS::HiviewDFX;
44 constexpr ClientType PARAM_CLIENT_TYPE = ClientType::INNER_KIT;
45 constexpr int32_t PARAM_INPUT_PATTERN = 6;
TestClientAttach01(const uint8_t * data,size_t size)46 void TestClientAttach01(const uint8_t *data, size_t size)
47 {
48     std::string fuzzedString(reinterpret_cast<const char *>(data), size);
49     auto errCode = static_cast<int32_t>(size);
50     auto paramIsShowkeyboard = static_cast<bool>(data[0] % 2);
51     auto info = HiSysOriginalInfo::Builder()
52                 .SetErrCode(errCode)
53                 .SetInputPattern(PARAM_INPUT_PATTERN)
54                 .SetIsShowKeyboard(paramIsShowkeyboard)
55                 .SetClientType(PARAM_CLIENT_TYPE)
56                 .Build();
57     ImcHiSysEventReporter::GetInstance().ReportEvent(ImfEventType::CLIENT_ATTACH, *info);
58 }
59 
TestClientAttach02(const uint8_t * data,size_t size)60 void TestClientAttach02(const uint8_t *data, size_t size)
61 {
62     std::string fuzzedString(reinterpret_cast<const char *>(data), size);
63     auto paramPeerName = fuzzedString;
64     auto paramPeerUserId = static_cast<int32_t>(size);
65     auto paramPeerPid = static_cast<int64_t>(size);
66     auto errCode = static_cast<int32_t>(size);
67     auto paramIsShowkeyboard = static_cast<bool>(data[0] % 2);
68     auto paramImeName = fuzzedString;
69     auto info = HiSysOriginalInfo::Builder()
70                     .SetPeerName(paramPeerName)
71                     .SetPeerPid(paramPeerPid)
72                     .SetPeerUserId(paramPeerUserId)
73                     .SetClientType(PARAM_CLIENT_TYPE)
74                     .SetInputPattern(PARAM_INPUT_PATTERN)
75                     .SetIsShowKeyboard(paramIsShowkeyboard)
76                     .SetImeName(paramImeName)
77                     .SetErrCode(errCode)
78                     .Build();
79     ImsaHiSysEventReporter::GetInstance().ReportEvent(ImfEventType::CLIENT_ATTACH, *info);
80 }
81 
TestClientShow(const uint8_t * data,size_t size)82 void TestClientShow(const uint8_t *data, size_t size)
83 {
84     std::string fuzzedString(reinterpret_cast<const char *>(data), size);
85     auto paramPeerName = fuzzedString;
86     auto paramPeerUserId = static_cast<int32_t>(size);
87     auto paramPeerPid = static_cast<int64_t>(size);
88     auto errCode = static_cast<int32_t>(size);
89     auto paramIEventCode = static_cast<int32_t>(size);
90     auto paramImeName = fuzzedString;
91     auto info = HiSysOriginalInfo::Builder()
92                     .SetPeerName(paramPeerName)
93                     .SetPeerPid(paramPeerPid)
94                     .SetPeerUserId(paramPeerUserId)
95                     .SetClientType(PARAM_CLIENT_TYPE)
96                     .SetImeName(paramImeName)
97                     .SetEventCode(paramIEventCode)
98                     .SetErrCode(errCode)
99                     .Build();
100     ImcHiSysEventReporter::GetInstance().ReportEvent(ImfEventType::CLIENT_SHOW, *info);
101 }
102 
TestStartInput(const uint8_t * data,size_t size)103 void TestStartInput(const uint8_t *data, size_t size)
104 {
105     std::string fuzzedString(reinterpret_cast<const char *>(data), size);
106     auto paramPeerName = fuzzedString;
107     auto paramPeerPid = static_cast<int64_t>(size);
108     auto errCode = static_cast<int32_t>(size);
109     auto paramIsShowkeyboard = static_cast<bool>(data[0] % 2);
110     auto paramIEventCode = static_cast<int32_t>(size);
111     auto info = HiSysOriginalInfo::Builder()
112                     .SetPeerName(paramPeerName)
113                     .SetPeerPid(paramPeerPid)
114                     .SetIsShowKeyboard(paramIsShowkeyboard)
115                     .SetEventCode(paramIEventCode)
116                     .SetErrCode(errCode)
117                     .Build();
118     ImaHiSysEventReporter::GetInstance().ReportEvent(ImfEventType::IME_START_INPUT, *info);
119 }
120 
TestBaseTextOperation(const uint8_t * data,size_t size)121 void TestBaseTextOperation(const uint8_t *data, size_t size)
122 {
123     std::string fuzzedString(reinterpret_cast<const char *>(data), size);
124     auto paramPeerName = fuzzedString;
125     auto paramPeerPid = static_cast<int64_t>(size);
126     auto errCode = static_cast<int32_t>(size);
127     auto paramIEventCode = static_cast<int32_t>(size);
128     auto info = HiSysOriginalInfo::Builder()
129                     .SetPeerName(paramPeerName)
130                     .SetPeerPid(paramPeerPid)
131                     .SetClientType(PARAM_CLIENT_TYPE)
132                     .SetEventCode(paramIEventCode)
133                     .SetErrCode(errCode)
134                     .Build();
135     ImaHiSysEventReporter::GetInstance().ReportEvent(ImfEventType::BASE_TEXT_OPERATOR, *info);
136 }
137 } // namespace OHOS
138 
139 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)140 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
141 {
142     if (data == nullptr || size == 0) {
143         return 0;
144     }
145     /* Run your code on data */
146     OHOS::TestClientAttach01(data, size);
147     OHOS::TestClientAttach02(data, size);
148     OHOS::TestClientShow(data, size);
149     OHOS::TestStartInput(data, size);
150     OHOS::TestBaseTextOperation(data, size);
151     return 0;
152 }