public ShortMemoryComparer(ScanCompareType compareType, short value1, short value2) { CompareType = compareType; Value1 = value1; Value2 = value2; }
/// <summary> /// Creates a <see cref="IScanComparer"/> for the given <see cref="ScanCompareType"/> and <see cref="ScanValueType"/>. /// </summary> /// <param name="compareType">The <see cref="ScanCompareType"/> to use.</param> /// <returns>The created <see cref="IScanComparer"/>.</returns> private IScanComparer CreateScanComparer(ScanCompareType compareType) { Contract.Ensures(Contract.Result <IScanComparer>() != null); switch (Settings.ValueType) { case ScanValueType.Byte: return(new ByteMemoryComparer(compareType, 0, 0)); case ScanValueType.Short: return(new ShortMemoryComparer(compareType, 0, 0)); case ScanValueType.Integer: return(new IntegerMemoryComparer(compareType, 0, 0)); case ScanValueType.Long: return(new LongMemoryComparer(compareType, 0, 0)); case ScanValueType.Float: return(new FloatMemoryComparer(compareType, ScanRoundMode.Normal, 2, 0, 0)); case ScanValueType.Double: return(new DoubleMemoryComparer(compareType, ScanRoundMode.Normal, 2, 0, 0)); default: throw new InvalidOperationException(); } }
public IntegerMemoryComparer(ScanCompareType compareType, int value1, int value2) { CompareType = compareType; Value1 = value1; Value2 = value2; }
public LongMemoryComparer(ScanCompareType compareType, long value1, long value2) { CompareType = compareType; Value1 = value1; Value2 = value2; }
public ByteMemoryComparer(ScanCompareType compareType, byte value1, byte value2) { CompareType = compareType; Value1 = value1; Value2 = value2; }
public LongMemoryComparer(ScanCompareType compareType, long value1, long value2, EndianBitConverter bitConverter) { CompareType = compareType; Value1 = value1; Value2 = value2; this.bitConverter = bitConverter; }
public void TestConstructor(ScanCompareType compareType, int value1, int value2) { var sut = new IntegerMemoryComparer(compareType, value1, value2); Check.That(sut.CompareType).IsEqualTo(compareType); Check.That(sut.ValueSize).IsEqualTo(sizeof(int)); Check.That(sut.Value1).IsOneOf(value1, value2); Check.That(sut.Value2).IsOneOf(value1, value2); }
public void TestConstructor(ScanCompareType compareType, short value1, short value2) { var sut = new ShortMemoryComparer(compareType, value1, value2, BitConverter); Check.That(sut.CompareType).IsEqualTo(compareType); Check.That(sut.ValueSize).IsEqualTo(sizeof(short)); Check.That(sut.Value1).IsOneOf(value1, value2); Check.That(sut.Value2).IsOneOf(value1, value2); }
public IntegerMemoryComparer(ScanCompareType compareType, int value1, int value2, EndianBitConverter bitConverter) { CompareType = compareType; Value1 = value1; Value2 = value2; this.bitConverter = bitConverter; }
public void TestConstructor(ScanCompareType compareType, byte value1, byte value2) { var sut = new ByteMemoryComparer(compareType, value1, value2); Check.That(sut.CompareType).IsEqualTo(compareType); Check.That(sut.ValueSize).IsEqualTo(sizeof(byte)); Check.That(sut.Value1).IsOneOf(value1, value2); Check.That(sut.Value2).IsOneOf(value1, value2); }
public ShortMemoryComparer(ScanCompareType compareType, short value1, short value2, EndianBitConverter bitConverter) { CompareType = compareType; Value1 = value1; Value2 = value2; this.bitConverter = bitConverter; }
public void TestConstructor(ScanCompareType compareType, ScanRoundMode roundMode, float value1, float value2) { var sut = new FloatMemoryComparer(compareType, roundMode, 1, value1, value2, BitConverter); Check.That(sut.CompareType).IsEqualTo(compareType); Check.That(sut.RoundType).IsEqualTo(roundMode); Check.That(sut.ValueSize).IsEqualTo(sizeof(float)); Check.That(sut.Value1).IsOneOf(value1, value2); Check.That(sut.Value2).IsOneOf(value1, value2); }
public void TestCompare(ScanCompareType compareType, long value1, long value2, byte[] data, bool expectedResult, ScanResult expectedScanResult) { var sut = new LongMemoryComparer(compareType, value1, value2, BitConverter); Check.That(sut.Compare(data, 0, out var scanResult)).IsEqualTo(expectedResult); Check.That(scanResult).IsEqualTo(expectedScanResult); if (scanResult != null) { Check.That(scanResult).IsInstanceOf <LongScanResult>(); } }
public void TestCompare(ScanCompareType compareType, int value1, int value2, byte[] data, bool expectedResult, ScanResult expectedScanResult) { var sut = new IntegerMemoryComparer(compareType, value1, value2); Check.That(sut.Compare(data, 0, out var scanResult)).IsEqualTo(expectedResult); Check.That(scanResult).IsEqualTo(expectedScanResult); if (scanResult != null) { Check.That(scanResult).IsInstanceOf <IntegerScanResult>(); } }
public void TestCompare(ScanCompareType compareType, float value1, float value2, byte[] data, bool expectedResult, ScanResult expectedScanResult) { var sut = new FloatMemoryComparer(compareType, ScanRoundMode.Normal, 1, value1, value2, BitConverter); Check.That(sut.Compare(data, 0, out var scanResult)).IsEqualTo(expectedResult); Check.That(scanResult).IsEqualTo(expectedScanResult); if (scanResult != null) { Check.That(scanResult).IsInstanceOf <FloatScanResult>(); } }
public void TestCompareWithPrevious(ScanCompareType compareType, short value1, short value2, byte[] data, ScanResult previousScanResult, bool expectedResult, ScanResult expectedScanResult) { var sut = new ShortMemoryComparer(compareType, value1, value2); Check.That(sut.Compare(data, 0, previousScanResult, out var scanResult)).IsEqualTo(expectedResult); Check.That(scanResult).IsEqualTo(expectedScanResult); if (scanResult != null) { Check.That(scanResult).IsInstanceOf <ShortScanResult>(); } }
private void ComboBox_CompareType_SelectedIndexChanged(object sender, EventArgs e) { ScanCompareType RescanCompareType = Conversions.Conversions.StringToScanType(ComboBox_CompareType.Items[ComboBox_CompareType.SelectedIndex].ToString()); if (TextBox_ScanValue.Enabled) { OldValueText = TextBox_ScanValue.Text; } if (ScanSecondValueTextBox.Visible) { OldSecondValueText = ScanSecondValueTextBox.Text; } Label_CompareType.Text = RescanCompareType.ToString().Replace('_', ' '); switch (RescanCompareType) { case ScanCompareType.Exact_Value: case ScanCompareType.Not_Equal_to_Value: case ScanCompareType.Increased_by_Value: case ScanCompareType.Decreased_by_Value: case ScanCompareType.Less_Than: case ScanCompareType.Greater_Than: ScanSecondValueTextBox.Text = ""; TextBox_ScanValue.Text = OldValueText; ScanSecondValueTextBox.Visible = false; TextBox_ScanValue.Enabled = true; TextBox_ScanValue.Width = 214; break; case ScanCompareType.Changed_Value: case ScanCompareType.Unchanged_Value: case ScanCompareType.Increased_Value: case ScanCompareType.Decreased_Value: case ScanCompareType.Unknown_Value: TextBox_ScanValue.Text = ""; ScanSecondValueTextBox.Text = ""; ScanSecondValueTextBox.Visible = false; TextBox_ScanValue.Enabled = false; TextBox_ScanValue.Width = 214; break; case ScanCompareType.Between_Exclusive: ScanSecondValueTextBox.Text = OldSecondValueText; ScanSecondValueTextBox.Visible = true; TextBox_ScanValue.Visible = true; TextBox_ScanValue.Enabled = true; TextBox_ScanValue.Width = ScanSecondValueTextBox.Width; break; } }
public void TestConstructor(ScanCompareType compareType, int value1, int value2) { var sut = new IntegerMemoryComparer(compareType, value1, value2); Check.That(sut.CompareType).IsEqualTo(compareType); Check.That(sut.ValueSize).IsEqualTo(sizeof(int)); Check.That(sut.Value1).IsOneOf(value1, value2); Check.That(sut.Value2).IsOneOf(value1, value2); if (compareType == ScanCompareType.Between || compareType == ScanCompareType.BetweenOrEqual) { Check.That(sut.Value1 <= sut.Value2).IsTrue(); } }
/// <summary> /// Creates a <see cref="IScanComparer"/> for the given <see cref="ScanCompareType"/> and <see cref="ScanValueType"/>. /// </summary> /// <param name="compareType">The <see cref="ScanCompareType"/> to use.</param> /// <returns>The created <see cref="IScanComparer"/>.</returns> private IScanComparer CreateScanComparer(ScanCompareType compareType) { Contract.Ensures(Contract.Result <IScanComparer>() != null); return(Settings.ValueType switch { ScanValueType.Byte => new ByteMemoryComparer(compareType, 0, 0), ScanValueType.Short => new ShortMemoryComparer(compareType, 0, 0, process.BitConverter), ScanValueType.Integer => new IntegerMemoryComparer(compareType, 0, 0, process.BitConverter), ScanValueType.Long => new LongMemoryComparer(compareType, 0, 0, process.BitConverter), ScanValueType.Float => new FloatMemoryComparer(compareType, ScanRoundMode.Normal, 2, 0, 0, process.BitConverter), ScanValueType.Double => new DoubleMemoryComparer(compareType, ScanRoundMode.Normal, 2, 0, 0, process.BitConverter), _ => throw new InvalidOperationException(), });
public FloatMemoryComparer(ScanCompareType compareType, ScanRoundMode roundType, int significantDigits, float value1, float value2) { CompareType = compareType; RoundType = roundType; this.significantDigits = Math.Max(significantDigits, 1); Value1 = (float)Math.Round(value1, this.significantDigits, MidpointRounding.AwayFromZero); Value2 = (float)Math.Round(value2, this.significantDigits, MidpointRounding.AwayFromZero); var factor = (int)Math.Pow(10.0, this.significantDigits); minValue = value1 - 1.0f / factor; maxValue = value1 + 1.0f / factor; }
public IntegerMemoryComparer(ScanCompareType compareType, int value1, int value2) { CompareType = compareType; if (compareType == ScanCompareType.Between || compareType == ScanCompareType.BetweenOrEqual) { if (value1 > value2) { Utils.Swap(ref value1, ref value2); } } Value1 = value1; Value2 = value2; }
public DoubleMemoryComparer(ScanCompareType compareType, ScanRoundMode roundType, int significantDigits, double value1, double value2, EndianBitConverter bitConverter) { CompareType = compareType; RoundType = roundType; this.significantDigits = Math.Max(significantDigits, 1); Value1 = Math.Round(value1, this.significantDigits, MidpointRounding.AwayFromZero); Value2 = Math.Round(value2, this.significantDigits, MidpointRounding.AwayFromZero); var factor = (int)Math.Pow(10.0, this.significantDigits); minValue = value1 - 1.0 / factor; maxValue = value1 + 1.0 / factor; this.bitConverter = bitConverter; }
public DoubleMemoryComparer(ScanCompareType compareType, ScanRoundMode roundType, int significantDigits, double value1, double value2) { CompareType = compareType; if (compareType == ScanCompareType.Between || compareType == ScanCompareType.BetweenOrEqual) { if (value1 > value2) { Utils.Swap(ref value1, ref value2); } } RoundType = roundType; this.significantDigits = Math.Max(significantDigits, 1); Value1 = Math.Round(value1, this.significantDigits, MidpointRounding.AwayFromZero); Value2 = Math.Round(value2, this.significantDigits, MidpointRounding.AwayFromZero); var factor = (int)Math.Pow(10.0, this.significantDigits); minValue = value1 - 1.0 / factor; maxValue = value1 + 1.0 / factor; }
private Int64 _ScanValue; //Rounded value for singles/doubles for significant digit comparisons #endregion Fields #region Constructors //Constructor public ScanMemory(Process Process, UInt64 StartAddress, UInt64 EndAddress, ScanDataType ScanDataType, ScanCompareType ScanCompareType, object ScanValue, object SecondScanValue, uint[] Protect, uint[] Type, bool Truncated, ScanOptimizationData ScanOptimizationData, string ExecutablePath, bool CompareToFirstScan) { ProcessMemoryEditor = new ProcessMemoryEditor(); ProcessMemoryEditor.ReadProcess = Process; this.BaseAddress = (IntPtr)StartAddress; this.MaxAddress = (IntPtr)EndAddress; this.ScanDataType = ScanDataType; this.ScanCompareType = ScanCompareType; this.Protect = Protect; this.Type = Type; this.ScanValue = ScanValue; this.SecondScanValue = SecondScanValue; this.Truncated = Truncated; this.ScanOptimizationData = ScanOptimizationData; this.ExecutablePath = ExecutablePath; this.CompareToFirstScan = CompareToFirstScan; }
public InvalidCompareTypeException(ScanCompareType type) : base($"{type} is not valid in the current state.") { }
public void TestCompareInvalidCompareTypeThrows(ScanCompareType compareType) { var sut = new ByteMemoryComparer(compareType, 0, 0); Check.ThatCode(() => sut.Compare(new byte[] { 0 }, 0, out _)).Throws <InvalidCompareTypeException>(); }
public void TestCompareInvalidCompareTypeThrows(ScanCompareType compareType) { var sut = new FloatMemoryComparer(compareType, ScanRoundMode.Normal, 1, 0.0f, 0.0f, BitConverter); Check.ThatCode(() => sut.Compare(BitConverter.GetBytes(0.0f), 0, out _)).Throws <InvalidCompareTypeException>(); }
public List <ulong> ScanProcess <T>(int pid, ScanCompareType compareType, T value, T extraValue = default) { CheckConnected(); int typeLength = 0; ScanValueType valueType; byte[] valueBuffer, extraValueBuffer = null; // fill in variables switch (value) { case bool b: valueType = ScanValueType.valTypeUInt8; typeLength = 1; valueBuffer = BitConverter.GetBytes(b); if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((bool)(object)extraValue); } break; case sbyte sb: valueType = ScanValueType.valTypeInt8; valueBuffer = BitConverter.GetBytes(sb); typeLength = 1; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((sbyte)(object)extraValue); } break; case byte b: valueType = ScanValueType.valTypeUInt8; valueBuffer = BitConverter.GetBytes(b); typeLength = 1; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((byte)(object)extraValue); } break; case short s: valueType = ScanValueType.valTypeInt16; valueBuffer = BitConverter.GetBytes(s); typeLength = 2; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((short)(object)extraValue); } break; case ushort us: valueType = ScanValueType.valTypeUInt16; valueBuffer = BitConverter.GetBytes(us); typeLength = 2; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((ushort)(object)extraValue); } break; case int i: valueType = ScanValueType.valTypeInt32; valueBuffer = BitConverter.GetBytes(i); typeLength = 4; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((int)(object)extraValue); } break; case uint ui: valueType = ScanValueType.valTypeUInt32; valueBuffer = BitConverter.GetBytes(ui); typeLength = 4; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((uint)(object)extraValue); } break; case long l: valueType = ScanValueType.valTypeInt64; valueBuffer = BitConverter.GetBytes(l); typeLength = 8; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((long)(object)extraValue); } break; case ulong ul: valueType = ScanValueType.valTypeUInt64; valueBuffer = BitConverter.GetBytes(ul); typeLength = 8; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((ulong)(object)extraValue); } break; case float f: valueType = ScanValueType.valTypeFloat; valueBuffer = BitConverter.GetBytes(f); typeLength = 4; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((float)(object)extraValue); } break; case double d: valueType = ScanValueType.valTypeDouble; valueBuffer = BitConverter.GetBytes(d); typeLength = 8; if (extraValue != null) { extraValueBuffer = BitConverter.GetBytes((double)(object)extraValue); } break; case string s: valueType = ScanValueType.valTypeString; valueBuffer = Encoding.ASCII.GetBytes(s); typeLength = valueBuffer.Length; break; case byte[] ba: valueType = ScanValueType.valTypeArrBytes; valueBuffer = ba; typeLength = valueBuffer.Length; break; default: throw new NotSupportedException("Requested scan value type is not supported! (Feed in Byte[] instead.)"); } // send packet SendCMDPacket(CMDS.CMD_PROC_SCAN, CMD_PROC_SCAN_PACKET_SIZE, pid, (byte)valueType, (byte)compareType, (int)(extraValue == null ? typeLength : typeLength * 2)); CheckStatus(); SendData(valueBuffer, typeLength); if (extraValueBuffer != null) { SendData(extraValueBuffer, typeLength); } CheckStatus(); // receive results int save = sock.ReceiveTimeout; sock.ReceiveTimeout = Int32.MaxValue; List <ulong> results = new List <ulong>(); while (true) { ulong result = BitConverter.ToUInt64(ReceiveData(sizeof(ulong)), 0); if (result == 0xFFFFFFFFFFFFFFFF) { break; } results.Add(result); } sock.ReceiveTimeout = save; return(results); }
public void TestCompareInvalidCompareTypeThrows(ScanCompareType compareType) { var sut = new IntegerMemoryComparer(compareType, 0, 0); Check.ThatCode(() => sut.Compare(BitConverter.GetBytes(0), 0, out _)).Throws <InvalidCompareTypeException>(); }