• 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 #ifndef ABILITY_FUZZ_UTIL_H
17 #define ABILITY_FUZZ_UTIL_H
18 
19 #include <fuzzer/FuzzedDataProvider.h>
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 #include "ability_record.h"
25 #include "ability_info.h"
26 #include "application_info.h"
27 #include "auto_startup_info.h"
28 #include "bundle_info.h"
29 #include "bundle_user_info.h"
30 #include "dlp_connection_info.h"
31 #include "dlp_state_data.h"
32 #include "ecological_rule/ability_ecological_rule_mgr_service_param.h"
33 #include "extract_insight_intent_profile.h"
34 #include "keep_alive_info.h"
35 #include "keep_alive_process_manager.h"
36 
37 namespace OHOS {
38 namespace AppExecFwk {
39 namespace AbilityFuzzUtil {
40 constexpr size_t CODE_TWO = 2;
41 constexpr size_t CODE_MAX = 99;
42 constexpr size_t STRING_MAX_LENGTH = 128;
43 std::vector<std::string> GenerateStringArray(FuzzedDataProvider& fdp, size_t arraySizeMax = STRING_MAX_LENGTH,
44     size_t stringSize = STRING_MAX_LENGTH)
45 {
46     std::vector<std::string> result;
47     size_t arraySize = fdp.ConsumeIntegralInRange<size_t>(0, arraySizeMax);
48     result.reserve(arraySize);
49 
50     for (size_t i = 0; i < arraySize; ++i) {
51         std::string str = fdp.ConsumeRandomLengthString(stringSize);
52         result.emplace_back(str);
53     }
54 
55     return result;
56 }
57 
GenerateElementName(FuzzedDataProvider & fdp,AppExecFwk::ElementName & elementName)58 AppExecFwk::ElementName GenerateElementName(FuzzedDataProvider& fdp, AppExecFwk::ElementName &elementName)
59 {
60     std::string deviceId;
61     std::string bundleName;
62     std::string abilityName;
63     std::string moduleName;
64     deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
65     bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
66     abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
67     moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
68     AppExecFwk::ElementName name(deviceId, bundleName, abilityName, moduleName);
69 
70     return name;
71 }
72 
GetRandomExtractInsightIntentGenericInfo(FuzzedDataProvider & fdp,ExtractInsightIntentGenericInfo & info)73 void GetRandomExtractInsightIntentGenericInfo(FuzzedDataProvider& fdp, ExtractInsightIntentGenericInfo& info)
74 {
75     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
76     info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
77     info.intentName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
78     info.displayName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
79     info.decoratorType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
80 }
81 
GetRandomInsightIntentInfoForQuery(FuzzedDataProvider & fdp,InsightIntentInfoForQuery & info)82 void GetRandomInsightIntentInfoForQuery(FuzzedDataProvider& fdp, InsightIntentInfoForQuery& info)
83 {
84     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
85     info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
86     info.intentName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
87     info.domain = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
88     info.intentVersion = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
89     info.displayName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
90     info.displayDescription = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
91     info.schema = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
92     info.icon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
93     info.llmDescription = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
94     info.intentType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
95     info.parameters = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
96     info.result = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
97     info.keywords = GenerateStringArray(fdp);
98 }
99 
GetRandomExtractInsightIntentInfo(FuzzedDataProvider & fdp,ExtractInsightIntentInfo & info)100 void GetRandomExtractInsightIntentInfo(FuzzedDataProvider& fdp, ExtractInsightIntentInfo& info)
101 {
102     info.decoratorFile = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
103     info.decoratorClass = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
104     info.displayDescription = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
105     info.domain = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
106     info.intentVersion = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
107     info.schema = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
108     info.icon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
109     info.llmDescription = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
110     info.result = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
111     info.example = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
112     info.keywords = GenerateStringArray(fdp);
113 }
114 
GetRandomInsightIntentExecuteParam(FuzzedDataProvider & fdp,InsightIntentExecuteParam & info)115 void GetRandomInsightIntentExecuteParam(FuzzedDataProvider& fdp, InsightIntentExecuteParam& info)
116 {
117     info.executeMode_ = fdp.ConsumeIntegral<int32_t>();
118     info.displayId_ = fdp.ConsumeIntegral<int32_t>();
119     info.flags_ = fdp.ConsumeIntegral<int32_t>();
120     info.insightIntentId_ = fdp.ConsumeIntegral<uint64_t>();
121     info.bundleName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
122     info.moduleName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
123     info.abilityName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
124     info.insightIntentName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
125     info.uris_ = GenerateStringArray(fdp);
126     info.decoratorType_ = fdp.ConsumeIntegral<int8_t>();
127     info.srcEntrance_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
128     info.className_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
129     info.methodName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
130     info.methodParams_ = GenerateStringArray(fdp);
131     info.pagePath_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
132     info.navigationId_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
133     info.navDestinationName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
134 }
135 
GetRandomExtractInsightIntentProfileInfo(FuzzedDataProvider & fdp,ExtractInsightIntentProfileInfo & info)136 void GetRandomExtractInsightIntentProfileInfo(FuzzedDataProvider& fdp, ExtractInsightIntentProfileInfo& info)
137 {
138     info.decoratorFile = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
139     info.decoratorClass = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
140     info.decoratorType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
141     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
142     info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
143     info.intentName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
144     info.domain = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
145     info.intentVersion = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
146     info.displayName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
147     info.displayDescription = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
148     info.schema = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
149     info.icon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
150     info.llmDescription = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
151     info.keywords = GenerateStringArray(fdp);
152     info.parameters = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
153     info.result = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
154     info.example = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
155     info.uri = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
156     info.uiAbility = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
157     info.pagePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
158     info.navigationId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
159     info.navDestinationName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
160     info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
161     info.executeMode = GenerateStringArray(fdp);
162     info.functionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
163     info.functionParams = GenerateStringArray(fdp);
164     info.formName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
165 }
166 
GetRandomKeepAliveStatus(FuzzedDataProvider & fdp,KeepAliveStatus & status)167 void GetRandomKeepAliveStatus(FuzzedDataProvider& fdp, KeepAliveStatus& status)
168 {
169     status.code = fdp.ConsumeIntegral<int32_t>();
170     status.setterId = fdp.ConsumeIntegral<int32_t>();
171     status.setter = static_cast<KeepAliveSetter>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
172 }
173 
GetRandomDlpConnectionInfo(FuzzedDataProvider & fdp,DlpConnectionInfo & info)174 void GetRandomDlpConnectionInfo(FuzzedDataProvider& fdp, DlpConnectionInfo& info)
175 {
176     info.dlpUid = fdp.ConsumeIntegral<int32_t>();
177     info.openedAbilityCount = fdp.ConsumeIntegral<int32_t>();
178 }
179 
GetRandomConnectionData(FuzzedDataProvider & fdp,ConnectionData & info)180 void GetRandomConnectionData(FuzzedDataProvider& fdp, ConnectionData& info)
181 {
182     info.isSuspended = fdp.ConsumeBool();
183     info.extensionPid = fdp.ConsumeIntegral<uint32_t>();
184     info.extensionUid = fdp.ConsumeIntegral<uint32_t>();
185     info.callerUid = fdp.ConsumeIntegral<uint32_t>();
186     info.callerPid = fdp.ConsumeIntegral<uint32_t>();
187     info.extensionBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
188     info.extensionModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
189     info.extensionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
190     info.callerName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
191 }
192 
GetRandomDlpStateData(FuzzedDataProvider & fdp,DlpStateData & info)193 void GetRandomDlpStateData(FuzzedDataProvider& fdp, DlpStateData& info)
194 {
195     info.targetPid = fdp.ConsumeIntegral<uint32_t>();
196     info.targetUid = fdp.ConsumeIntegral<uint32_t>();
197     info.callerUid = fdp.ConsumeIntegral<uint32_t>();
198     info.callerPid = fdp.ConsumeIntegral<uint32_t>();
199     info.callerName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
200     info.targetBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
201     info.targetModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
202     info.targetAbilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
203 }
204 
GenerateSignatureInfo(FuzzedDataProvider & fdp,SignatureInfo & signatureInfo)205 void GenerateSignatureInfo(FuzzedDataProvider& fdp, SignatureInfo &signatureInfo)
206 {
207     signatureInfo.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
208     signatureInfo.fingerprint = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
209     signatureInfo.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
210     signatureInfo.certificate = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
211 }
212 
GetRandomAbilityInfo(FuzzedDataProvider & fdp,AbilityInfo & info)213 void GetRandomAbilityInfo(FuzzedDataProvider& fdp, AbilityInfo& info)
214 {
215     info.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
216     info.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
217     info.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
218     info.iconPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
219     info.labelId = fdp.ConsumeIntegral<int32_t>();
220     info.descriptionId = fdp.ConsumeIntegral<int32_t>();
221     info.iconId = fdp.ConsumeIntegral<int32_t>();
222     info.theme = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
223     info.visible = fdp.ConsumeBool();
224     info.kind = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
225 }
226 
GetRandomAbilityExperienceRule(FuzzedDataProvider & fdp,AbilityExperienceRule & rule)227 void GetRandomAbilityExperienceRule(FuzzedDataProvider& fdp, AbilityExperienceRule& rule)
228 {
229     rule.resultCode = fdp.ConsumeIntegral<int32_t>();
230     rule.sceneCode = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
231     rule.isBackSkuExempt = fdp.ConsumeBool();
232     rule.embedResultCode = fdp.ConsumeIntegral<int32_t>();
233 }
234 
GetRandomAutoStartupInfo(FuzzedDataProvider & fdp,AutoStartupInfo & info)235 void GetRandomAutoStartupInfo(FuzzedDataProvider& fdp, AutoStartupInfo& info)
236 {
237     info.appCloneIndex = fdp.ConsumeIntegral<int32_t>();
238     info.userId = fdp.ConsumeIntegral<int32_t>();
239     info.retryCount = fdp.ConsumeIntegral<int32_t>();
240     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
241     info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
242     info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
243     info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
244     info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
245 }
246 
GetRandomBundleInfo(FuzzedDataProvider & fdp,BundleInfo & info)247 void GetRandomBundleInfo(FuzzedDataProvider& fdp, BundleInfo& info)
248 {
249     info.isNewVersion = fdp.ConsumeBool();
250     info.isKeepAlive = fdp.ConsumeBool();
251     info.singleton = fdp.ConsumeBool();
252     info.isPreInstallApp = fdp.ConsumeBool();
253     info.isNativeApp = fdp.ConsumeBool();
254     info.entryInstallationFree = fdp.ConsumeBool();
255     info.isDifferentName = fdp.ConsumeBool();
256     info.versionCode = fdp.ConsumeIntegral<uint32_t>();
257     info.minCompatibleVersionCode = fdp.ConsumeIntegral<uint32_t>();
258     info.compatibleVersion = fdp.ConsumeIntegral<uint32_t>();
259     info.targetVersion = fdp.ConsumeIntegral<uint32_t>();
260     info.appIndex = fdp.ConsumeIntegral<int32_t>();
261     info.minSdkVersion = fdp.ConsumeIntegral<int32_t>();
262     info.maxSdkVersion = fdp.ConsumeIntegral<int32_t>();
263     info.overlayType = fdp.ConsumeIntegral<int32_t>();
264     info.installTime = fdp.ConsumeIntegral<int64_t>();
265     info.updateTime = fdp.ConsumeIntegral<int64_t>();
266     info.firstInstallTime = fdp.ConsumeIntegral<int64_t>();
267     info.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
268     info.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
269     info.vendor = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
270     info.releaseType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
271     info.mainEntry = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
272     info.entryModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
273     info.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
274     info.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
275     info.seInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
276     info.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
277     info.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
278     info.jointUserId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
279     GenerateSignatureInfo(fdp, info.signatureInfo);
280     info.oldAppIds = GenerateStringArray(fdp);
281     info.hapModuleNames = GenerateStringArray(fdp);
282     info.moduleNames = GenerateStringArray(fdp);
283     info.modulePublicDirs = GenerateStringArray(fdp);
284     info.moduleDirs = GenerateStringArray(fdp);
285     info.moduleResPaths = GenerateStringArray(fdp);
286     info.reqPermissions = GenerateStringArray(fdp);
287     info.defPermissions = GenerateStringArray(fdp);
288 }
289 
GetRandomKeepAliveInfo(FuzzedDataProvider & fdp,KeepAliveInfo & info)290 void GetRandomKeepAliveInfo(FuzzedDataProvider& fdp, KeepAliveInfo& info)
291 {
292     info.userId = fdp.ConsumeIntegral<int32_t>();
293     info.setterId = fdp.ConsumeIntegral<int32_t>();
294     info.appType = static_cast<KeepAliveAppType>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
295     info.setter = static_cast<KeepAliveSetter>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
296     info.policy = static_cast<KeepAlivePolicy>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
297     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
298 }
299 
GetRandomKeepAliveAbilityInfo(FuzzedDataProvider & fdp,KeepAliveAbilityInfo & info)300 void GetRandomKeepAliveAbilityInfo(FuzzedDataProvider& fdp, KeepAliveAbilityInfo& info)
301 {
302     info.userId = fdp.ConsumeIntegral<int32_t>();
303     info.appCloneIndex = fdp.ConsumeIntegral<int32_t>();
304     info.uid = fdp.ConsumeIntegral<int32_t>();
305     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
306     info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
307     info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
308 }
309 
GetRandomKeepAliveAppInfo(FuzzedDataProvider & fdp,AppInfo & info)310 void GetRandomKeepAliveAppInfo(FuzzedDataProvider& fdp, AppInfo& info)
311 {
312     info.processName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
313     info.state = static_cast<AppState>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
314     info.pid = fdp.ConsumeIntegral<uint32_t>();
315     info.appIndex = fdp.ConsumeIntegral<int32_t>();
316     info.instanceKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
317     info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
318 }
319 
GetRandomAppqfInfo(FuzzedDataProvider & fdp,AppqfInfo & deployedAppqfInfo)320 void GetRandomAppqfInfo(FuzzedDataProvider& fdp, AppqfInfo& deployedAppqfInfo)
321 {
322     deployedAppqfInfo.type = static_cast<QuickFixType>(fdp.ConsumeIntegralInRange<int8_t>(0, CODE_TWO));
323     deployedAppqfInfo.versionCode = fdp.ConsumeIntegral<int32_t>();
324     deployedAppqfInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
325     deployedAppqfInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
326     deployedAppqfInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
327     std::vector<HqfInfo> hqfInfos;
328 }
329 
GetRandomDeployingAppqfInfo(FuzzedDataProvider & fdp,AppqfInfo & deployingAppqfInfo)330 void GetRandomDeployingAppqfInfo(FuzzedDataProvider& fdp, AppqfInfo& deployingAppqfInfo)
331 {
332     deployingAppqfInfo.type = static_cast<QuickFixType>(fdp.ConsumeIntegralInRange<int8_t>(0, CODE_TWO));
333     deployingAppqfInfo.versionCode = fdp.ConsumeIntegral<int32_t>();
334     deployingAppqfInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
335     deployingAppqfInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
336     deployingAppqfInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
337     std::vector<HqfInfo> hqfInfos;
338 }
339 
GetRandomAppQuickFix(FuzzedDataProvider & fdp,AppQuickFix & appQuickFix)340 void GetRandomAppQuickFix(FuzzedDataProvider& fdp, AppQuickFix& appQuickFix)
341 {
342     appQuickFix.versionCode = fdp.ConsumeIntegral<int32_t>();
343     appQuickFix.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
344     appQuickFix.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
345     GetRandomAppqfInfo(fdp, appQuickFix.deployedAppqfInfo);
346     GetRandomDeployingAppqfInfo(fdp, appQuickFix.deployingAppqfInfo);
347 }
348 
GetRandomResourceInfo(FuzzedDataProvider & fdp,Resource & labelResource)349 void GetRandomResourceInfo(FuzzedDataProvider& fdp, Resource& labelResource)
350 {
351     labelResource.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
352     labelResource.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
353     labelResource.id = fdp.ConsumeIntegral<int32_t>();
354 }
355 
GetRandomApplicationInfo(FuzzedDataProvider & fdp,ApplicationInfo & appInfo)356 void GetRandomApplicationInfo(FuzzedDataProvider& fdp, ApplicationInfo& appInfo)
357 {
358     appInfo.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
359     appInfo.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
360     appInfo.versionCode = fdp.ConsumeIntegral<int32_t>();
361     appInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
362     appInfo.minCompatibleVersionCode = fdp.ConsumeIntegral<int32_t>();
363     appInfo.apiCompatibleVersion = fdp.ConsumeIntegral<int32_t>();
364     appInfo.apiTargetVersion = fdp.ConsumeIntegral<int32_t>();
365     appInfo.crowdtestDeadline = fdp.ConsumeIntegral<int64_t>();
366     appInfo.iconPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
367     appInfo.iconId = fdp.ConsumeIntegral<int32_t>();
368     GetRandomResourceInfo(fdp, appInfo.labelResource);
369     appInfo.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
370     appInfo.labelId = fdp.ConsumeIntegral<int32_t>();
371     GetRandomResourceInfo(fdp, appInfo.labelResource);
372     appInfo.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
373     appInfo.descriptionId = fdp.ConsumeIntegral<int32_t>();
374     GetRandomResourceInfo(fdp, appInfo.labelResource);
375     appInfo.keepAlive = fdp.ConsumeBool();
376     appInfo.removable = fdp.ConsumeBool();
377     appInfo.singleton = fdp.ConsumeBool();
378     appInfo.userDataClearable = fdp.ConsumeBool();
379     appInfo.allowAppRunWhenDeviceFirstLocked = fdp.ConsumeBool();
380     appInfo.accessible = fdp.ConsumeBool();
381     appInfo.runningResourcesApply = fdp.ConsumeBool();
382     appInfo.associatedWakeUp = fdp.ConsumeBool();
383     appInfo.hideDesktopIcon = fdp.ConsumeBool();
384     appInfo.formVisibleNotify = fdp.ConsumeBool();
385     appInfo.installedForAllUser = fdp.ConsumeBool();
386     appInfo.allowEnableNotification = fdp.ConsumeBool();
387     appInfo.allowMultiProcess = fdp.ConsumeBool();
388     appInfo.gwpAsanEnabled = fdp.ConsumeBool();
389     appInfo.hasPlugin = fdp.ConsumeBool();
390     appInfo.allowCommonEvent = GenerateStringArray(fdp);
391     appInfo.assetAccessGroups = GenerateStringArray(fdp);
392     appInfo.isSystemApp = fdp.ConsumeBool();
393     appInfo.isLauncherApp = fdp.ConsumeBool();
394     appInfo.isFreeInstallApp = fdp.ConsumeBool();
395     appInfo.asanEnabled = fdp.ConsumeBool();
396     appInfo.asanLogPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
397     appInfo.codePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
398     appInfo.dataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
399     appInfo.dataBaseDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
400     appInfo.cacheDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
401     appInfo.entryDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
402     appInfo.apiReleaseType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
403     appInfo.debug = fdp.ConsumeBool();
404     appInfo.deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
405     appInfo.distributedNotificationEnabled = fdp.ConsumeBool();
406     appInfo.entityType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
407     appInfo.process = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
408     appInfo.supportedModes = fdp.ConsumeIntegral<int32_t>();
409     appInfo.vendor = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
410     appInfo.appPrivilegeLevel = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
411     appInfo.appDistributionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
412     appInfo.appProvisionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
413     appInfo.accessTokenId = fdp.ConsumeIntegral<int32_t>();
414     appInfo.applicationReservedFlag = fdp.ConsumeIntegral<int32_t>();
415     appInfo.accessTokenIdEx = fdp.ConsumeIntegral<int64_t>();
416     appInfo.enabled = fdp.ConsumeBool();
417     appInfo.appIndex = fdp.ConsumeIntegral<int64_t>();
418     appInfo.uid = fdp.ConsumeIntegral<int32_t>();
419     appInfo.maxChildProcess = fdp.ConsumeIntegral<int32_t>();
420     appInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
421     appInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
422     appInfo.arkNativeFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
423     appInfo.arkNativeFileAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
424     appInfo.permissions = GenerateStringArray(fdp);
425     appInfo.moduleSourceDirs = GenerateStringArray(fdp);
426     appInfo.targetBundleList = GenerateStringArray(fdp);
427     appInfo.fingerprint = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
428     GetRandomAppQuickFix(fdp, appInfo.appQuickFix);
429     appInfo.icon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
430     appInfo.flags = fdp.ConsumeIntegral<int32_t>();
431     appInfo.entryModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
432     appInfo.isCompressNativeLibs = fdp.ConsumeBool();
433     appInfo.signatureKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
434     appInfo.multiProjects = fdp.ConsumeBool();
435     appInfo.tsanEnabled = fdp.ConsumeBool();
436     appInfo.hwasanEnabled = fdp.ConsumeBool();
437     appInfo.ubsanEnabled = fdp.ConsumeBool();
438     appInfo.cloudFileSyncEnabled = fdp.ConsumeBool();
439     appInfo.needAppDetail = fdp.ConsumeBool();
440     appInfo.appDetailAbilityLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
441     appInfo.targetBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
442     appInfo.targetPriority = fdp.ConsumeIntegral<int32_t>();
443     appInfo.overlayState = fdp.ConsumeIntegral<int32_t>();
444     appInfo.bundleType = static_cast<BundleType>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
445     appInfo.compileSdkVersion = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
446     appInfo.compileSdkType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
447     appInfo.organization = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
448     appInfo.installSource = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
449     appInfo.configuration = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
450 }
451 
GetRandomAbilityRequestInfo(FuzzedDataProvider & fdp,AbilityRequest & info)452 void GetRandomAbilityRequestInfo(FuzzedDataProvider& fdp, AbilityRequest& info)
453 {
454     info.restart = fdp.ConsumeBool();
455     info.startRecent = fdp.ConsumeBool();
456     info.uriReservedFlag = fdp.ConsumeBool();
457     info.isFromIcon = fdp.ConsumeBool();
458     info.isShellCall = fdp.ConsumeBool();
459     info.isQueryERMS = fdp.ConsumeBool();
460     info.isEmbeddedAllowed = fdp.ConsumeBool();
461     info.callSpecifiedFlagTimeout = fdp.ConsumeBool();
462     info.hideStartWindow = fdp.ConsumeBool();
463     info.restartCount = fdp.ConsumeIntegral<uint32_t>();
464     info.uid = fdp.ConsumeIntegral<uint32_t>();
465     info.collaboratorType = static_cast<CollaboratorType>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
466     info.callerTokenRecordId = fdp.ConsumeIntegral<uint32_t>();
467     info.userId = fdp.ConsumeIntegral<uint32_t>();
468     info.callerAccessTokenId = fdp.ConsumeIntegral<uint32_t>();
469     info.specifyTokenId = fdp.ConsumeIntegral<uint32_t>();
470     info.callerUid = fdp.ConsumeIntegral<uint32_t>();
471     info.requestCode = fdp.ConsumeIntegral<uint32_t>();
472     info.callType = static_cast<AbilityCallType>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
473     info.restartTime = fdp.ConsumeIntegral<uint64_t>();
474     info.extensionType = static_cast<ExtensionAbilityType>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
475     info.extensionProcessMode = static_cast<ExtensionProcessMode>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_TWO));
476     info.specifiedFlag = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
477     info.customProcess = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
478     info.reservedBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
479     info.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
480     info.startTime = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
481     Want want;
482     GetRandomAbilityInfo(fdp, info.abilityInfo);
483     GetRandomApplicationInfo(fdp, info.appInfo);
484 }
485 
GetRandomStartOptions(FuzzedDataProvider & fdp,StartOptions & startOptions)486 void GetRandomStartOptions(FuzzedDataProvider& fdp, StartOptions& startOptions)
487 {
488     startOptions.windowLeftUsed_ = fdp.ConsumeBool();
489     startOptions.windowTopUsed_ = fdp.ConsumeBool();
490     startOptions.windowWidthUsed_ = fdp.ConsumeBool();
491     startOptions.windowHeightUsed_ = fdp.ConsumeBool();
492     startOptions.minWindowWidthUsed_ = fdp.ConsumeBool();
493     startOptions.minWindowHeightUsed_ = fdp.ConsumeBool();
494     startOptions.maxWindowWidthUsed_ = fdp.ConsumeBool();
495     startOptions.maxWindowHeightUsed_ = fdp.ConsumeBool();
496     startOptions.requestId_ = fdp.ConsumeRandomLengthString();
497     startOptions.SetWithAnimation(fdp.ConsumeBool());
498     startOptions.SetWindowFocused(fdp.ConsumeBool());
499     startOptions.SetHideStartWindow(fdp.ConsumeBool());
500     startOptions.SetWindowMode(fdp.ConsumeIntegral<int32_t>());
501     startOptions.SetDisplayID(fdp.ConsumeIntegral<int32_t>());
502     startOptions.SetWindowLeft(fdp.ConsumeIntegral<int32_t>());
503     startOptions.SetWindowTop(fdp.ConsumeIntegral<int32_t>());
504     startOptions.SetWindowWidth(fdp.ConsumeIntegral<int32_t>());
505     startOptions.SetWindowHeight(fdp.ConsumeIntegral<int32_t>());
506     startOptions.SetMinWindowWidth(fdp.ConsumeIntegral<int32_t>());
507     startOptions.SetMinWindowHeight(fdp.ConsumeIntegral<int32_t>());
508     startOptions.SetMaxWindowWidth(fdp.ConsumeIntegral<int32_t>());
509     startOptions.SetMaxWindowHeight(fdp.ConsumeIntegral<int32_t>());
510 }
511 }  // namespace AbilityFuzzUtil
512 }  // namespace AppExecFwk
513 }  // namespace OHOS
514 #endif  // BMS_FUZZTEST_UTIL_H