public MachineState DoOperation(OperatorEffect operatorEffect, AbstractValue offset) { if (offset.IsPointer) { throw new ArgumentException("_offset pointer not supported."); } var newState = new MachineState(this); switch (operatorEffect) { case OperatorEffect.Jnz: { if (!newState.zeroFlag) { newState.instructionPointer += offset.Value; } break; } default: { throw new ArgumentException( String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect"); } } return(newState); }
public AbstractBuffer DoOperation(OperatorEffect operatorEffect, AbstractValue rhs) { if (null == rhs) { throw new ArgumentNullException("rhs"); } var lhs = this; // TODO: should have a guard for if rhs isn't a pointer switch (operatorEffect) { case OperatorEffect.Assignment: { var result = new AbstractBuffer(lhs); return(result); } case OperatorEffect.Add: { var result = new AbstractBuffer(lhs); result.BaseIndex += rhs.Value; return(result); } case OperatorEffect.Sub: { var result = new AbstractBuffer(lhs); if (result.BaseIndex < rhs.Value) { throw new ArgumentOutOfRangeException( String.Format( "Attempting to set a negative baseindex, baseindex: {0:x4}, _subValue {1:x4}", result.BaseIndex, rhs.Value ) ); } result.BaseIndex -= rhs.Value; return(result); } case OperatorEffect.And: { var result = new AbstractBuffer(lhs); result.BaseIndex &= rhs.Value; return(result); } default: throw new ArgumentException( String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect"); } }
public MachineState DoOperation(RegisterName lhs, OperatorEffect operatorEffect, RegisterName rhs) { var newState = new MachineState(this); var result = DoOperation(Registers[lhs], operatorEffect, Registers[rhs]); newState.Registers[lhs] = result.Value; newState.ZeroFlag = result.ZeroFlag; return(newState); }
private static OperationResult DoOperation(AbstractValue lhs, OperatorEffect operatorEffect, AbstractValue rhs) { if (rhs.IsPointer && operatorEffect != OperatorEffect.Assignment) { throw new ArgumentException("rhs pointer only supported for OperatorEffect.Assignment."); } var result = new OperationResult(); AbstractValue totalValue; if (operatorEffect == OperatorEffect.Assignment) { var newValue = new AbstractValue(rhs); if (rhs.IsInitialized && rhs.IsOutOfBounds) { newValue.IsOutOfBounds = true; } result.Value = newValue; return(result); } if (operatorEffect == OperatorEffect.Cmp) { result.ZeroFlag = (lhs.Value - rhs.Value) == 0; totalValue = lhs; result.Value = totalValue; return(result); } if (lhs.IsPointer) { var newBuffer = lhs.PointsTo.DoOperation(operatorEffect, rhs); result.Value = new AbstractValue(newBuffer); return(result); } var total = CalculateValueFor(lhs.Value, operatorEffect, rhs.Value); totalValue = new AbstractValue(total); if (lhs.IsTainted || rhs.IsTainted) { totalValue = totalValue.AddTaint(); } result.Value = totalValue; return(result); }
public MachineState DoOperation(UInt32 offset, OperatorEffect operatorEffect, AbstractValue rhs) { var newState = new MachineState(this); switch (operatorEffect) { case OperatorEffect.Assignment: { newState.dataSegment[offset] = DoOperation(newState.dataSegment[offset], operatorEffect, rhs).Value; break; } } return(newState); }
public MachineState DoOperation(RegisterName lhs, Int32 index, OperatorEffect operatorEffect, AbstractValue rhs) { var newState = new MachineState(this); switch (operatorEffect) { case OperatorEffect.Assignment: case OperatorEffect.Cmp: { var result = DoOperation(Registers[lhs].PointsTo[index], operatorEffect, rhs); newState.Registers[lhs].PointsTo[index] = result.Value; newState.ZeroFlag = result.ZeroFlag; break; } } return(newState); }
public MachineState DoOperation(RegisterName lhs, OperatorEffect operatorEffect, AbstractValue rhs) { var newState = new MachineState(this); if (Registers[lhs].IsPointer && operatorEffect != OperatorEffect.Assignment) { var newBuffer = Registers[lhs].PointsTo.DoOperation(operatorEffect, rhs); newState.Registers[lhs] = new AbstractValue(newBuffer); } else { var result = DoOperation(Registers[lhs], operatorEffect, rhs); newState.Registers[lhs] = result.Value; newState.ZeroFlag = result.ZeroFlag; } return(newState); }
private static UInt32 CalculateValueFor(UInt32 lhs, OperatorEffect operatorEffect, UInt32 rhs) { switch (operatorEffect) { case OperatorEffect.Add: { return(lhs + rhs); } case OperatorEffect.Sub: { return(lhs - rhs); } case OperatorEffect.And: { return(lhs & rhs); } case OperatorEffect.Xor: { return(lhs ^ rhs); } case OperatorEffect.Shr: { return(lhs >> (Byte)rhs); } case OperatorEffect.Shl: { return(lhs << (Byte)rhs); } default: { throw new ArgumentException( String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect"); } } }
public AbstractBuffer DoOperation(OperatorEffect operatorEffect, AbstractValue rhs) { if (null == rhs) { throw new ArgumentNullException("rhs"); } var lhs = this; // TODO: should have a guard for if rhs isn't a pointer switch (operatorEffect) { case OperatorEffect.Assignment: { var result = new AbstractBuffer(lhs); return result; } case OperatorEffect.Add: { var result = new AbstractBuffer(lhs); result.BaseIndex += rhs.Value; return result; } case OperatorEffect.Sub: { var result = new AbstractBuffer(lhs); if (result.BaseIndex < rhs.Value) { throw new ArgumentOutOfRangeException( String.Format( "Attempting to set a negative baseindex, baseindex: {0:x4}, _subValue {1:x4}", result.BaseIndex, rhs.Value ) ); } result.BaseIndex -= rhs.Value; return result; } case OperatorEffect.And: { var result = new AbstractBuffer(lhs); result.BaseIndex &= rhs.Value; return result; } default: throw new ArgumentException( String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect"); } }
private static UInt32 CalculateValueFor(UInt32 lhs, OperatorEffect operatorEffect, UInt32 rhs) { switch (operatorEffect) { case OperatorEffect.Add: { return lhs + rhs; } case OperatorEffect.Sub: { return lhs - rhs; } case OperatorEffect.And: { return lhs & rhs; } case OperatorEffect.Xor: { return lhs ^ rhs; } case OperatorEffect.Shr: { return lhs >> (Byte)rhs; } case OperatorEffect.Shl: { return lhs << (Byte)rhs; } default: { throw new ArgumentException( String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect"); } } }
private static OperationResult DoOperation(AbstractValue lhs, OperatorEffect operatorEffect, AbstractValue rhs) { if (rhs.IsPointer && operatorEffect != OperatorEffect.Assignment) { throw new ArgumentException("rhs pointer only supported for OperatorEffect.Assignment."); } var result = new OperationResult(); AbstractValue totalValue; if (operatorEffect == OperatorEffect.Assignment) { var newValue = new AbstractValue(rhs); if (rhs.IsInitialized && rhs.IsOutOfBounds) { newValue.IsOutOfBounds = true; } result.Value = newValue; return result; } if (operatorEffect == OperatorEffect.Cmp) { result.ZeroFlag = (lhs.Value - rhs.Value) == 0; totalValue = lhs; result.Value = totalValue; return result; } if (lhs.IsPointer) { var newBuffer = lhs.PointsTo.DoOperation(operatorEffect, rhs); result.Value = new AbstractValue(newBuffer); return result; } var total = CalculateValueFor(lhs.Value, operatorEffect, rhs.Value); totalValue = new AbstractValue(total); if (lhs.IsTainted || rhs.IsTainted) { totalValue = totalValue.AddTaint(); } result.Value = totalValue; return result; }
public MachineState DoOperation(RegisterName lhs, OperatorEffect operatorEffect, RegisterName rhs) { var newState = new MachineState(this); var result = DoOperation(Registers[lhs], operatorEffect, Registers[rhs]); newState.Registers[lhs] = result.Value; newState.ZeroFlag = result.ZeroFlag; return newState; }
public MachineState DoOperation(RegisterName lhs, OperatorEffect operatorEffect, AbstractValue rhs) { var newState = new MachineState(this); if (Registers[lhs].IsPointer && operatorEffect != OperatorEffect.Assignment) { var newBuffer = Registers[lhs].PointsTo.DoOperation(operatorEffect, rhs); newState.Registers[lhs] = new AbstractValue(newBuffer); } else { var result = DoOperation(Registers[lhs], operatorEffect, rhs); newState.Registers[lhs] = result.Value; newState.ZeroFlag = result.ZeroFlag; } return newState; }
public MachineState DoOperation(RegisterName lhs, Int32 index, OperatorEffect operatorEffect, AbstractValue rhs) { var newState = new MachineState(this); switch (operatorEffect) { case OperatorEffect.Assignment: case OperatorEffect.Cmp: { var result = DoOperation(Registers[lhs].PointsTo[index], operatorEffect, rhs); newState.Registers[lhs].PointsTo[index] = result.Value; newState.ZeroFlag = result.ZeroFlag; break; } } return newState; }
public MachineState DoOperation(UInt32 offset, OperatorEffect operatorEffect, AbstractValue rhs) { var newState = new MachineState(this); switch (operatorEffect) { case OperatorEffect.Assignment: { newState.dataSegment[offset] = DoOperation(newState.dataSegment[offset], operatorEffect, rhs).Value; break; } } return newState; }
public MachineState DoOperation(OperatorEffect operatorEffect, AbstractValue offset) { if (offset.IsPointer) { throw new ArgumentException("_offset pointer not supported."); } var newState = new MachineState(this); switch (operatorEffect) { case OperatorEffect.Jnz: { if (!newState.zeroFlag) { newState.instructionPointer += offset.Value; } break; } default: { throw new ArgumentException( String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect"); } } return newState; }