From c15d48ec00e49d92ec18c208f4e081fc70c4763b Mon Sep 17 00:00:00 2001 From: Vadim Afanasyev Date: Wed, 5 Jun 2024 20:58:31 +0800 Subject: [PATCH 1/2] Added HashSet API support --- Sources/FuzzilliCli/Profiles/ArkProfile.swift | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index 71b94d9..49ff151 100644 --- a/Sources/FuzzilliCli/Profiles/ArkProfile.swift +++ b/Sources/FuzzilliCli/Profiles/ArkProfile.swift @@ -27,7 +27,7 @@ fileprivate let RunNearStackLimitGenerator = CodeGenerator("RunNearStackLimitGen /// ArkTS Generators fileprivate let ArkTSObjectInstanceGenerator = ValueGenerator("ArkTSObjectInstanceGenerator") { b, n in - let builtin = chooseUniform(from: ["Stack", "HashMap"]) + let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet"]) let constructor = b.loadBuiltin(builtin) b.construct(constructor) } @@ -36,11 +36,15 @@ fileprivate let ArkTSObjectInstanceGenerator = ValueGenerator("ArkTSObjectInstan fileprivate let arkTSStack = ILType.iterable + ILType.object(ofGroup: "Stack", withProperties: ["length"], withMethods: ["push", "pop", "peek", "locate", "forEach", "isEmpty"]) /// Type of a ArkTS HashMap object. fileprivate let arkTSHashMap = ILType.iterable + ILType.object(ofGroup: "HashMap", withProperties: ["length"], withMethods: ["isEmpty", "hasKey", "hasValue", "get", "setAll", "set", "remove", "clear", "keys", "values", "replace", "forEach", "entries"]) +/// Type of a ArkTS HashSet object. +fileprivate let arkTSHashSet = ILType.iterable + ILType.object(ofGroup: "HashSet", withProperties: ["length"], withMethods: ["isEmpty", "has", "add", "remove", "clear", "values", "forEach", "entries"]) /// Type of the ArkTS Stack constructor builtin. fileprivate let arkTSStackConstructor = ILType.constructor([] => arkTSStack) /// Type of the ArkTS HashMap constructor builtin. fileprivate let arkTSHashMapConstructor = ILType.constructor([] => arkTSHashMap) +/// Type of the ArkTS HashMap constructor builtin. +fileprivate let arkTSHashSetConstructor = ILType.constructor([] => arkTSHashSet) /// ObjectGroup modelling ArkTS Stack objects fileprivate let arkTSStacks = ObjectGroup( @@ -83,6 +87,25 @@ fileprivate let arkTSHashMaps = ObjectGroup( ] ) +/// ObjectGroup modelling ArkTS HashSet objects +fileprivate let arkTSHashSets = ObjectGroup( + name: "HashSet", + instanceType: arkTSHashSet, + properties: [ + "length" : .number, + ], + methods: [ + "isEmpty" : [] => .boolean, + "has" : [.anything] => .boolean, + "add" : [.anything] => .boolean, + "remove" : [.anything] => .boolean, + "clear" : [] => .undefined, + "values" : [] => .object(), // returns an array iterator + "forEach" : [.function([.opt(.anything), .opt(.anything), .opt(arkTSHashSet)] => .undefined), .opt(.object())] => .undefined, + "entries" : [] => .object(), + ] +) + let arkProfile = Profile( processArgs: { randomize in var args = [ @@ -102,6 +125,7 @@ let arkProfile = Profile( let arkPrivate = globalThis.ArkPrivate; arkPrivate.Load(arkPrivate.Stack); arkPrivate.Load(arkPrivate.HashMap); + //artPrivate.Load(arkPrivate.HashSet); //Does not work this way function bgc() { for(let i=0; i<0x10000; i+=1) {new String();} @@ -146,11 +170,13 @@ let arkProfile = Profile( "bgc" : .function([] => .undefined), "Stack" : arkTSStackConstructor, "HashMap" : arkTSHashMapConstructor, + "HashSet" : arkTSHashSetConstructor, ], additionalObjectGroups: [ arkTSStacks, arkTSHashMaps, + arkTSHashSets, ], optionalPostProcessor: nil -- Gitee From 440f2349a1747518867cf79b21680f32dc30977d Mon Sep 17 00:00:00 2001 From: Vadim Afanasyev Date: Thu, 6 Jun 2024 21:25:35 +0800 Subject: [PATCH 2/2] Fixed HashSet support error --- Sources/FuzzilliCli/Profiles/ArkProfile.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index 49ff151..3bcccb3 100644 --- a/Sources/FuzzilliCli/Profiles/ArkProfile.swift +++ b/Sources/FuzzilliCli/Profiles/ArkProfile.swift @@ -123,9 +123,9 @@ let arkProfile = Profile( codePrefix: """ let arkPrivate = globalThis.ArkPrivate; - arkPrivate.Load(arkPrivate.Stack); - arkPrivate.Load(arkPrivate.HashMap); - //artPrivate.Load(arkPrivate.HashSet); //Does not work this way + var Stack = arkPrivate.Load(arkPrivate.Stack); + var HashMap = arkPrivate.Load(arkPrivate.HashMap); + var HashSet = arkPrivate.Load(arkPrivate.HashSet); function bgc() { for(let i=0; i<0x10000; i+=1) {new String();} -- Gitee