/// <summary> /// Converts the text to hex. /// </summary> private void ConvertHex() { if (SyntaxChecker.CanParseValue(this.DataType, this.Text)) { this.Text = Conversions.ParsePrimitiveStringAsHexString(this.DataType, this.Text); } this.SwitchHex(); }
/// <summary> /// Converts a value to an address. /// </summary> /// <param name="context">Type descriptor context.</param> /// <param name="culture">Globalization info.</param> /// <param name="value">The value being converted.</param> /// <param name="destinationType">The target type to convert to.</param> /// <returns>The converted value.</returns> public override Object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType) { if (SyntaxChecker.CanParseValue(DataType.UInt64, value?.ToString())) { return(Conversions.ToHex(Conversions.ParsePrimitiveStringAsPrimitive(DataType.UInt64, value?.ToString()), formatAsAddress: true, includePrefix: false)); } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Invoked when the convert to hexedecimal menu item is clicked. /// </summary> /// <param name="sender">Sending object.</param> /// <param name="e">Event args.</param> private void ConvertToHexMenuItemClick(Object sender, EventArgs e) { if (SyntaxChecker.CanParseValue(this.ElementType, this.Text)) { this.Text = Conversions.ParsePrimitiveStringAsHexString(this.ElementType, this.Text); } this.IsHex = true; }
/// <summary> /// Sets the raw value being represented. /// </summary> /// <param name="value">The raw value.</param> public void SetValue(Object value) { String valueString = value?.ToString(); if (!SyntaxChecker.CanParseValue(this.DataType, valueString)) { return; } if (this.IsHex) { this.Text = Conversions.ParsePrimitiveStringAsHexString(this.DataType, valueString); } else { this.Text = valueString; } }
/// <summary> /// Converts a value to the proper dynamic type. /// </summary> /// <param name="context">Type descriptor context.</param> /// <param name="culture">Globalization info.</param> /// <param name="value">The value being converted.</param> /// <param name="destinationType">The target type to convert to.</param> /// <returns>The converted value.</returns> public override Object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType) { String valueString = (value == null) ? String.Empty : value.ToString(); DataType dataType = (value == null) ? null : value.GetType(); Boolean isHex = false; if (typeof(AddressItem).IsAssignableFrom(context?.Instance?.GetType())) { isHex = (context.Instance as AddressItem).IsValueHex; } if (value == null || !SyntaxChecker.CanParseValue(dataType, valueString)) { return(base.ConvertTo(context, culture, value, destinationType)); } return(isHex ? Conversions.ParsePrimitiveAsHexString(dataType, valueString) : valueString); }
/// <summary> /// Edits a project item based on the project item type. /// </summary> /// <param name="projectItem">The project item to edit.</param> private void EditProjectItem(ProjectItem projectItem) { if (projectItem is AddressItem) { ValueEditorModel valueEditor = new ValueEditorModel(); AddressItem addressItem = projectItem as AddressItem; dynamic result = valueEditor.EditValue(null, null, addressItem); if (SyntaxChecker.CanParseValue(addressItem.DataType, result?.ToString())) { addressItem.AddressValue = result; } } else if (projectItem is ScriptItem) { ScriptEditorModel scriptEditor = new ScriptEditorModel(); ScriptItem scriptItem = projectItem as ScriptItem; scriptItem.Script = scriptEditor.EditValue(null, null, scriptItem.Script) as String; } }
/// <summary> /// Initializes a new instance of the <see cref="AddressItem" /> class. /// </summary> /// <param name="baseAddress">The base address. This will be added as an offset from the resolved base identifier.</param> /// <param name="dataType">The data type of the value at this address.</param> /// <param name="description">The description of this address.</param> /// <param name="baseIdentifier">The identifier for the base address of this object.</param> /// <param name="offsets">The pointer offsets of this address item.</param> /// <param name="isValueHex">A value indicating whether the value at this address should be displayed as hex.</param> /// <param name="value">The value at this address. If none provided, it will be figured out later. Used here to allow immediate view updates upon creation.</param> public AddressItem( DataType dataType, String description = "New Address", Boolean isValueHex = false, Object value = null) : base(description) { // Bypass setters to avoid running setter code this.dataType = dataType; this.isValueHex = isValueHex; if (!this.isValueHex && SyntaxChecker.CanParseValue(dataType, value?.ToString())) { this.addressValue = value; } else if (this.isValueHex && SyntaxChecker.CanParseHex(dataType, value?.ToString())) { this.addressValue = value; } }
/// <summary> /// Determines if the current text is valid for the current data type. /// </summary> private void UpdateValidity() { if (this.IsHex) { if (SyntaxChecker.CanParseHex(this.ElementType, this.Text)) { this.IsTextValid = true; return; } } else { if (SyntaxChecker.CanParseValue(this.ElementType, this.Text)) { this.IsTextValid = true; return; } } this.IsTextValid = false; return; }
/// <summary> /// Converts an address string to the corresponding value. /// </summary> /// <param name="context">Type descriptor context.</param> /// <param name="culture">Globalization info.</param> /// <param name="value">The value being converted.</param> /// <returns>The converted value.</returns> public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) { DataType dataType = null; Boolean isHex = false; if (typeof(AddressItem).IsAssignableFrom(context.Instance.GetType())) { dataType = (context.Instance as AddressItem)?.DataType; isHex = (context.Instance as AddressItem).IsValueHex; } if (dataType == (DataType)null || !value.GetType().IsAssignableFrom(typeof(String))) { return(base.ConvertFrom(context, culture, value)); } if (!(isHex ? SyntaxChecker.CanParseHex(dataType, value as String) : SyntaxChecker.CanParseValue(dataType, value as String))) { return(base.ConvertFrom(context, culture, value)); } return(isHex ? Conversions.ParseHexStringAsPrimitive(dataType, value as String) : Conversions.ParsePrimitiveStringAsPrimitive(dataType, value as String)); }
public Int32 Handle() { DataTypeBase dataType = ScanSettings.DataType; ScanConstraint.ConstraintType constraintType = ScanConstraint.ConstraintType.Equal; if (String.IsNullOrWhiteSpace(this.Constraint)) { // Default to equals this.Constraint = "e"; } switch (this.Constraint.ToLower()) { case "le": break; case "l": break; case "g": break; case "ge": break; case "e": break; case "c": break; case "u": break; case "i": break; case "d": break; default: Console.WriteLine("Unknown constraint type '" + this.Constraint + "', defaulting to equal"); break; } if (!SyntaxChecker.CanParseValue(dataType, this.Value)) { Console.WriteLine("Failed to parse '" + this.Value + "' as data type " + dataType?.ToString()); return(-1); } ScanConstraint scanConstraints = new ScanConstraint(constraintType, dataType, Conversions.ParsePrimitiveStringAsPrimitive(dataType, this.Value)); // Collect values TrackableTask <Snapshot> valueCollectorTask = ValueCollector.CollectValues( SessionManager.Session.SnapshotManager.GetActiveSnapshotCreateIfNone(SessionManager.Session.OpenedProcess, dataType), TrackableTask.UniversalIdentifier); // Perform manual scan Snapshot snapshot = valueCollectorTask.Result; TrackableTask <Snapshot> scanTask = ManualScanner.Scan( snapshot, scanConstraints, TrackableTask.UniversalIdentifier); SessionManager.Session.SnapshotManager.SaveSnapshot(scanTask.Result); Console.WriteLine(); return(0); }