Skip to content

Commit 6abd952

Browse files
Yi2255Samuel Groß
authored andcommitted
feature/void
1 parent fe1d0e5 commit 6abd952

13 files changed

+93
-0
lines changed

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,11 @@ public class ProgramBuilder {
20392039
return emit(TypeOf(), withInputs: [v]).output
20402040
}
20412041

2042+
@discardableResult
2043+
public func void(_ v: Variable) -> Variable {
2044+
return emit(Void_(), withInputs: [v]).output
2045+
}
2046+
20422047
@discardableResult
20432048
public func testInstanceOf(_ v: Variable, _ type: Variable) -> Variable {
20442049
return emit(TestInstanceOf(), withInputs: [v, type]).output

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@ public let codeGeneratorWeights = [
193193
"ApiConstructorCallGenerator": 15,
194194
"ApiMethodCallGenerator": 15,
195195
"ApiFunctionCallGenerator": 15,
196+
"VoidGenerator": 1,
196197
]

Sources/Fuzzilli/CodeGen/CodeGenerators.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ public let CodeGenerators: [CodeGenerator] = [
974974
b.compare(type, with: rhs, using: .strictEqual)
975975
},
976976

977+
CodeGenerator("VoidGenerator", inputs: .one) { b, val in
978+
b.void(val)
979+
},
980+
977981
CodeGenerator("InstanceOfGenerator", inputs: .preferred(.anything, .constructor())) { b, val, cls in
978982
b.testInstanceOf(val, cls)
979983
},

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ extension Instruction: ProtobufConvertible {
565565
}
566566
case .typeOf:
567567
$0.typeOf = Fuzzilli_Protobuf_TypeOf()
568+
case .void:
569+
$0.void = Fuzzilli_Protobuf_Void()
568570
case .testInstanceOf:
569571
$0.testInstanceOf = Fuzzilli_Protobuf_TestInstanceOf()
570572
case .testIn:
@@ -1042,6 +1044,8 @@ extension Instruction: ProtobufConvertible {
10421044
op = ConfigureComputedProperty(flags: flags, type: try convertEnum(p.type, PropertyType.allCases))
10431045
case .typeOf:
10441046
op = TypeOf()
1047+
case .void:
1048+
op = Void_()
10451049
case .testInstanceOf:
10461050
op = TestInstanceOf()
10471051
case .testIn:

Sources/Fuzzilli/FuzzIL/JSTyper.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ public struct JSTyper: Analyzer {
676676
case .typeOf:
677677
set(instr.output, .string)
678678

679+
case .void:
680+
set(instr.output, .undefined)
681+
679682
case .testInstanceOf:
680683
set(instr.output, .boolean)
681684

Sources/Fuzzilli/FuzzIL/JsOperations.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,14 @@ final class TypeOf: JsOperation {
10301030
}
10311031
}
10321032

1033+
final class Void_: JsOperation {
1034+
override var opcode: Opcode { .void(self) }
1035+
1036+
init() {
1037+
super.init(numInputs: 1, numOutputs: 1)
1038+
}
1039+
}
1040+
10331041
final class TestInstanceOf: JsOperation {
10341042
override var opcode: Opcode { .testInstanceOf(self) }
10351043

Sources/Fuzzilli/FuzzIL/Opcodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ enum Opcode {
106106
case deleteComputedProperty(DeleteComputedProperty)
107107
case configureComputedProperty(ConfigureComputedProperty)
108108
case typeOf(TypeOf)
109+
case void(Void_)
109110
case testInstanceOf(TestInstanceOf)
110111
case testIn(TestIn)
111112
case beginPlainFunction(BeginPlainFunction)

Sources/Fuzzilli/Lifting/FuzzILLifter.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ public class FuzzILLifter: Lifter {
366366
case .typeOf:
367367
w.emit("\(output()) <- TypeOf \(input(0))")
368368

369+
case .void:
370+
w.emit("\(output()) <- Void_ \(input(0))")
371+
369372
case .testInstanceOf:
370373
w.emit("\(output()) <- TestInstanceOf \(input(0)), \(input(1))")
371374

Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ public class JavaScriptLifter: Lifter {
642642
let expr = UnaryExpression.new() + "typeof " + input(0)
643643
w.assign(expr, to: instr.output)
644644

645+
case .void:
646+
let expr = UnaryExpression.new() + "void " + input(0)
647+
w.assign(expr, to: instr.output)
648+
645649
case .testInstanceOf:
646650
let lhs = input(0)
647651
let rhs = input(1)

Sources/Fuzzilli/Protobuf/operations.pb.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,16 @@ public struct Fuzzilli_Protobuf_TypeOf: Sendable {
12781278
public init() {}
12791279
}
12801280

1281+
public struct Fuzzilli_Protobuf_Void: Sendable {
1282+
// SwiftProtobuf.Message conformance is added in an extension below. See the
1283+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
1284+
// methods supported on all messages.
1285+
1286+
public var unknownFields = SwiftProtobuf.UnknownStorage()
1287+
1288+
public init() {}
1289+
}
1290+
12811291
public struct Fuzzilli_Protobuf_TestInstanceOf: Sendable {
12821292
// SwiftProtobuf.Message conformance is added in an extension below. See the
12831293
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
@@ -4885,6 +4895,25 @@ extension Fuzzilli_Protobuf_TypeOf: SwiftProtobuf.Message, SwiftProtobuf._Messag
48854895
}
48864896
}
48874897

4898+
extension Fuzzilli_Protobuf_Void: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
4899+
public static let protoMessageName: String = _protobuf_package + ".Void"
4900+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
4901+
4902+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
4903+
while let _ = try decoder.nextFieldNumber() {
4904+
}
4905+
}
4906+
4907+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
4908+
try unknownFields.traverse(visitor: &visitor)
4909+
}
4910+
4911+
public static func ==(lhs: Fuzzilli_Protobuf_Void, rhs: Fuzzilli_Protobuf_Void) -> Bool {
4912+
if lhs.unknownFields != rhs.unknownFields {return false}
4913+
return true
4914+
}
4915+
}
4916+
48884917
extension Fuzzilli_Protobuf_TestInstanceOf: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
48894918
public static let protoMessageName: String = _protobuf_package + ".TestInstanceOf"
48904919
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()

0 commit comments

Comments
 (0)