Skip to content

Commit

Permalink
feature/void
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi2255 committed Dec 3, 2024
1 parent 0e20cd5 commit eb9d48f
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Sources/Fuzzilli/Base/ProgramBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,11 @@ public class ProgramBuilder {
return emit(TypeOf(), withInputs: [v]).output
}

@discardableResult
public func void(_ v: Variable) -> Variable {
return emit(Void_(), withInputs: [v]).output
}

@discardableResult
public func testInstanceOf(_ v: Variable, _ type: Variable) -> Variable {
return emit(TestInstanceOf(), withInputs: [v, type]).output
Expand Down
1 change: 1 addition & 0 deletions Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,5 @@ public let codeGeneratorWeights = [
"ApiConstructorCallGenerator": 15,
"ApiMethodCallGenerator": 15,
"ApiFunctionCallGenerator": 15,
"VoidGenerator": 1,
]
4 changes: 4 additions & 0 deletions Sources/Fuzzilli/CodeGen/CodeGenerators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,10 @@ public let CodeGenerators: [CodeGenerator] = [
b.compare(type, with: rhs, using: .strictEqual)
},

CodeGenerator("VoidGenerator", inputs: .one) { b, val in
b.void(val)
},

CodeGenerator("InstanceOfGenerator", inputs: .preferred(.anything, .constructor())) { b, val, cls in
b.testInstanceOf(val, cls)
},
Expand Down
4 changes: 4 additions & 0 deletions Sources/Fuzzilli/FuzzIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ extension Instruction: ProtobufConvertible {
}
case .typeOf:
$0.typeOf = Fuzzilli_Protobuf_TypeOf()
case .void:
$0.void = Fuzzilli_Protobuf_Void()
case .testInstanceOf:
$0.testInstanceOf = Fuzzilli_Protobuf_TestInstanceOf()
case .testIn:
Expand Down Expand Up @@ -1042,6 +1044,8 @@ extension Instruction: ProtobufConvertible {
op = ConfigureComputedProperty(flags: flags, type: try convertEnum(p.type, PropertyType.allCases))
case .typeOf:
op = TypeOf()
case .void:
op = Void_()
case .testInstanceOf:
op = TestInstanceOf()
case .testIn:
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/FuzzIL/JSTyper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ public struct JSTyper: Analyzer {
case .typeOf:
set(instr.output, .string)

case .void:
set(instr.output, .undefined)

case .testInstanceOf:
set(instr.output, .boolean)

Expand Down
8 changes: 8 additions & 0 deletions Sources/Fuzzilli/FuzzIL/JsOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,14 @@ final class TypeOf: JsOperation {
}
}

final class Void_: JsOperation {
override var opcode: Opcode { .void(self) }

init() {
super.init(numInputs: 1, numOutputs: 1)
}
}

final class TestInstanceOf: JsOperation {
override var opcode: Opcode { .testInstanceOf(self) }

Expand Down
1 change: 1 addition & 0 deletions Sources/Fuzzilli/FuzzIL/Opcodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum Opcode {
case deleteComputedProperty(DeleteComputedProperty)
case configureComputedProperty(ConfigureComputedProperty)
case typeOf(TypeOf)
case void(Void_)
case testInstanceOf(TestInstanceOf)
case testIn(TestIn)
case beginPlainFunction(BeginPlainFunction)
Expand Down
1 change: 0 additions & 1 deletion Sources/Fuzzilli/Fuzzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ public class Fuzzer {
assert(runner.isInitialized)

let script = lifter.lift(program)

dispatchEvent(events.PreExecute, data: (program, purpose))
let execution = runner.run(script, withTimeout: timeout ?? config.timeout)
dispatchEvent(events.PostExecute, data: execution)
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/Lifting/FuzzILLifter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ public class FuzzILLifter: Lifter {
case .typeOf:
w.emit("\(output()) <- TypeOf \(input(0))")

case .void:
w.emit("\(output()) <- Void_ \(input(0))")

case .testInstanceOf:
w.emit("\(output()) <- TestInstanceOf \(input(0)), \(input(1))")

Expand Down
4 changes: 4 additions & 0 deletions Sources/Fuzzilli/Lifting/JavaScriptLifter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ public class JavaScriptLifter: Lifter {
let expr = UnaryExpression.new() + "typeof " + input(0)
w.assign(expr, to: instr.output)

case .void:
let expr = UnaryExpression.new() + "void " + input(0)
w.assign(expr, to: instr.output)

case .testInstanceOf:
let lhs = input(0)
let rhs = input(1)
Expand Down
29 changes: 29 additions & 0 deletions Sources/Fuzzilli/Protobuf/operations.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,16 @@ public struct Fuzzilli_Protobuf_TypeOf: Sendable {
public init() {}
}

public struct Fuzzilli_Protobuf_Void: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

public var unknownFields = SwiftProtobuf.UnknownStorage()

public init() {}
}

public struct Fuzzilli_Protobuf_TestInstanceOf: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
Expand Down Expand Up @@ -4885,6 +4895,25 @@ extension Fuzzilli_Protobuf_TypeOf: SwiftProtobuf.Message, SwiftProtobuf._Messag
}
}

extension Fuzzilli_Protobuf_Void: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
public static let protoMessageName: String = _protobuf_package + ".Void"
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()

public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let _ = try decoder.nextFieldNumber() {
}
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
try unknownFields.traverse(visitor: &visitor)
}

public static func ==(lhs: Fuzzilli_Protobuf_Void, rhs: Fuzzilli_Protobuf_Void) -> Bool {
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}

extension Fuzzilli_Protobuf_TestInstanceOf: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
public static let protoMessageName: String = _protobuf_package + ".TestInstanceOf"
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
Expand Down
3 changes: 3 additions & 0 deletions Sources/Fuzzilli/Protobuf/operations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ message ConfigureComputedProperty {
message TypeOf {
}

message Void {
}

message TestInstanceOf {
}

Expand Down
27 changes: 27 additions & 0 deletions Sources/Fuzzilli/Protobuf/program.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,14 @@ public struct Fuzzilli_Protobuf_Instruction: Sendable {
set {operation = .typeOf(newValue)}
}

public var void: Fuzzilli_Protobuf_Void {
get {
if case .void(let v)? = operation {return v}
return Fuzzilli_Protobuf_Void()
}
set {operation = .void(newValue)}
}

public var testInstanceOf: Fuzzilli_Protobuf_TestInstanceOf {
get {
if case .testInstanceOf(let v)? = operation {return v}
Expand Down Expand Up @@ -1554,6 +1562,7 @@ public struct Fuzzilli_Protobuf_Instruction: Sendable {
case deleteComputedProperty(Fuzzilli_Protobuf_DeleteComputedProperty)
case configureComputedProperty(Fuzzilli_Protobuf_ConfigureComputedProperty)
case typeOf(Fuzzilli_Protobuf_TypeOf)
case void(Fuzzilli_Protobuf_Void)
case testInstanceOf(Fuzzilli_Protobuf_TestInstanceOf)
case testIn(Fuzzilli_Protobuf_TestIn)
case beginPlainFunction(Fuzzilli_Protobuf_BeginPlainFunction)
Expand Down Expand Up @@ -1881,6 +1890,7 @@ extension Fuzzilli_Protobuf_Instruction: SwiftProtobuf.Message, SwiftProtobuf._M
177: .same(proto: "explore"),
178: .same(proto: "probe"),
179: .same(proto: "fixup"),
180: .same(proto: "void"),
]

public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
Expand Down Expand Up @@ -4199,6 +4209,19 @@ extension Fuzzilli_Protobuf_Instruction: SwiftProtobuf.Message, SwiftProtobuf._M
self.operation = .fixup(v)
}
}()
case 180: try {
var v: Fuzzilli_Protobuf_Void?
var hadOneofValue = false
if let current = self.operation {
hadOneofValue = true
if case .void(let m) = current {v = m}
}
try decoder.decodeSingularMessageField(value: &v)
if let v = v {
if hadOneofValue {try decoder.handleConflictingOneOf()}
self.operation = .void(v)
}
}()
default: break
}
}
Expand Down Expand Up @@ -4529,6 +4552,10 @@ extension Fuzzilli_Protobuf_Instruction: SwiftProtobuf.Message, SwiftProtobuf._M
guard case .typeOf(let v)? = self.operation else { preconditionFailure() }
try visitor.visitSingularMessageField(value: v, fieldNumber: 80)
}()
case .void?: try {
guard case .void(let v)? = self.operation else { preconditionFailure() }
try visitor.visitSingularMessageField(value: v, fieldNumber: 80)
}()
case .testInstanceOf?: try {
guard case .testInstanceOf(let v)? = self.operation else { preconditionFailure() }
try visitor.visitSingularMessageField(value: v, fieldNumber: 81)
Expand Down
1 change: 1 addition & 0 deletions Sources/Fuzzilli/Protobuf/program.proto
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ message Instruction {
Explore explore = 177;
Probe probe = 178;
Fixup fixup = 179;
Void void = 180;
}
}

Expand Down

0 comments on commit eb9d48f

Please sign in to comment.