1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#include "stubhandleallocsocketfd_fuzzer.h" 17c29fa5a6Sopenharmony_ci 18c29fa5a6Sopenharmony_ci#include "mmi_service.h" 19c29fa5a6Sopenharmony_ci#include "multimodal_input_connect_stub.h" 20c29fa5a6Sopenharmony_ci 21c29fa5a6Sopenharmony_ci#undef MMI_LOG_TAG 22c29fa5a6Sopenharmony_ci#define MMI_LOG_TAG "StubHandleAllocSocketFdFuzzTest" 23c29fa5a6Sopenharmony_ci 24c29fa5a6Sopenharmony_ciclass UDSSession; 25c29fa5a6Sopenharmony_ciusing SessionPtr = std::shared_ptr<UDSSession>; 26c29fa5a6Sopenharmony_ci 27c29fa5a6Sopenharmony_cinamespace OHOS { 28c29fa5a6Sopenharmony_cinamespace MMI { 29c29fa5a6Sopenharmony_ciconst std::u16string FORMMGR_INTERFACE_TOKEN { u"ohos.multimodalinput.IConnectManager" }; 30c29fa5a6Sopenharmony_ciEpollEventType event_type = EPOLL_EVENT_SIGNAL; 31c29fa5a6Sopenharmony_ciInputHandlerType handlerType = NONE; 32c29fa5a6Sopenharmony_ciHandleEventType eventType = HANDLE_EVENT_TYPE_NONE; 33c29fa5a6Sopenharmony_ciint32_t tmpfd = 1; 34c29fa5a6Sopenharmony_ciuint32_t tmp32 = 1; 35c29fa5a6Sopenharmony_ciint32_t type = 1; 36c29fa5a6Sopenharmony_ciint64_t number = 1; 37c29fa5a6Sopenharmony_ciint32_t infoId = 1; 38c29fa5a6Sopenharmony_ciint32_t userId = 1; 39c29fa5a6Sopenharmony_ciint32_t deviceId = 1; 40c29fa5a6Sopenharmony_ciuint32_t frameCount = 1; 41c29fa5a6Sopenharmony_ciuint32_t vsyncCount = 1; 42c29fa5a6Sopenharmony_ciint64_t infraredFrequency = 1; 43c29fa5a6Sopenharmony_cistd::vector<int32_t> vecInt = { 1, 2, 3 }; 44c29fa5a6Sopenharmony_cistd::vector<bool> vecBool = { 1 }; 45c29fa5a6Sopenharmony_cistd::vector<std::u16string> argString = { u"hello", u"worid" }; 46c29fa5a6Sopenharmony_cistd::vector<int64_t> patternInt = { 1, 2, 3 }; 47c29fa5a6Sopenharmony_cistd::map<int32_t, int32_t> mpInt = { { 1, 2 }, { 2, 2 }, { 3, 2 } }; 48c29fa5a6Sopenharmony_cistd::vector<InfraredFrequency> requencysInf = { { 1, 2 }, { 2, 2 } }; 49c29fa5a6Sopenharmony_ciint32_t g_tmpDate = 1; 50c29fa5a6Sopenharmony_civoid* g_pixelMapPtr = &g_tmpDate; 51c29fa5a6Sopenharmony_cibool g_isAuthorize = true; 52c29fa5a6Sopenharmony_cibool g_isNativeInject = true; 53c29fa5a6Sopenharmony_cibool g_switchFlag = true; 54c29fa5a6Sopenharmony_cibool g_enableFlag = true; 55c29fa5a6Sopenharmony_cibool g_rotateSwitchFlag = true; 56c29fa5a6Sopenharmony_cibool g_stateFlag = true; 57c29fa5a6Sopenharmony_cistd::string message = "hello"; 58c29fa5a6Sopenharmony_cistd::string businessId = "hello"; 59c29fa5a6Sopenharmony_cistd::string flag = "hello"; 60c29fa5a6Sopenharmony_cistd::shared_ptr<InputDevice> inputDevice; 61c29fa5a6Sopenharmony_cistd::shared_ptr<InputDevice> device; 62c29fa5a6Sopenharmony_cistd::shared_ptr<PointerEvent> pointerEvent; 63c29fa5a6Sopenharmony_cistd::shared_ptr<KeyOption> p_option; 64c29fa5a6Sopenharmony_cistd::shared_ptr<KeyEvent> keyEvent; 65c29fa5a6Sopenharmony_ci 66c29fa5a6Sopenharmony_cibool StubHandleAllocSocketFdFuzzTest(const uint8_t *data, size_t size) 67c29fa5a6Sopenharmony_ci{ 68c29fa5a6Sopenharmony_ci MessageParcel datas; 69c29fa5a6Sopenharmony_ci if (!datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN) || 70c29fa5a6Sopenharmony_ci !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) { 71c29fa5a6Sopenharmony_ci return false; 72c29fa5a6Sopenharmony_ci } 73c29fa5a6Sopenharmony_ci MessageParcel reply; 74c29fa5a6Sopenharmony_ci MessageOption option; 75c29fa5a6Sopenharmony_ci MMIService::GetInstance()->AddEpoll(event_type, tmpfd); 76c29fa5a6Sopenharmony_ci MMIService::GetInstance()->DelEpoll(event_type, tmpfd); 77c29fa5a6Sopenharmony_ci MMIService::GetInstance()->InitLibinputService(); 78c29fa5a6Sopenharmony_ci MMIService::GetInstance()->InitDelegateTasks(); 79c29fa5a6Sopenharmony_ci MMIService::GetInstance()->AddAppDebugListener(); 80c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetMouseScrollRows(tmpfd); 81c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetMouseIcon(tmpfd, g_pixelMapPtr); 82c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadMouseScrollRows(tmpfd); 83c29fa5a6Sopenharmony_ci MMIService::GetInstance()->MarkProcessed(tmpfd, tmpfd); 84c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadPointerColor(tmpfd); 85c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnSupportKeys(tmpfd, vecInt, vecBool); 86c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnGetDeviceIds(vecInt); 87c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnGetDevice(tmpfd, inputDevice); 88c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnGetKeyboardType(tmpfd, tmpfd); 89c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetKeyboardRepeatDelay(tmpfd); 90c29fa5a6Sopenharmony_ci MMIService::GetInstance()->CheckRemoveInput(tmpfd, handlerType, eventType, tmpfd, tmp32); 91c29fa5a6Sopenharmony_ci MMIService::GetInstance()->RemoveInputHandler(handlerType, eventType, tmpfd, tmp32); 92c29fa5a6Sopenharmony_ci MMIService::GetInstance()->MarkEventConsumed(tmpfd); 93c29fa5a6Sopenharmony_ci MMIService::GetInstance()->MoveMouseEvent(tmpfd, tmpfd); 94c29fa5a6Sopenharmony_ci MMIService::GetInstance()->InjectKeyEvent(keyEvent, g_isNativeInject); 95c29fa5a6Sopenharmony_ci MMIService::GetInstance()->CheckInjectKeyEvent(keyEvent, tmpfd, g_isNativeInject); 96c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnGetKeyState(vecInt, mpInt); 97c29fa5a6Sopenharmony_ci MMIService::GetInstance()->InjectPointerEvent(pointerEvent, g_isNativeInject); 98c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnAddSystemAbility(tmpfd, "deviceId"); 99c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SubscribeKeyEvent(tmpfd, p_option); 100c29fa5a6Sopenharmony_ci MMIService::GetInstance()->UnsubscribeKeyEvent(tmpfd); 101c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SubscribeSwitchEvent(tmpfd, tmpfd); 102c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetDisplayBind(tmpfd, tmpfd, message); 103c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetFunctionKeyState(tmpfd, g_enableFlag); 104c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetPointerLocation(tmpfd, tmpfd); 105c29fa5a6Sopenharmony_ci MMIService::GetInstance()->AddReloadDeviceTimer(); 106c29fa5a6Sopenharmony_ci MMIService::GetInstance()->Dump(tmpfd, argString); 107c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnGetWindowPid(tmpfd, tmpfd); 108c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetWindowPid(tmpfd); 109c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetKeyDownDuration(businessId, tmpfd); 110c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadScrollSwich(g_switchFlag); 111c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadScrollDirection(g_switchFlag); 112c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadTapSwitch(g_switchFlag); 113c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadPointerSpeed(tmpfd); 114c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadPinchSwitch(g_switchFlag); 115c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadSwipeSwitch(g_switchFlag); 116c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadRightMenuType(tmpfd); 117c29fa5a6Sopenharmony_ci MMIService::GetInstance()->ReadTouchpadRotateSwitch(g_rotateSwitchFlag); 118c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadScrollSwitch(g_switchFlag); 119c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadScrollSwitch(g_switchFlag); 120c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadScrollDirection(g_stateFlag); 121c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadScrollDirection(g_stateFlag); 122c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadTapSwitch(g_switchFlag); 123c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadTapSwitch(g_switchFlag); 124c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadPointerSpeed(tmpfd); 125c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadPointerSpeed(tmpfd); 126c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadPinchSwitch(g_switchFlag); 127c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadPinchSwitch(g_switchFlag); 128c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadSwipeSwitch(g_switchFlag); 129c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadSwipeSwitch(g_switchFlag); 130c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadRightClickType(type); 131c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetTouchpadRotateSwitch(g_rotateSwitchFlag); 132c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetTouchpadRotateSwitch(g_rotateSwitchFlag); 133c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetKeyState(vecInt, mpInt); 134c29fa5a6Sopenharmony_ci MMIService::GetInstance()->Authorize(g_isAuthorize); 135c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnAuthorize(g_isAuthorize); 136c29fa5a6Sopenharmony_ci MMIService::GetInstance()->CancelInjection(); 137c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnCancelInjection(); 138c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetInfraredFrequencies(requencysInf); 139c29fa5a6Sopenharmony_ci MMIService::GetInstance()->TransmitInfrared(number, patternInt); 140c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetPixelMapData(infoId, g_pixelMapPtr); 141c29fa5a6Sopenharmony_ci MMIService::GetInstance()->SetCurrentUser(userId); 142c29fa5a6Sopenharmony_ci MMIService::GetInstance()->AddVirtualInputDevice(device, deviceId); 143c29fa5a6Sopenharmony_ci MMIService::GetInstance()->RemoveVirtualInputDevice(tmpfd); 144c29fa5a6Sopenharmony_ci MMIService::GetInstance()->EnableHardwareCursorStats(g_enableFlag); 145c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount); 146c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR 147c29fa5a6Sopenharmony_ci MMIService::GetInstance()->GetPointerSnapshot(g_pixelMapPtr); 148c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MAGICCURSOR 149c29fa5a6Sopenharmony_ci MMIService::GetInstance()->state_ = ServiceRunningState::STATE_RUNNING; 150c29fa5a6Sopenharmony_ci MMIService::GetInstance()->OnRemoteRequest( 151c29fa5a6Sopenharmony_ci static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ALLOC_SOCKET_FD), datas, reply, option); 152c29fa5a6Sopenharmony_ci return true; 153c29fa5a6Sopenharmony_ci} 154c29fa5a6Sopenharmony_ci} // MMI 155c29fa5a6Sopenharmony_ci} // OHOS 156c29fa5a6Sopenharmony_ci 157c29fa5a6Sopenharmony_ci/* Fuzzer entry point */ 158c29fa5a6Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 159c29fa5a6Sopenharmony_ci{ 160c29fa5a6Sopenharmony_ci /* Run your code on data */ 161c29fa5a6Sopenharmony_ci if (data == nullptr) { 162c29fa5a6Sopenharmony_ci return 0; 163c29fa5a6Sopenharmony_ci } 164c29fa5a6Sopenharmony_ci 165c29fa5a6Sopenharmony_ci OHOS::MMI::StubHandleAllocSocketFdFuzzTest(data, size); 166c29fa5a6Sopenharmony_ci return 0; 167c29fa5a6Sopenharmony_ci} 168