/// <summary> /// Creates a boolean expression expressing the conditions under which the given packet /// variables match this specific packet. /// </summary> /// <param name="ctx">The Z3 context.</param> /// <param name="packet">The packet variables over which to form an expression.</param> /// <returns>A boolean expression.</returns> public BoolExpr Matches(Context ctx, WindowsFirewallPacketVariables packet) { var conjuncts = new List <BoolExpr>(); if (this.SourceAddress != null) { conjuncts.Add(ctx.MkEq(packet.SourceAddress, AddressRange.AddressToBitVecExpr(ctx, this.SourceAddress))); } if (this.SourcePort != null) { conjuncts.Add(ctx.MkEq(packet.SourcePort, PortRange.PortToBitVecExpr(ctx, (int)this.SourcePort))); } if (this.DestinationPort != null) { conjuncts.Add(ctx.MkEq(packet.DestinationPort, PortRange.PortToBitVecExpr(ctx, (int)this.DestinationPort))); } if (this.Protocol != null) { conjuncts.Add(ctx.MkEq(packet.Protocol, NetworkProtocol.ProtocolToBitVecExpr(ctx, (int)this.Protocol))); } return(ctx.MkAnd(conjuncts.ToArray())); }
/// <summary> /// Builds a boolean expression over the port variable which is true only if /// the protocol variable value, once bound, matches this protocol. /// </summary> /// <param name="ctx">The Z3 context.</param> /// <param name="protocol">The protocol variable to check for match.</param> /// <returns>A Z3 boolean expression.</returns> public BoolExpr Matches(Context ctx, BitVecExpr protocol) { if (this.Any) { return(ctx.MkTrue()); } return(ctx.MkEq(protocol, NetworkProtocol.ProtocolToBitVecExpr(ctx, this.ProtocolNumber))); }