1 /*
2 * Copyright (c) 2022 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 "accessibleabilityclient_fuzzer.h"
17 #include "accessibility_element_info.h"
18 #include "accessibility_gesture_inject_path.h"
19 #include "accessibility_ui_test_ability.h"
20 #include "accessible_ability_listener.h"
21 #include "securec.h"
22
23 namespace OHOS {
24 namespace {
25 constexpr size_t DATA_MIN_SIZE = 416;
26 constexpr char END_CHAR = '\0';
27 constexpr size_t LEN = 10;
28 constexpr size_t VEC_SIZE = 5;
29 constexpr size_t MAP_SIZE = 5;
30 } // namespace
31
32 template<class T>
GetObject(T & object,const uint8_t * data,size_t size)33 size_t GetObject(T &object, const uint8_t *data, size_t size)
34 {
35 size_t objectSize = sizeof(object);
36 if (objectSize > size) {
37 return 0;
38 }
39 return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0;
40 }
41
42 class AccessibleAbilityListenerForFuzzTest : public Accessibility::AccessibleAbilityListener {
43 public:
44 virtual ~AccessibleAbilityListenerForFuzzTest() = default;
OnAbilityConnected()45 void OnAbilityConnected() override {}
OnAbilityDisconnected()46 void OnAbilityDisconnected() override {}
OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo & eventInfo)47 void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo &eventInfo) override {}
OnKeyPressEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)48 bool OnKeyPressEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent) override
49 {
50 return false;
51 }
52 };
53
GenerateRect(OHOS::Accessibility::Rect & bounds,const uint8_t * data,size_t size)54 static size_t GenerateRect(OHOS::Accessibility::Rect &bounds, const uint8_t* data, size_t size)
55 {
56 size_t position = 0;
57 int32_t posX = 0;
58 int32_t posY = 0;
59 position += GetObject<int32_t>(posX, &data[position], size - position);
60 position += GetObject<int32_t>(posY, &data[position], size - position);
61 bounds.SetLeftTopScreenPostion(posX, posY);
62
63 position += GetObject<int32_t>(posX, &data[position], size - position);
64 position += GetObject<int32_t>(posY, &data[position], size - position);
65 bounds.SetRightBottomScreenPostion(posX, posY);
66 return position;
67 }
68
GenerateRangeInfo(OHOS::Accessibility::RangeInfo & rangeInfo,const uint8_t * data,size_t size)69 static size_t GenerateRangeInfo(OHOS::Accessibility::RangeInfo &rangeInfo, const uint8_t* data, size_t size)
70 {
71 size_t position = 0;
72 int32_t int32Data = 0;
73 position += GetObject<int32_t>(int32Data, &data[position], size - position);
74 rangeInfo.SetMin(int32Data);
75
76 position += GetObject<int32_t>(int32Data, &data[position], size - position);
77 rangeInfo.SetMax(int32Data);
78
79 position += GetObject<int32_t>(int32Data, &data[position], size - position);
80 rangeInfo.SetCurrent(int32Data);
81 return position;
82 }
83
GenerateGridInfo(OHOS::Accessibility::GridInfo & grid,const uint8_t * data,size_t size)84 static size_t GenerateGridInfo(OHOS::Accessibility::GridInfo &grid, const uint8_t* data, size_t size)
85 {
86 size_t position = 0;
87 int32_t rowCount = 0;
88 int32_t columnCount = 0;
89 int32_t selectionMode = 0;
90 position += GetObject<int32_t>(rowCount, &data[position], size - position);
91 position += GetObject<int32_t>(columnCount, &data[position], size - position);
92 position += GetObject<int32_t>(selectionMode, &data[position], size - position);
93 grid.SetGrid(rowCount, columnCount, selectionMode);
94 return position;
95 }
96
GenerateGridItemInfo(OHOS::Accessibility::GridItemInfo & gridItem,const uint8_t * data,size_t size)97 static size_t GenerateGridItemInfo(OHOS::Accessibility::GridItemInfo &gridItem, const uint8_t* data, size_t size)
98 {
99 size_t position = 0;
100 int32_t columnIndex_ = 0;
101 int32_t rowIndex = 0;
102 int32_t columnSpan = 0;
103 int32_t rowSpan = 0;
104 position += GetObject<int32_t>(columnIndex_, &data[position], size - position);
105 position += GetObject<int32_t>(rowIndex, &data[position], size - position);
106 position += GetObject<int32_t>(columnSpan, &data[position], size - position);
107 position += GetObject<int32_t>(rowSpan, &data[position], size - position);
108 bool heading = data[position++] & 0x01;
109 bool selected = data[position++] & 0x01;
110 gridItem.SetGridItemInfo(rowIndex, rowSpan, columnIndex_, columnSpan, heading, selected);
111 return position;
112 }
113
GenerateAccessibilityElementInfoP1(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)114 static void GenerateAccessibilityElementInfoP1(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
115 const uint8_t* data, size_t size, size_t& position)
116 {
117 int32_t int32Data = 0;
118 int64_t int64Data = 0;
119 position += GetObject<int32_t>(int32Data, &data[position], size - position);
120 sourceElementInfo.SetPageId(int32Data);
121
122 position += GetObject<int32_t>(int32Data, &data[position], size - position);
123 sourceElementInfo.SetWindowId(int32Data);
124
125 position += GetObject<int64_t>(int64Data, &data[position], size - position);
126 sourceElementInfo.SetAccessibilityId(int64Data);
127
128 position += GetObject<int64_t>(int64Data, &data[position], size - position);
129 sourceElementInfo.SetComponentId(int64Data);
130
131 position += GetObject<int64_t>(int64Data, &data[position], size - position);
132 sourceElementInfo.SetParent(int64Data);
133
134 position += GetObject<int32_t>(int32Data, &data[position], size - position);
135 sourceElementInfo.SetTextLengthLimit(int32Data);
136
137 position += GetObject<int32_t>(int32Data, &data[position], size - position);
138 sourceElementInfo.SetCurrentIndex(int32Data);
139
140 position += GetObject<int32_t>(int32Data, &data[position], size - position);
141 sourceElementInfo.SetBeginIndex(int32Data);
142
143 position += GetObject<int32_t>(int32Data, &data[position], size - position);
144 sourceElementInfo.SetEndIndex(int32Data);
145
146 position += GetObject<int32_t>(int32Data, &data[position], size - position);
147 sourceElementInfo.SetLiveRegion(int32Data);
148
149 position += GetObject<int32_t>(int32Data, &data[position], size - position);
150 sourceElementInfo.SetLabeled(int32Data);
151
152 position += GetObject<int32_t>(int32Data, &data[position], size - position);
153 sourceElementInfo.SetSelectedBegin(int32Data);
154
155 position += GetObject<int32_t>(int32Data, &data[position], size - position);
156 sourceElementInfo.SetSelectedEnd(int32Data);
157
158 position += GetObject<int32_t>(int32Data, &data[position], size - position);
159 sourceElementInfo.SetInputType(int32Data);
160
161 position += GetObject<int32_t>(int32Data, &data[position], size - position);
162 sourceElementInfo.SetItemCounts(int32Data);
163
164 position += GetObject<int32_t>(int32Data, &data[position], size - position);
165 sourceElementInfo.SetTriggerAction(static_cast<OHOS::Accessibility::ActionType>(int32Data));
166
167 position += GetObject<int32_t>(int32Data, &data[position], size - position);
168 sourceElementInfo.SetTextMovementStep(static_cast<OHOS::Accessibility::TextMoveUnit>(int32Data));
169
170 for (size_t i = 0; i < VEC_SIZE; i++) {
171 position += GetObject<int64_t>(int64Data, &data[position], size - position);
172 sourceElementInfo.AddChild(int64Data);
173 }
174 }
175
GenerateAccessibilityElementInfoP2(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)176 static void GenerateAccessibilityElementInfoP2(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
177 const uint8_t* data, size_t size, size_t& position)
178 {
179 char name[LEN + 1];
180 name[LEN] = END_CHAR;
181 for (size_t i = 0; i < LEN; i++) {
182 position += GetObject<char>(name[i], &data[position], size - position);
183 }
184 std::string bundleName(name);
185 sourceElementInfo.SetBundleName(bundleName);
186
187 for (size_t i = 0; i < LEN; i++) {
188 position += GetObject<char>(name[i], &data[position], size - position);
189 }
190 std::string componentType(name);
191 sourceElementInfo.SetComponentType(componentType);
192
193 for (size_t i = 0; i < LEN; i++) {
194 position += GetObject<char>(name[i], &data[position], size - position);
195 }
196 std::string text(name);
197 sourceElementInfo.SetContent(text);
198
199 for (size_t i = 0; i < LEN; i++) {
200 position += GetObject<char>(name[i], &data[position], size - position);
201 }
202 std::string hintText(name);
203 sourceElementInfo.SetHint(hintText);
204
205 for (size_t i = 0; i < LEN; i++) {
206 position += GetObject<char>(name[i], &data[position], size - position);
207 }
208 std::string contentDescription(name);
209 sourceElementInfo.SetDescriptionInfo(contentDescription);
210
211 for (size_t i = 0; i < LEN; i++) {
212 position += GetObject<char>(name[i], &data[position], size - position);
213 }
214 std::string resourceName(name);
215 sourceElementInfo.SetComponentResourceId(resourceName);
216
217 for (size_t i = 0; i < LEN; i++) {
218 position += GetObject<char>(name[i], &data[position], size - position);
219 }
220 std::string inspectorKey(name);
221 sourceElementInfo.SetInspectorKey(inspectorKey);
222
223 for (size_t i = 0; i < LEN; i++) {
224 position += GetObject<char>(name[i], &data[position], size - position);
225 }
226 std::string error(name);
227 sourceElementInfo.SetError(error);
228 }
229
GenerateAccessibilityElementInfoP3(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)230 static void GenerateAccessibilityElementInfoP3(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
231 const uint8_t* data, size_t size, size_t& position)
232 {
233 sourceElementInfo.SetCheckable(data[position++] & 0x01);
234 sourceElementInfo.SetChecked(data[position++] & 0x01);
235 sourceElementInfo.SetFocusable(data[position++] & 0x01);
236 sourceElementInfo.SetFocused(data[position++] & 0x01);
237 sourceElementInfo.SetVisible(data[position++] & 0x01);
238 sourceElementInfo.SetAccessibilityFocus(data[position++] & 0x01);
239 sourceElementInfo.SetSelected(data[position++] & 0x01);
240 sourceElementInfo.SetClickable(data[position++] & 0x01);
241 sourceElementInfo.SetLongClickable(data[position++] & 0x01);
242 sourceElementInfo.SetEnabled(data[position++] & 0x01);
243 sourceElementInfo.SetPassword(data[position++] & 0x01);
244 sourceElementInfo.SetScrollable(data[position++] & 0x01);
245 sourceElementInfo.SetEditable(data[position++] & 0x01);
246 sourceElementInfo.SetPopupSupported(data[position++] & 0x01);
247 sourceElementInfo.SetPluraLineSupported(data[position++] & 0x01);
248 sourceElementInfo.SetDeletable(data[position++] & 0x01);
249 sourceElementInfo.SetHinting(data[position++] & 0x01);
250 sourceElementInfo.SetEssential(data[position++] & 0x01);
251 sourceElementInfo.SetContentInvalid(data[position++] & 0x01);
252 sourceElementInfo.SetValidElement(data[position++] & 0x01);
253
254 OHOS::Accessibility::Rect bounds;
255 position += GenerateRect(bounds, &data[position], size - position);
256 sourceElementInfo.SetRectInScreen(bounds);
257
258 OHOS::Accessibility::RangeInfo rangeInfo;
259 position += GenerateRangeInfo(rangeInfo, &data[position], size - position);
260 sourceElementInfo.SetRange(rangeInfo);
261
262 OHOS::Accessibility::GridInfo grid;
263 position += GenerateGridInfo(grid, &data[position], size - position);
264 sourceElementInfo.SetGrid(grid);
265
266 OHOS::Accessibility::GridItemInfo gridItem;
267 position += GenerateGridItemInfo(gridItem, &data[position], size - position);
268 sourceElementInfo.SetGridItem(gridItem);
269
270 OHOS::Accessibility::GridItemInfo otherGridItem;
271 otherGridItem.SetGridItemInfo(gridItem);
272
273 int32_t int32Data = 0;
274 char name[LEN + 1];
275 name[LEN] = END_CHAR;
276 for (size_t count = 0; count < VEC_SIZE; count++) {
277 position += GetObject<int32_t>(int32Data, &data[position], size - position);
278 for (size_t i = 0; i < LEN; i++) {
279 position += GetObject<char>(name[i], &data[position], size - position);
280 }
281 std::string description(name);
282 OHOS::Accessibility::AccessibleAction action(
283 static_cast<OHOS::Accessibility::ActionType>(int32Data), description);
284 sourceElementInfo.AddAction(action);
285 }
286 }
287
GenerateAccessibilityElementInfoP4(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)288 static void GenerateAccessibilityElementInfoP4(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
289 const uint8_t* data, size_t size, size_t& position)
290 {
291 char name[LEN + 1];
292 name[LEN] = END_CHAR;
293 std::vector<std::string> contentList;
294 for (size_t count = 0; count < VEC_SIZE; count++) {
295 char name[LEN + 1];
296 name[LEN] = END_CHAR;
297 for (size_t i = 0; i < LEN; i++) {
298 position += GetObject<char>(name[i], &data[position], size - position);
299 }
300 std::string content(name);
301 contentList.push_back(content);
302 }
303 sourceElementInfo.SetContentList(contentList);
304
305 for (size_t i = 0; i < LEN; i++) {
306 position += GetObject<char>(name[i], &data[position], size - position);
307 }
308 std::string latestContent(name);
309 sourceElementInfo.SetLatestContent(latestContent);
310
311 for (size_t i = 0; i < LEN; i++) {
312 position += GetObject<char>(name[i], &data[position], size - position);
313 }
314 std::string pagePath(name);
315 sourceElementInfo.SetPagePath(pagePath);
316
317 for (size_t i = 0; i < LEN; i++) {
318 position += GetObject<char>(name[i], &data[position], size - position);
319 }
320 std::string accessibilityText(name);
321 sourceElementInfo.SetAccessibilityText(accessibilityText);
322
323 for (size_t i = 0; i < LEN; i++) {
324 position += GetObject<char>(name[i], &data[position], size - position);
325 }
326 std::string textType(name);
327 sourceElementInfo.SetTextType(textType);
328 }
329
GenerateAccessibilityElementInfoP5(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)330 static void GenerateAccessibilityElementInfoP5(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
331 const uint8_t* data, size_t size, size_t& position)
332 {
333 float offset = 0.0;
334 position += GetObject<float>(offset, &data[position], size - position);
335 sourceElementInfo.SetOffset(offset);
336
337 int32_t iChildTreeId = 0;
338 int32_t iChildWindowId = 0;
339 position += GetObject<int32_t>(iChildTreeId, &data[position], size - position);
340 position += GetObject<int32_t>(iChildWindowId, &data[position], size - position);
341 sourceElementInfo.SetChildTreeIdAndWinId(iChildTreeId, iChildWindowId);
342
343 int32_t int32Data = 0;
344 position += GetObject<int32_t>(int32Data, &data[position], size - position);
345 sourceElementInfo.SetBelongTreeId(int32Data);
346
347 position += GetObject<int32_t>(int32Data, &data[position], size - position);
348 sourceElementInfo.SetParentWindowId(int32Data);
349
350 position += GetObject<int32_t>(int32Data, &data[position], size - position);
351 sourceElementInfo.SetMainWindowId(int32Data);
352
353 position += GetObject<int32_t>(int32Data, &data[position], size - position);
354 sourceElementInfo.SetInnerWindowId(int32Data);
355 }
356
GenerateAccessibilityElementInfo(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size)357 static size_t GenerateAccessibilityElementInfo(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
358 const uint8_t* data, size_t size)
359 {
360 size_t position = 0;
361 GenerateAccessibilityElementInfoP1(sourceElementInfo, data, size, position);
362 GenerateAccessibilityElementInfoP2(sourceElementInfo, data, size, position);
363 GenerateAccessibilityElementInfoP3(sourceElementInfo, data, size, position);
364 GenerateAccessibilityElementInfoP4(sourceElementInfo, data, size, position);
365 GenerateAccessibilityElementInfoP5(sourceElementInfo, data, size, position);
366 return position;
367 }
368
GenerateAccessibilityWindowInfo(OHOS::Accessibility::AccessibilityWindowInfo & sourceWindowInfo,const uint8_t * data,size_t size)369 static size_t GenerateAccessibilityWindowInfo(OHOS::Accessibility::AccessibilityWindowInfo &sourceWindowInfo,
370 const uint8_t* data, size_t size)
371 {
372 size_t position = 0;
373 uint64_t uint64Data = 0;
374 position += GetObject<uint64_t>(uint64Data, &data[position], size - position);
375 sourceWindowInfo.SetDisplayId(uint64Data);
376
377 uint32_t uint32Data = 0;
378 position += GetObject<uint32_t>(uint32Data, &data[position], size - position);
379 sourceWindowInfo.SetWindowMode(uint32Data);
380
381 position += GetObject<uint32_t>(uint32Data, &data[position], size - position);
382 sourceWindowInfo.SetWindowType(uint32Data);
383
384 int32_t int32Data = 0;
385 position += GetObject<int32_t>(int32Data, &data[position], size - position);
386 sourceWindowInfo.SetAccessibilityWindowType(static_cast<OHOS::Accessibility::AccessibilityWindowType>(int32Data));
387
388 position += GetObject<int32_t>(int32Data, &data[position], size - position);
389 sourceWindowInfo.SetWindowLayer(int32Data);
390
391 position += GetObject<int32_t>(int32Data, &data[position], size - position);
392 sourceWindowInfo.SetWindowId(int32Data);
393
394 sourceWindowInfo.SetActive(data[position++] & 0x01);
395 sourceWindowInfo.SetFocused(data[position++] & 0x01);
396 sourceWindowInfo.SetAccessibilityFocused(data[position++] & 0x01);
397 sourceWindowInfo.SetDecorEnable(data[position++] & 0x01);
398
399 position += GetObject<int32_t>(int32Data, &data[position], size - position);
400 sourceWindowInfo.SetInnerWid(int32Data);
401
402 position += GetObject<int32_t>(int32Data, &data[position], size - position);
403 sourceWindowInfo.SetMainWindowId(int32Data);
404
405 int64_t int64Data = 0;
406 position += GetObject<int64_t>(int64Data, &data[position], size - position);
407 sourceWindowInfo.SetUiNodeId(int32Data);
408
409 float floatData = 0.0;
410 position += GetObject<float>(floatData, &data[position], size - position);
411 sourceWindowInfo.SetScaleVal(floatData);
412
413 position += GetObject<float>(floatData, &data[position], size - position);
414 sourceWindowInfo.SetScaleX(floatData);
415
416 position += GetObject<float>(floatData, &data[position], size - position);
417 sourceWindowInfo.SetScaleY(floatData);
418
419 char name[LEN + 1];
420 name[LEN] = END_CHAR;
421 for (size_t i = 0; i < LEN; i++) {
422 position += GetObject<char>(name[i], &data[position], size - position);
423 }
424 std::string bundleName(name);
425 sourceWindowInfo.SetBundleName(bundleName);
426
427 OHOS::Accessibility::Rect bounds;
428 position += GenerateRect(bounds, &data[position], size - position);
429 sourceWindowInfo.SetRectInScreen(bounds);
430 std::vector<OHOS::Accessibility::Rect> touchHotAreas = {bounds};
431 sourceWindowInfo.SetTouchHotAreas(touchHotAreas);
432 return position;
433 }
434
GenerateAccessibilityEventInfo(OHOS::Accessibility::AccessibilityEventInfo & sourceEventInfo,const uint8_t * data,size_t size)435 static size_t GenerateAccessibilityEventInfo(OHOS::Accessibility::AccessibilityEventInfo &sourceEventInfo,
436 const uint8_t* data, size_t size)
437 {
438 size_t position = 0;
439 uint32_t uint32Data = 0;
440 position += GetObject<uint32_t>(uint32Data, &data[position], size - position);
441 sourceEventInfo.SetEventType(static_cast<OHOS::Accessibility::EventType>(uint32Data));
442
443 position += GetObject<uint32_t>(uint32Data, &data[position], size - position);
444 sourceEventInfo.SetGestureType(static_cast<OHOS::Accessibility::GestureType>(uint32Data));
445
446 char name[LEN + 1];
447 name[LEN] = END_CHAR;
448 for (size_t i = 0; i < LEN; i++) {
449 position += GetObject<char>(name[i], &data[position], size - position);
450 }
451 std::string bundleName(name);
452 sourceEventInfo.SetBundleName(bundleName);
453
454 for (size_t i = 0; i < LEN; i++) {
455 position += GetObject<char>(name[i], &data[position], size - position);
456 }
457 std::string notificationContent(name);
458 sourceEventInfo.SetNotificationContent(notificationContent);
459
460 int32_t int32Data = 0;
461 position += GetObject<int32_t>(int32Data, &data[position], size - position);
462 sourceEventInfo.SetTriggerAction(static_cast<OHOS::Accessibility::ActionType>(int32Data));
463
464 position += GetObject<int32_t>(int32Data, &data[position], size - position);
465 sourceEventInfo.SetTextMovementStep(static_cast<OHOS::Accessibility::TextMoveUnit>(int32Data));
466
467 position += GetObject<int32_t>(int32Data, &data[position], size - position);
468 sourceEventInfo.SetWindowContentChangeTypes(
469 static_cast<OHOS::Accessibility::WindowsContentChangeTypes>(int32Data));
470
471 position += GetObject<int32_t>(int32Data, &data[position], size - position);
472 sourceEventInfo.SetWindowChangeTypes(static_cast<OHOS::Accessibility::WindowUpdateType>(int32Data));
473
474 position += GetObject<int32_t>(int32Data, &data[position], size - position);
475 sourceEventInfo.SetNotificationInfo(static_cast<OHOS::Accessibility::NotificationCategory>(int32Data));
476
477 position += GetObject<int32_t>(int32Data, &data[position], size - position);
478 sourceEventInfo.SetPageId(int32Data);
479
480 int64_t int64Data = 0;
481 position += GetObject<int64_t>(int64Data, &data[position], size - position);
482 sourceEventInfo.SetTimeStamp(int64Data);
483
484 return position;
485 }
486
DoSomethingInterestingWithRegisterAbilityListener()487 bool DoSomethingInterestingWithRegisterAbilityListener()
488 {
489 std::shared_ptr<AccessibleAbilityListenerForFuzzTest> listener =
490 std::make_shared<AccessibleAbilityListenerForFuzzTest>();
491 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->RegisterAbilityListener(listener);
492 return true;
493 }
494
DoSomethingInterestingWithGetFocus(const uint8_t * data,size_t size)495 bool DoSomethingInterestingWithGetFocus(const uint8_t* data, size_t size)
496 {
497 if (data == nullptr || size < DATA_MIN_SIZE) {
498 return false;
499 }
500
501 size_t startPos = 0;
502 int32_t focusType = 0;
503 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
504 GetObject<int32_t>(focusType, &data[startPos], size - startPos);
505 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetFocus(focusType, resultElementInfo);
506
507 return true;
508 }
509
DoSomethingInterestingWithGetFocusByElementInfo(const uint8_t * data,size_t size)510 bool DoSomethingInterestingWithGetFocusByElementInfo(const uint8_t* data, size_t size)
511 {
512 if (data == nullptr || size < DATA_MIN_SIZE) {
513 return false;
514 }
515
516 size_t startPos = 0;
517 int32_t focusType = 0;
518 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
519 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
520 startPos += GetObject<int32_t>(focusType, &data[startPos], size - startPos);
521 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
522 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetFocusByElementInfo(
523 sourceElementInfo, focusType, resultElementInfo);
524
525 return true;
526 }
527
DoSomethingInterestingWithInjectGesture(const uint8_t * data,size_t size)528 bool DoSomethingInterestingWithInjectGesture(const uint8_t* data, size_t size)
529 {
530 if (data == nullptr || size < DATA_MIN_SIZE) {
531 return false;
532 }
533
534 size_t startPos = 0;
535 Accessibility::AccessibilityGesturePosition position;
536 float point = .0f;
537 startPos += GetObject<float>(point, &data[startPos], size - startPos);
538 position.positionX_ = point;
539
540 startPos += GetObject<float>(point, &data[startPos], size - startPos);
541 position.positionY_ = point;
542
543 std::shared_ptr<Accessibility::AccessibilityGestureInjectPath> gesturePath =
544 std::make_shared<Accessibility::AccessibilityGestureInjectPath>();
545 gesturePath->AddPosition(position);
546
547 int64_t int64Data = 0;
548 GetObject<int64_t>(int64Data, &data[startPos], size - startPos);
549 gesturePath->SetDurationTime(int64Data);
550 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->InjectGesture(gesturePath);
551 gesturePath->GetDurationTime();
552 gesturePath->GetPositions();
553 return true;
554 }
555
DoSomethingInterestingWithGetRoot(const uint8_t * data,size_t size)556 bool DoSomethingInterestingWithGetRoot(const uint8_t* data, size_t size)
557 {
558 if (data == nullptr || size < DATA_MIN_SIZE) {
559 return false;
560 }
561
562 size_t startPos = 0;
563 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
564 GenerateAccessibilityElementInfo(resultElementInfo, &data[startPos], size - startPos);
565 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetRoot(resultElementInfo);
566
567 return true;
568 }
569
DoSomethingInterestingWithGetRootByWindow(const uint8_t * data,size_t size)570 bool DoSomethingInterestingWithGetRootByWindow(const uint8_t* data, size_t size)
571 {
572 if (data == nullptr || size < DATA_MIN_SIZE) {
573 return false;
574 }
575
576 size_t startPos = 0;
577 OHOS::Accessibility::AccessibilityWindowInfo sourceWindowInfo;
578 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
579 GenerateAccessibilityWindowInfo(sourceWindowInfo, &data[startPos], size - startPos);
580 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetRootByWindow(
581 sourceWindowInfo, resultElementInfo);
582
583 return true;
584 }
585
DoSomethingInterestingWithGetWindow(const uint8_t * data,size_t size)586 bool DoSomethingInterestingWithGetWindow(const uint8_t* data, size_t size)
587 {
588 if (data == nullptr || size < DATA_MIN_SIZE) {
589 return false;
590 }
591
592 size_t startPos = 0;
593 int32_t windowId = 0;
594 OHOS::Accessibility::AccessibilityWindowInfo resultWindowInfo;
595 GetObject<int32_t>(windowId, &data[startPos], size - startPos);
596 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetWindow(windowId, resultWindowInfo);
597
598 return true;
599 }
600
DoSomethingInterestingWithGetWindows(const uint8_t * data,size_t size)601 bool DoSomethingInterestingWithGetWindows(const uint8_t* data, size_t size)
602 {
603 if (data == nullptr || size < DATA_MIN_SIZE) {
604 return false;
605 }
606
607 size_t startPos = 0;
608 std::vector<OHOS::Accessibility::AccessibilityWindowInfo> resultWindowInfos;
609 OHOS::Accessibility::AccessibilityWindowInfo windowInfo;
610 GenerateAccessibilityWindowInfo(windowInfo, &data[startPos], size - startPos);
611 resultWindowInfos.push_back(windowInfo);
612 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetWindows(resultWindowInfos);
613 return true;
614 }
615
DoSomethingInterestingWithGetWindowsByDisplayId(const uint8_t * data,size_t size)616 bool DoSomethingInterestingWithGetWindowsByDisplayId(const uint8_t* data, size_t size)
617 {
618 if (data == nullptr || size < DATA_MIN_SIZE) {
619 return false;
620 }
621
622 size_t startPos = 0;
623 uint64_t displayId = 0;
624 std::vector<OHOS::Accessibility::AccessibilityWindowInfo> resultWindowInfos;
625 GetObject<uint64_t>(displayId, &data[startPos], size - startPos);
626 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetWindows(displayId, resultWindowInfos);
627
628 return true;
629 }
630
DoSomethingInterestingWithGetNext(const uint8_t * data,size_t size)631 bool DoSomethingInterestingWithGetNext(const uint8_t* data, size_t size)
632 {
633 if (data == nullptr || size < DATA_MIN_SIZE) {
634 return false;
635 }
636
637 size_t startPos = 0;
638 int32_t direction = 0;
639 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
640 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
641 startPos += GetObject<int32_t>(direction, &data[startPos], size - startPos);
642 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
643 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetNext(sourceElementInfo,
644 static_cast<OHOS::Accessibility::FocusMoveDirection>(direction), resultElementInfo);
645
646 return true;
647 }
648
DoSomethingInterestingWithGetChildElementInfo(const uint8_t * data,size_t size)649 bool DoSomethingInterestingWithGetChildElementInfo(const uint8_t* data, size_t size)
650 {
651 if (data == nullptr || size < DATA_MIN_SIZE) {
652 return false;
653 }
654
655 size_t startPos = 0;
656 int32_t index = 0;
657 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
658 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
659 startPos += GetObject<int32_t>(index, &data[startPos], size - startPos);
660 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
661 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetChildElementInfo(
662 index, sourceElementInfo, resultElementInfo);
663 return true;
664 }
665
DoSomethingInterestingWithGetChildren(const uint8_t * data,size_t size)666 bool DoSomethingInterestingWithGetChildren(const uint8_t* data, size_t size)
667 {
668 if (data == nullptr || size < DATA_MIN_SIZE) {
669 return false;
670 }
671
672 size_t startPos = 0;
673 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
674 std::vector<OHOS::Accessibility::AccessibilityElementInfo> resultElementInfos;
675 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
676 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetChildren(sourceElementInfo, resultElementInfos);
677
678 return true;
679 }
680
DoSomethingInterestingWithGetByContent(const uint8_t * data,size_t size)681 bool DoSomethingInterestingWithGetByContent(const uint8_t* data, size_t size)
682 {
683 if (data == nullptr || size < DATA_MIN_SIZE) {
684 return false;
685 }
686
687 size_t startPos = 0;
688 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
689 std::vector<OHOS::Accessibility::AccessibilityElementInfo> resultElementInfos;
690 startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
691 char name[LEN + 1];
692 name[LEN] = END_CHAR;
693 for (size_t i = 0; i < LEN; i++) {
694 startPos += GetObject<char>(name[i], &data[startPos], size - startPos);
695 }
696 std::string text(name);
697 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetByContent(
698 sourceElementInfo, text, resultElementInfos);
699
700 return true;
701 }
702
DoSomethingInterestingWithGetSource(const uint8_t * data,size_t size)703 bool DoSomethingInterestingWithGetSource(const uint8_t* data, size_t size)
704 {
705 if (data == nullptr || size < DATA_MIN_SIZE) {
706 return false;
707 }
708
709 size_t startPos = 0;
710 OHOS::Accessibility::AccessibilityEventInfo sourceEventInfo;
711 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
712 GenerateAccessibilityEventInfo(sourceEventInfo, &data[startPos], size - startPos);
713 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetSource(sourceEventInfo, resultElementInfo);
714
715 return true;
716 }
717
DoSomethingInterestingWithGetParentElementInfo(const uint8_t * data,size_t size)718 bool DoSomethingInterestingWithGetParentElementInfo(const uint8_t* data, size_t size)
719 {
720 if (data == nullptr || size < DATA_MIN_SIZE) {
721 return false;
722 }
723
724 size_t startPos = 0;
725 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
726 OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
727 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
728 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetParentElementInfo(
729 sourceElementInfo, resultElementInfo);
730
731 return true;
732 }
733
DoSomethingInterestingWithExecuteAction(const uint8_t * data,size_t size)734 bool DoSomethingInterestingWithExecuteAction(const uint8_t* data, size_t size)
735 {
736 if (data == nullptr || size < DATA_MIN_SIZE) {
737 return false;
738 }
739
740 size_t startPos = 0;
741 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
742 startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
743 int32_t action = 0;
744 startPos += GetObject<int32_t>(action, &data[startPos], size - startPos);
745 std::map<std::string, std::string> actionArguments;
746 for (size_t count = 0; count < MAP_SIZE; count++) {
747 char name[LEN + 1];
748 name[LEN] = END_CHAR;
749 for (size_t i = 0; i < LEN; i++) {
750 startPos += GetObject<char>(name[i], &data[startPos], size - startPos);
751 }
752 std::string action1(name);
753 for (size_t i = 0; i < LEN; i++) {
754 startPos += GetObject<char>(name[i], &data[startPos], size - startPos);
755 }
756 std::string action2(name);
757 actionArguments.insert(std::make_pair(action1, action2));
758 }
759 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->ExecuteAction(
760 sourceElementInfo, static_cast<OHOS::Accessibility::ActionType>(action), actionArguments);
761
762 return true;
763 }
764
DoSomethingInterestingWithSetTargetBundleName(const uint8_t * data,size_t size)765 bool DoSomethingInterestingWithSetTargetBundleName(const uint8_t* data, size_t size)
766 {
767 if (data == nullptr || size < DATA_MIN_SIZE) {
768 return false;
769 }
770
771 size_t startPos = 0;
772 std::vector<std::string> targetBundleNames;
773 for (size_t count = 0; count < VEC_SIZE; count++) {
774 char name[LEN + 1];
775 name[LEN] = END_CHAR;
776 for (size_t i = 0; i < LEN; i++) {
777 startPos += GetObject<char>(name[i], &data[startPos], size - startPos);
778 }
779 std::string targetBundleName(name);
780 targetBundleNames.push_back(targetBundleName);
781 }
782 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->SetTargetBundleName(targetBundleNames);
783
784 return true;
785 }
786
DoSomethingInterestingWithSetCacheMode(const uint8_t * data,size_t size)787 bool DoSomethingInterestingWithSetCacheMode(const uint8_t* data, size_t size)
788 {
789 if (data == nullptr || size < DATA_MIN_SIZE) {
790 return false;
791 }
792
793 size_t startPos = 0;
794 int32_t cacheMode = 0;
795 GetObject<int32_t>(cacheMode, &data[startPos], size - startPos);
796 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->SetCacheMode(cacheMode);
797
798 return true;
799 }
800
FuzzWithSearchElementInfoByAccessibilityId(const uint8_t * data,size_t size)801 bool FuzzWithSearchElementInfoByAccessibilityId(const uint8_t* data, size_t size)
802 {
803 if (data == nullptr || size < DATA_MIN_SIZE) {
804 return false;
805 }
806
807 size_t startPos = 0;
808 int32_t windowId = 0;
809 int64_t elementId = 0;
810 uint32_t mode = 0;
811 bool isFilter = false;
812
813 startPos += GetObject<int32_t>(windowId, &data[startPos], size - startPos);
814 startPos += GetObject<int64_t>(elementId, &data[startPos], size - startPos);
815
816 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
817 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
818
819 startPos += GetObject<uint32_t>(mode, &data[startPos], size - startPos);
820 startPos += GetObject<bool>(isFilter, &data[startPos], size - startPos);
821 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->SearchElementInfoByAccessibilityId(
822 windowId, elementId, mode, sourceElementInfo, isFilter);
823
824 return true;
825 }
826
CheckGenerateAccessibilityWindowInfo(OHOS::Accessibility::AccessibilityWindowInfo & sourceWindowInfo)827 static bool CheckGenerateAccessibilityWindowInfo(OHOS::Accessibility::AccessibilityWindowInfo &sourceWindowInfo)
828 {
829 sourceWindowInfo.GetAccessibilityWindowType();
830 sourceWindowInfo.GetWindowLayer();
831 sourceWindowInfo.GetWindowId();
832 sourceWindowInfo.GetRectInScreen();
833 sourceWindowInfo.IsActive();
834 sourceWindowInfo.IsFocused();
835 sourceWindowInfo.IsAccessibilityFocused();
836 sourceWindowInfo.GetDisplayId();
837 sourceWindowInfo.GetWindowType();
838 sourceWindowInfo.GetWindowMode();
839 sourceWindowInfo.IsDecorEnable();
840 sourceWindowInfo.GetInnerWid();
841 sourceWindowInfo.GetUiNodeId();
842 sourceWindowInfo.GetScaleVal();
843 sourceWindowInfo.GetScaleX();
844 sourceWindowInfo.GetScaleY();
845 sourceWindowInfo.GetBundleName();
846 sourceWindowInfo.GetTouchHotAreas();
847 sourceWindowInfo.GetMainWindowId();
848 return true;
849 }
850
CheckGenerateAccessibilityElementInfoP1(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)851 static bool CheckGenerateAccessibilityElementInfoP1(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
852 const uint8_t* data, size_t size, size_t& position)
853 {
854 int32_t index = 0;
855 position += GetObject<int32_t>(index, &data[position], size - position);
856 sourceElementInfo.GetChildId(index);
857 sourceElementInfo.GetAccessibilityText();
858 sourceElementInfo.GetTextType();
859 sourceElementInfo.GetOffset();
860 sourceElementInfo.GetPageId();
861 sourceElementInfo.GetTextMovementStep();
862 sourceElementInfo.GetItemCounts();
863 sourceElementInfo.GetTriggerAction();
864 sourceElementInfo.GetLatestContent();
865 sourceElementInfo.GetChildTreeId();
866 sourceElementInfo.GetChildWindowId();
867 sourceElementInfo.GetBelongTreeId();
868 sourceElementInfo.GetParentWindowId();
869
870 std::vector<std::string> contentList;
871 for (size_t count = 0; count < VEC_SIZE; count++) {
872 char name[LEN + 1];
873 name[LEN] = END_CHAR;
874 for (size_t i = 0; i < LEN; i++) {
875 position += GetObject<char>(name[i], &data[position], size - position);
876 }
877 std::string content(name);
878 contentList.push_back(content);
879 }
880 sourceElementInfo.GetContentList(contentList);
881
882 int64_t int64Data = 0;
883 for (size_t i = 0; i < VEC_SIZE; i++) {
884 position += GetObject<int64_t>(int64Data, &data[position], size - position);
885 sourceElementInfo.RemoveChild(int64Data);
886 }
887
888 return true;
889 }
890
CheckGenerateAccessibilityElementInfoP2(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo)891 static bool CheckGenerateAccessibilityElementInfoP2(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo)
892 {
893 sourceElementInfo.GetChildCount();
894 sourceElementInfo.GetChildIds();
895 sourceElementInfo.GetActionList();
896 sourceElementInfo.GetTextLengthLimit();
897 sourceElementInfo.GetMainWindowId();
898 sourceElementInfo.GetInnerWindowId();
899 sourceElementInfo.GetParentNodeId();
900 sourceElementInfo.GetRectInScreen();
901 sourceElementInfo.IsCheckable();
902 sourceElementInfo.IsChecked();
903 sourceElementInfo.IsFocusable();
904 sourceElementInfo.IsFocused();
905 sourceElementInfo.IsVisible();
906 sourceElementInfo.HasAccessibilityFocus();
907 sourceElementInfo.IsSelected();
908 sourceElementInfo.IsClickable();
909 sourceElementInfo.IsLongClickable();
910 sourceElementInfo.IsEnabled();
911 sourceElementInfo.IsPassword();
912 sourceElementInfo.IsScrollable();
913 sourceElementInfo.GetCurrentIndex();
914 sourceElementInfo.GetBeginIndex();
915 sourceElementInfo.GetEndIndex();
916 sourceElementInfo.GetInputType();
917 sourceElementInfo.GetInspectorKey();
918 sourceElementInfo.GetPagePath();
919 sourceElementInfo.IsValidElement();
920 sourceElementInfo.IsEditable();
921 sourceElementInfo.IsPluraLineSupported();
922 sourceElementInfo.IsPopupSupported();
923 sourceElementInfo.IsDeletable();
924 sourceElementInfo.IsEssential();
925 sourceElementInfo.IsGivingHint();
926 sourceElementInfo.GetBundleName();
927 sourceElementInfo.GetComponentType();
928 sourceElementInfo.GetContent();
929 sourceElementInfo.GetSelectedBegin();
930 sourceElementInfo.GetSelectedEnd();
931 sourceElementInfo.GetHint();
932 sourceElementInfo.GetDescriptionInfo();
933 sourceElementInfo.GetComponentResourceId();
934 sourceElementInfo.GetLiveRegion();
935 sourceElementInfo.GetContentInvalid();
936 sourceElementInfo.GetError();
937 sourceElementInfo.GetLabeledAccessibilityId();
938 sourceElementInfo.GetRange();
939 sourceElementInfo.GetGrid();
940 sourceElementInfo.GetGridItem();
941
942 return true;
943 }
944
CheckGenerateAccessibilityElementInfoP3(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)945 static bool CheckGenerateAccessibilityElementInfoP3(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
946 const uint8_t* data, size_t size, size_t& position)
947 {
948 int32_t int32Data = 0;
949 char name[LEN + 1];
950 name[LEN] = END_CHAR;
951 for (size_t count = 0; count < VEC_SIZE; count++) {
952 position += GetObject<int32_t>(int32Data, &data[position], size - position);
953 for (size_t i = 0; i < LEN; i++) {
954 position += GetObject<char>(name[i], &data[position], size - position);
955 }
956 std::string description(name);
957 OHOS::Accessibility::AccessibleAction action(
958 static_cast<OHOS::Accessibility::ActionType>(int32Data), description);
959 sourceElementInfo.DeleteAction(action);
960 }
961
962 for (size_t count = 0; count < VEC_SIZE; count++) {
963 position += GetObject<int32_t>(int32Data, &data[position], size - position);
964 for (size_t i = 0; i < LEN; i++) {
965 position += GetObject<char>(name[i], &data[position], size - position);
966 }
967 std::string description(name);
968 OHOS::Accessibility::AccessibleAction action(
969 static_cast<OHOS::Accessibility::ActionType>(int32Data), description);
970 sourceElementInfo.AddAction(action);
971 OHOS::Accessibility::ActionType actionType = action.GetActionType();
972 sourceElementInfo.DeleteAction(actionType);
973 }
974
975 sourceElementInfo.DeleteAllActions();
976 return true;
977 }
978
CheckGridItemInfo()979 static bool CheckGridItemInfo()
980 {
981 OHOS::Accessibility::GridItemInfo gridItem;
982 gridItem.GetColumnIndex();
983 gridItem.GetRowIndex();
984 gridItem.GetColumnSpan();
985 gridItem.GetRowSpan();
986 gridItem.IsHeading();
987 gridItem.IsSelected();
988 return true;
989 }
990
FuzzWithGetRootByWindowBatch(const uint8_t * data,size_t size)991 bool FuzzWithGetRootByWindowBatch(const uint8_t* data, size_t size)
992 {
993 if (data == nullptr || size < DATA_MIN_SIZE) {
994 return false;
995 }
996
997 size_t startPos = 0;
998 bool isFilter = false;
999 bool needCut = false;
1000
1001 OHOS::Accessibility::AccessibilityWindowInfo windowInfo;
1002 GenerateAccessibilityWindowInfo(windowInfo, &data[startPos], size - startPos);
1003 std::vector<OHOS::Accessibility::AccessibilityElementInfo> infos;
1004 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
1005 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
1006 infos.push_back(sourceElementInfo);
1007
1008 startPos += GetObject<bool>(isFilter, &data[startPos], size - startPos);
1009 startPos += GetObject<bool>(needCut, &data[startPos], size - startPos);
1010 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetRootByWindowBatch(
1011 windowInfo, infos, isFilter, needCut);
1012
1013 CheckGenerateAccessibilityWindowInfo(windowInfo);
1014 CheckGenerateAccessibilityElementInfoP1(sourceElementInfo, &data[startPos], size - startPos, startPos);
1015 CheckGenerateAccessibilityElementInfoP2(sourceElementInfo);
1016 CheckGenerateAccessibilityElementInfoP3(sourceElementInfo, &data[startPos], size - startPos, startPos);
1017 CheckGridItemInfo();
1018 return true;
1019 }
1020
FuzzWithGetRootBatch(const uint8_t * data,size_t size)1021 bool FuzzWithGetRootBatch(const uint8_t* data, size_t size)
1022 {
1023 if (data == nullptr || size < DATA_MIN_SIZE) {
1024 return false;
1025 }
1026
1027 size_t startPos = 0;
1028 std::vector<OHOS::Accessibility::AccessibilityElementInfo> infos;
1029 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
1030 GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
1031 infos.push_back(sourceElementInfo);
1032 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetRootBatch(infos);
1033
1034 return true;
1035 }
1036
FuzzWithConnect()1037 bool FuzzWithConnect()
1038 {
1039 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->Connect();
1040 OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->Disconnect();
1041
1042 return true;
1043 }
1044
FuzzWithExtraElementInfoFirstPart(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)1045 static void FuzzWithExtraElementInfoFirstPart(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
1046 const uint8_t* data, size_t size, size_t& position)
1047 {
1048 OHOS::Accessibility::ExtraElementInfo extraElementInfo;
1049 char name[LEN + 1];
1050 name[LEN] = END_CHAR;
1051 for (size_t i = 0; i < LEN; i++) {
1052 position += GetObject<char>(name[i], &data[position], size - position);
1053 }
1054 std::string keyStr(name);
1055 std::string valueStr(name);
1056 extraElementInfo.SetExtraElementInfo(keyStr, valueStr);
1057
1058 int32_t int32Data = 0;
1059 position += GetObject<int32_t>(int32Data, &data[position], size - position);
1060 extraElementInfo.SetExtraElementInfo(keyStr, int32Data);
1061
1062 extraElementInfo.GetExtraElementInfoValueStr();
1063 extraElementInfo.GetExtraElementInfoValueInt();
1064
1065 sourceElementInfo.SetExtraElement(extraElementInfo);
1066 sourceElementInfo.GetExtraElement();
1067 sourceElementInfo.GetAccessibilityLevel();
1068
1069 position += GetObject<int32_t>(int32Data, &data[position], size - position);
1070 sourceElementInfo.SetZIndex(int32Data);
1071 sourceElementInfo.GetZIndex();
1072
1073 float floatData = 0.0;
1074 position += GetObject<float>(floatData, &data[position], size - position);
1075 sourceElementInfo.SetOpacity(floatData);
1076 sourceElementInfo.GetOpacity();
1077
1078 for (size_t i = 0; i < LEN; i++) {
1079 position += GetObject<char>(name[i], &data[position], size - position);
1080 }
1081 std::string backgroundColor(name);
1082 sourceElementInfo.SetBackgroundColor(backgroundColor);
1083 sourceElementInfo.GetBackgroundColor();
1084
1085 for (size_t i = 0; i < LEN; i++) {
1086 position += GetObject<char>(name[i], &data[position], size - position);
1087 }
1088 std::string backgroundImage(name);
1089 sourceElementInfo.SetBackgroundImage(backgroundImage);
1090 sourceElementInfo.GetBackgroundImage();
1091 }
1092
FuzzWithExtraElementInfoSecondPart(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)1093 static void FuzzWithExtraElementInfoSecondPart(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
1094 const uint8_t* data, size_t size, size_t& position)
1095 {
1096 char name[LEN + 1];
1097 name[LEN] = END_CHAR;
1098 for (size_t i = 0; i < LEN; i++) {
1099 position += GetObject<char>(name[i], &data[position], size - position);
1100 }
1101 std::string blur(name);
1102 sourceElementInfo.SetBlur(blur);
1103 sourceElementInfo.GetBlur();
1104
1105 for (size_t i = 0; i < LEN; i++) {
1106 position += GetObject<char>(name[i], &data[position], size - position);
1107 }
1108 std::string hitTestBehavior(name);
1109 sourceElementInfo.SetHitTestBehavior(hitTestBehavior);
1110 sourceElementInfo.GetHitTestBehavior();
1111
1112 for (size_t i = 0; i < LEN; i++) {
1113 position += GetObject<char>(name[i], &data[position], size - position);
1114 }
1115 std::string customComponentType(name);
1116 sourceElementInfo.SetCustomComponentType(customComponentType);
1117 sourceElementInfo.GetCustomComponentType();
1118
1119 for (size_t i = 0; i < LEN; i++) {
1120 position += GetObject<char>(name[i], &data[position], size - position);
1121 }
1122 std::string accessibilityNextFocusInspectorKey(name);
1123 sourceElementInfo.SetAccessibilityNextFocusInspectorKey(accessibilityNextFocusInspectorKey);
1124 sourceElementInfo.GetAccessibilityNextFocusInspectorKey();
1125 }
1126
FuzzWithExtraElementInfoThirdPart(OHOS::Accessibility::AccessibilityElementInfo & sourceElementInfo,const uint8_t * data,size_t size,size_t & position)1127 static void FuzzWithExtraElementInfoThirdPart(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
1128 const uint8_t* data, size_t size, size_t& position)
1129 {
1130 int64_t int64Data = 0;
1131 position += GetObject<int64_t>(int64Data, &data[position], size - position);
1132 sourceElementInfo.SetNavDestinationId(int64Data);
1133 sourceElementInfo.GetNavDestinationId();
1134
1135 position += GetObject<int64_t>(int64Data, &data[position], size - position);
1136 sourceElementInfo.SetAccessibilityNextFocusId(int64Data);
1137 sourceElementInfo.GetAccessibilityNextFocusId();
1138
1139 position += GetObject<int64_t>(int64Data, &data[position], size - position);
1140 sourceElementInfo.SetAccessibilityPreviousFocusId(int64Data);
1141 sourceElementInfo.GetAccessibilityPreviousFocusId();
1142
1143 bool boolData = false;
1144 position += GetObject<bool>(boolData, &data[position], size - position);
1145 sourceElementInfo.SetIsActive(boolData);
1146 sourceElementInfo.GetIsActive();
1147
1148 position += GetObject<bool>(boolData, &data[position], size - position);
1149 sourceElementInfo.SetAccessibilityVisible(boolData);
1150 sourceElementInfo.GetAccessibilityVisible();
1151
1152 position += GetObject<bool>(boolData, &data[position], size - position);
1153 sourceElementInfo.SetClip(boolData);
1154 sourceElementInfo.GetClip();
1155
1156 position += GetObject<bool>(boolData, &data[position], size - position);
1157 sourceElementInfo.SetAccessibilityScrollable(boolData);
1158 sourceElementInfo.GetAccessibilityScrollable();
1159 }
1160
FuzzWithExtraElementInfo(const uint8_t * data,size_t size)1161 bool FuzzWithExtraElementInfo(const uint8_t* data, size_t size)
1162 {
1163 if (data == nullptr || size < DATA_MIN_SIZE) {
1164 return false;
1165 }
1166
1167 size_t position = 0;
1168 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
1169 FuzzWithExtraElementInfoFirstPart(sourceElementInfo, data, size, position);
1170 FuzzWithExtraElementInfoSecondPart(sourceElementInfo, data, size, position);
1171 FuzzWithExtraElementInfoThirdPart(sourceElementInfo, data, size, position);
1172
1173 return true;
1174 }
1175
FuzzWithSpanInfo(const uint8_t * data,size_t size)1176 bool FuzzWithSpanInfo(const uint8_t* data, size_t size)
1177 {
1178 if (data == nullptr || size < DATA_MIN_SIZE) {
1179 return false;
1180 }
1181
1182 OHOS::Accessibility::SpanInfo span;
1183 int32_t int32Data = 0;
1184 size_t position = 0;
1185 position += GetObject<int32_t>(int32Data, &data[position], size - position);
1186 span.SetSpanId(int32Data);
1187 span.GetSpanId();
1188
1189 char name[LEN + 1];
1190 name[LEN] = END_CHAR;
1191 for (size_t i = 0; i < LEN; i++) {
1192 position += GetObject<char>(name[i], &data[position], size - position);
1193 }
1194 std::string spanText(name);
1195 span.SetSpanText(spanText);
1196 span.GetSpanText();
1197
1198 OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
1199 std::vector<OHOS::Accessibility::SpanInfo> spanList;
1200 spanList.push_back(span);
1201 sourceElementInfo.SetSpanList(spanList);
1202 sourceElementInfo.GetSpanList();
1203
1204 for (size_t i = 0; i < LEN; i++) {
1205 position += GetObject<char>(name[i], &data[position], size - position);
1206 }
1207 std::string accessibilityText(name);
1208 span.SetAccessibilityText(accessibilityText);
1209 span.GetAccessibilityText();
1210
1211 for (size_t i = 0; i < LEN; i++) {
1212 position += GetObject<char>(name[i], &data[position], size - position);
1213 }
1214 std::string accessibilityDescription(name);
1215 span.SetAccessibilityDescription(accessibilityDescription);
1216 span.GetAccessibilityDescription();
1217
1218 for (size_t i = 0; i < LEN; i++) {
1219 position += GetObject<char>(name[i], &data[position], size - position);
1220 }
1221 std::string accessibilityLevel(name);
1222 span.SetAccessibilityLevel(accessibilityLevel);
1223 span.GetAccessibilityLevel();
1224
1225 sourceElementInfo.AddSpan(span);
1226
1227 return true;
1228 }
1229 } // namespace OHOS
1230
1231 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)1232 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
1233 {
1234 /* Run your code on data */
1235 OHOS::DoSomethingInterestingWithRegisterAbilityListener();
1236 OHOS::DoSomethingInterestingWithGetFocus(data, size);
1237 OHOS::DoSomethingInterestingWithGetFocusByElementInfo(data, size);
1238 OHOS::DoSomethingInterestingWithInjectGesture(data, size);
1239 OHOS::DoSomethingInterestingWithGetRoot(data, size);
1240 OHOS::DoSomethingInterestingWithGetRootByWindow(data, size);
1241 OHOS::DoSomethingInterestingWithGetWindow(data, size);
1242 OHOS::DoSomethingInterestingWithGetWindows(data, size);
1243 OHOS::DoSomethingInterestingWithGetWindowsByDisplayId(data, size);
1244 OHOS::DoSomethingInterestingWithGetNext(data, size);
1245 OHOS::DoSomethingInterestingWithGetChildElementInfo(data, size);
1246 OHOS::DoSomethingInterestingWithGetChildren(data, size);
1247 OHOS::DoSomethingInterestingWithGetByContent(data, size);
1248 OHOS::DoSomethingInterestingWithGetSource(data, size);
1249 OHOS::DoSomethingInterestingWithGetParentElementInfo(data, size);
1250 OHOS::DoSomethingInterestingWithExecuteAction(data, size);
1251 OHOS::DoSomethingInterestingWithSetTargetBundleName(data, size);
1252 OHOS::DoSomethingInterestingWithSetCacheMode(data, size);
1253 OHOS::FuzzWithSearchElementInfoByAccessibilityId(data, size);
1254 OHOS::FuzzWithGetRootByWindowBatch(data, size);
1255 OHOS::FuzzWithGetRootBatch(data, size);
1256 OHOS::FuzzWithConnect();
1257 OHOS::FuzzWithExtraElementInfo(data, size);
1258 OHOS::FuzzWithSpanInfo(data, size);
1259 return 0;
1260 }