예제 #1
0
        /// <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)
        {
            Type    valueType = null;
            Boolean isHex     = false;

            if (context.Instance.GetType().IsAssignableFrom(typeof(AddressItem)))
            {
                valueType = (context.Instance as AddressItem)?.ElementType;
            }

            if (context.Instance.GetType().IsAssignableFrom(typeof(AddressItem)))
            {
                isHex = (context.Instance as AddressItem).IsValueHex;
            }

            if (valueType == null || !value.GetType().IsAssignableFrom(typeof(String)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            if (!(isHex ? CheckSyntax.CanParseHex(valueType, value as String) : CheckSyntax.CanParseValue(valueType, value as String)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            return(isHex ? Conversions.ParseHexStringAsDynamic(valueType, value as String) : Conversions.ParsePrimitiveStringAsDynamic(valueType, value as String));
        }
예제 #2
0
        private void acceptButton_Click(object sender, EventArgs e)
        {
            string ValueString = AddressTextBox.Text;

            //If not hex we can just convert address to an int and use it
            if (!IsHexCB.Checked)
            {
                //Check if address is a valid non-hex integer
                if (CheckSyntax.Int32Value(ValueString, IsHexCB.Checked))
                {
                    //Convert to a hex string
                    Address = Convert.ToUInt64(ValueString);
                }
                else //Wasn't a valid integer
                {
                    MessageBox.Show("Invalid address format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    failed = true;
                }
            }

            //Check if hex string is valid
            else if (CheckSyntax.Address(ValueString))
            {
                //Valid: proceed to convert it to an int
                Address = Conversions.HexToUInt64(AddressTextBox.Text);
            }
            else //Nope, they screwed up
            {
                MessageBox.Show("Invalid address format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                failed = true;
            }
        }
        /// <summary>
        /// Event for double clicking a project node.
        /// </summary>
        /// <param name="sender">Sending object.</param>
        /// <param name="e">Tree node mouse event args.</param>
        private void ProjectExplorerTreeViewNodeMouseDoubleClick(Object sender, TreeNodeAdvMouseEventArgs e)
        {
            if (e == null || e.Node == null)
            {
                return;
            }

            ProjectItem projectItem = this.GetProjectItemFromNode(e.Node);

            if (projectItem is AddressItem)
            {
                ValueEditorModel valueEditor = new ValueEditorModel();
                AddressItem      addressItem = projectItem as AddressItem;
                dynamic          result      = valueEditor.EditValue(null, null, addressItem);

                if (CheckSyntax.CanParseValue(addressItem.ElementType, result?.ToString()))
                {
                    addressItem.Value = 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;
            }
        }
예제 #4
0
        /// <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="elementType">The data type of the value at this address.</param>
        /// <param name="description">The description of this address.</param>
        /// <param name="resolveType">The identifier type for this address item.</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(
            IntPtr baseAddress,
            Type elementType,
            String description = "New Address",
            AddressResolver.ResolveTypeEnum resolveType = AddressResolver.ResolveTypeEnum.Module,
            String baseIdentifier       = null,
            IEnumerable <Int32> offsets = null,
            Boolean isValueHex          = false,
            String value = null)
            : base(description)
        {
            // Bypass setters to avoid running setter code
            this.baseAddress    = baseAddress;
            this.ElementType    = elementType;
            this.resolveType    = resolveType;
            this.baseIdentifier = baseIdentifier;
            this.offsets        = offsets;
            this.isValueHex     = isValueHex;

            if (!this.isValueHex && CheckSyntax.CanParseValue(elementType, value))
            {
                this.addressValue = Conversions.ParsePrimitiveStringAsDynamic(elementType, value);
            }
            else if (this.isValueHex && CheckSyntax.CanParseHex(elementType, value))
            {
                this.addressValue = Conversions.ParseHexStringAsPrimitiveString(elementType, value);
            }
        }
예제 #5
0
        private void Button_Scan_Start_Click(object sender, EventArgs e)
        {
            UInt64 FirstAddress;
            UInt64 LastAddress;

            if (!CheckSyntax.Address(TextBox_EndAddress.Text) || !CheckSyntax.Address(TextBox_StartAddress.Text))
            {
                MessageBox.Show("Address range must be in hexadecimal format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            FirstAddress = Conversions.Conversions.HexToUInt64(TextBox_StartAddress.Text);
            LastAddress  = Conversions.Conversions.HexToUInt64(TextBox_EndAddress.Text);

            if ((FirstAddress < 0 || FirstAddress > SystemMaxAddress) || (LastAddress < 0 || LastAddress > SystemMaxAddress))
            {
                MessageBox.Show("Addresses must be between 0 and " + SystemMaxAddress.ToString() + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (LastAddress < FirstAddress)
            {
                MessageBox.Show("Invalid address range. Swapping values and attempting to proceed anyways.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                UInt64 Temp = FirstAddress;
                FirstAddress = LastAddress;
                LastAddress  = Temp;
            }

            if (CheckBox_OptimizeScan.Checked && !RadioButton_LastDigits.Checked)
            {
                while (FirstAddress % NUD_OptimizeScan.Value != 0)
                {
                    FirstAddress++;
                }
                while (LastAddress % NUD_OptimizeScan.Value != 0)
                {
                    LastAddress--;
                }

                if ((FirstAddress < 0 || FirstAddress > SystemMaxAddress) || (LastAddress < 0 || LastAddress > SystemMaxAddress))
                {
                    MessageBox.Show("Specified allignment results in invalid address range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            if (!ScanButtonShared(false, FirstAddress, LastAddress))
            {
                return;
            }

            TextBox_StartAddress.Enabled = false;
            TextBox_EndAddress.Enabled   = false;
            ComboBox_DataType.Enabled    = false;
            Button_Scan_Start.Enabled    = false;
            Canceled = false;
            Button_Scan_Abort.Enabled = true;
            ListView_Address.Items.Clear();
            ShowSecondScanOptions();
        }
예제 #6
0
        private void Button_Accept_Click(object sender, EventArgs e)
        {
            string ValueString = TextBox_Address.Text;

            if (!CheckBox_IsHex.Checked)
            {
                if (CheckSyntax.Int32Value(ValueString, CheckBox_IsHex.Checked))
                {
                    Address = Convert.ToUInt64(ValueString);
                }
                else
                {
                    MessageBox.Show("Invalid address format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    failed = true;
                }
            }

            else if (CheckSyntax.Address(ValueString))
            {
                Address = Conversions.Conversions.HexToUInt64(TextBox_Address.Text);
            }
            else
            {
                MessageBox.Show("Invalid address format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                failed = true;
            }
        }
예제 #7
0
        /// <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 (CheckSyntax.CanParseValue(typeof(UInt64), value.ToString()))
            {
                return(Conversions.ToHex(Conversions.ParsePrimitiveStringAsDynamic(typeof(UInt64), value.ToString()), formatAsAddress: true, includePrefix: false));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
예제 #8
0
        /// <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)
        {
            if (CheckSyntax.CanParseAddress(value.ToString()))
            {
                return(Conversions.AddressToValue(value.ToString()).ToIntPtr());
            }

            return(base.ConvertFrom(context, culture, value));
        }
예제 #9
0
        /// <summary>
        /// Invoked when the convert to decimal menu item is clicked.
        /// </summary>
        /// <param name="sender">Sending object.</param>
        /// <param name="e">Event args.</param>
        private void ConvertToDecMenuItemClick(Object sender, EventArgs e)
        {
            if (CheckSyntax.CanParseHex(this.ElementType, this.Text))
            {
                this.Text = Conversions.ParseHexStringAsPrimitiveString(this.ElementType, this.Text);
            }

            this.IsHex = false;
        }
예제 #10
0
        public static string HexToDec(string value, bool isAddress)
        {
            //Check if valid syntax of a hex address
            if (CheckSyntax.Int64Value(value, true))
            {
                value = Conversions.HexToUInt64(value).ToString();
            }

            //Return updated string
            return(value);
        }
예제 #11
0
 private void txtFullName_KeyUp(object sender, KeyRoutedEventArgs e)
 {
     try
     {
         //For check sytax entered in NAme field
         CheckSyntax.checkOnlyName(sender, e);
     }
     catch (Exception ex)
     {
         MessageDialog msg = new MessageDialog(ex.Message + " Void - txtFullNAme_KeyUp");
         //msg.ShowAsync();
     }
 }
예제 #12
0
 private void txtPhoneNumber_KeyUp(object sender, KeyRoutedEventArgs e)
 {
     try
     {
         //For check sytax entered in PhoneNumber field
         CheckSyntax.checkOnlyNumber(sender, e);
     }
     catch (Exception ex)
     {
         MessageDialog msg = new MessageDialog(ex.Message, "Err - txtPhoneNumber_KeyUp");
         //msg.ShowAsync();
     }
 }
예제 #13
0
 //Converts to 8 digit address format
 public static string ToAddress(string value)
 {
     if (CheckSyntax.Int32Value(value, false))
     {
         return(String.Format("{0:X8}", Convert.ToUInt32(value)));
     }
     else if (CheckSyntax.Int64Value(value, false))
     {
         return(String.Format("{0:X16}", Convert.ToUInt64(value)));
     }
     else
     {
         return("??");
     }
 }
예제 #14
0
        private void SetNewCoords(int addX, int addY)
        {
            //Check syntax for int of all values
            if (!(CheckSyntax.Int32Value(XTextBox.Text, false) && CheckSyntax.Int32Value(YTextBox.Text, false) &&
                  CheckSyntax.Int32Value(WTextBox.Text, false) && CheckSyntax.Int32Value(HTextBox.Text, false)))
            {
                return;
            }

            int x = Convert.ToInt32(XTextBox.Text) + addX;
            int y = Convert.ToInt32(YTextBox.Text) + addY;
            int w = Convert.ToInt32(WTextBox.Text);
            int h = Convert.ToInt32(HTextBox.Text);

            WindowEditor.SetWindowPosm((IntPtr)Child_hwnd, IntPtr.Zero, x, y, w, h, 0);
            this.Focus();
        }
예제 #15
0
        /// <summary>
        /// Hex string to an Int32.
        /// </summary>
        /// <param name="value">Value to be converted.</param>
        /// <param name="targetType">Type to convert to.</param>
        /// <param name="parameter">Optional conversion parameter.</param>
        /// <param name="culture">Globalization info.</param>
        /// <returns>An Int32. If conversion cannot take place, returns 0.</returns>
        public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(0);
            }

            if (value is String)
            {
                if (CheckSyntax.CanParseHex(typeof(Int32), value.ToString()))
                {
                    return(Conversions.ParseHexStringAsDynamic(typeof(Int32), value.ToString()));
                }
            }

            return(0);
        }
예제 #16
0
        /// <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 (!CheckSyntax.CanParseValue(this.ElementType, valueString))
            {
                return;
            }

            if (this.IsHex)
            {
                this.Text = Conversions.ParsePrimitiveStringAsHexString(this.ElementType, valueString);
            }
            else
            {
                this.Text = valueString;
            }
        }
예제 #17
0
        /// <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();
            Type    valueType   = (value == null) ? null : value.GetType();
            Boolean isHex       = false;

            if (context.Instance.GetType().IsAssignableFrom(typeof(AddressItem)))
            {
                isHex = (context.Instance as AddressItem).IsValueHex;
            }

            if (value == null || !CheckSyntax.CanParseValue(valueType, valueString))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            return(isHex ? Conversions.ParseDynamicAsHexString(valueType, valueString) : valueString);
        }
예제 #18
0
        public static string DecToHex(string value, bool isAddress)
        {
            //Convert to hex

            //Check if valid syntax of an integer address
            if (CheckSyntax.Int32Value(value, false))
            {
                if (isAddress)
                {
                    value = Conversions.ToAddress(value);
                }
                else
                {
                    value = Conversions.ToHex(value);
                }
            }

            return(value);
        }
예제 #19
0
        /// <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 (CheckSyntax.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;
            }
        }
예제 #20
0
        /// <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(
            Type dataType,
            String description = "New Address",
            Boolean isValueHex = false,
            String value       = null)
            : base(description)
        {
            // Bypass setters to avoid running setter code
            this.dataType   = dataType;
            this.isValueHex = isValueHex;

            if (!this.isValueHex && CheckSyntax.CanParseValue(dataType, value))
            {
                this.addressValue = Conversions.ParsePrimitiveStringAsPrimitive(dataType, value);
            }
            else if (this.isValueHex && CheckSyntax.CanParseHex(dataType, value))
            {
                this.addressValue = Conversions.ParseHexStringAsPrimitiveString(dataType, value);
            }
        }
예제 #21
0
        /// <summary>
        /// Determines if the current text is valid for the current data type.
        /// </summary>
        private void UpdateValidity()
        {
            if (this.IsHex)
            {
                if (CheckSyntax.CanParseHex(this.ElementType, this.Text))
                {
                    this.IsTextValid = true;
                    return;
                }
            }
            else
            {
                if (CheckSyntax.CanParseValue(this.ElementType, this.Text))
                {
                    this.IsTextValid = true;
                    return;
                }
            }

            this.IsTextValid = false;
            return;
        }
예제 #22
0
        private bool ScanButtonShared(bool IsRescan, UInt64 FirstAddress, UInt64 LastAddress)
        {
            object ScanValue;
            object SecondScanValue;

            SelectedScanType = (ScanDataType)ComboBox_DataType.SelectedIndex;

            #region Collect scan data from form and check for errors
            if (TargetProcess == null)
            {
                MessageBox.Show("Please select a process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            if (!CheckSyntax.Value(TextBox_ScanValue.Text, (ScanDataType)ComboBox_DataType.SelectedIndex, CheckBox_IsHex.Checked) && TextBox_ScanValue.Enabled == true ||
                !CheckSyntax.Value(ScanSecondValueTextBox.Text, (ScanDataType)ComboBox_DataType.SelectedIndex, CheckBox_IsHex.Checked) && ScanSecondValueTextBox.Visible == true)
            {
                MessageBox.Show("Invalid value format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            if (TextBox_ScanValue.Enabled == true)
            {
                ScanValue = Conversions.Conversions.ToUnsigned(TextBox_ScanValue.Text, SelectedScanType);
            }
            else
            {
                ScanValue = null;
            }

            if (ScanSecondValueTextBox.Visible == true)
            {
                SecondScanValue = Conversions.Conversions.ToUnsigned(ScanSecondValueTextBox.Text, SelectedScanType);
            }
            else
            {
                SecondScanValue = null;
            }
            #endregion

            #region Prescan events
            uint[] Protect      = new uint[8];
            int    CheckedItems = CheckedListBox_Protection.CheckedIndices.Count;
            for (int ecx = 0; ecx < CheckedItems; ecx++)
            {
                Protect[CheckedListBox_Protection.CheckedIndices[ecx]] = 1;
            }
            uint[] Type = new uint[3];
            CheckedItems = CheckedListBox_Type.CheckedIndices.Count;
            for (int ecx = 0; ecx < CheckedItems; ecx++)
            {
                Type[CheckedListBox_Type.CheckedIndices[ecx]] = 1;
            }

            ScanOptimizationData ScanOptimizationData = new ScanOptimizationData(CheckBox_OptimizeScan.Checked, (UInt64)NUD_OptimizeScan.Value, RadioButton_LastDigits.Checked);

            bool CompareToFirstScan = false;
            if (IsRescan && CheckBox_CompareToFirstCB.Checked == true)
            {
                CompareToFirstScan = true;
            }

            Scan = new ScanMemory(TargetProcess, FirstAddress, LastAddress, SelectedScanType,
                                  Conversions.Conversions.StringToScanType(ComboBox_CompareType.Items[ComboBox_CompareType.SelectedIndex].ToString()),
                                  ScanValue, SecondScanValue, Protect, Type, RadioButton_Truncated.Checked, ScanOptimizationData, ExecutablePath, CompareToFirstScan);

            Scan.ScanProgressChanged += new ScanMemory.ScanProgressedEventHandler(scan_ScanProgressChanged);
            Scan.ScanCompleted       += new ScanMemory.ScanCompletedEventHandler(scan_ScanCompleted);
            Scan.ScanCanceled        += new ScanMemory.ScanCanceledEventHandler(scan_ScanCanceled);

            ListView_Address.VirtualListSize = 0;
            ListView_Address.Items.Clear();

            if (CurrentAddressAccessor != null)
            {
                CurrentAddressAccessor.Dispose();
            }
            if (CurrentScanAddresses != null)
            {
                CurrentScanAddresses.Dispose();
            }

            ProgressBar.Value = 0;
            #endregion

            #region Start scan
            ScanTimeStopwatch = Stopwatch.StartNew();
            try
            {
                Scan.StartScan(IsRescan);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Scan.CancelScan();
                return(false);
            }
            return(true);

            #endregion
        }
예제 #23
0
        private void acceptButton_Click(object sender, EventArgs e)
        {
            string ValueString = ValueTextBox.Text;

            switch (ScanType)
            {
            case ScanDataType.Binary:
                if (CheckSyntax.BinaryValue(ValueString))
                {
                    Value = Conversions.ToUnsigned(ValueString, ScanType);
                }
                else
                {
                    failed = true;
                }
                break;

            case ScanDataType.Byte:
                //Check syntax
                if (CheckSyntax.ByteValue(ValueString, IsHexCB.Checked))
                {
                    if (!IsHexCB.Checked)
                    {
                        //Take unsigned value
                        Value = Conversions.ToUnsigned(ValueString, ScanType);
                    }
                    else     //Take unsigned value after converting it from hex
                    {
                        Value = Conversions.ToUnsigned(Conversions.HexToByte(ValueString).ToString(), ScanType);
                    }
                }
                else     //Invalid syntax
                {
                    failed = true;
                }
                break;

            case ScanDataType.Int16:
                if (CheckSyntax.Int32Value(ValueString, IsHexCB.Checked))
                {
                    if (!IsHexCB.Checked)
                    {
                        Value = Conversions.ToUnsigned(ValueString, ScanType);
                    }
                    else
                    {
                        Value = Conversions.ToUnsigned(Conversions.HexToShort(ValueString).ToString(), ScanType);
                    }
                }
                else
                {
                    failed = true;
                }
                break;

            case ScanDataType.Int32:
                if (CheckSyntax.Int32Value(ValueString, IsHexCB.Checked))
                {
                    if (!IsHexCB.Checked)
                    {
                        Value = Conversions.ToUnsigned(ValueString, ScanType);
                    }
                    else
                    {
                        Value = Conversions.ToUnsigned(Conversions.HexToInt(ValueString).ToString(), ScanType);
                    }
                }
                else
                {
                    failed = true;
                }
                break;

            case ScanDataType.Int64:
                if (CheckSyntax.Int64Value(ValueString, IsHexCB.Checked))
                {
                    if (!IsHexCB.Checked)
                    {
                        Value = Conversions.ToUnsigned(ValueString, ScanType);
                    }
                    else
                    {
                        Value = Conversions.ToUnsigned(Conversions.HexToUInt64(ValueString).ToString(), ScanType);
                    }
                }
                else
                {
                    failed = true;
                }
                break;

            case ScanDataType.Single:
                if (CheckSyntax.SingleValue(ValueString, IsHexCB.Checked))
                {
                    if (!IsHexCB.Checked)
                    {
                        Value = Conversions.ToUnsigned(ValueString, ScanType);
                    }
                    else
                    {
                        Value = Conversions.ToUnsigned(Conversions.HexToSingle(ValueString).ToString(), ScanType);
                    }
                }
                else
                {
                    failed = true;
                }
                break;

            case ScanDataType.Double:
                if (CheckSyntax.DoubleValue(ValueString, IsHexCB.Checked))
                {
                    if (!IsHexCB.Checked)
                    {
                        Value = Conversions.ToUnsigned(ValueString, ScanType);
                    }
                    else
                    {
                        Value = Conversions.ToUnsigned(Conversions.HexToDouble(ValueString).ToString(), ScanType);
                    }
                }
                else
                {
                    failed = true;
                }
                break;

            case ScanDataType.Text:
                //TODO: everything
                Value = ValueString;
                break;
            }

            if (failed)
            {
                MessageBox.Show("Invalid value format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #24
0
        private void acceptButton_Click(object sender, EventArgs e)
        {
            if (IsHexCB.Checked == true)
            {
                if (!CheckSyntax.Address(AddressTextBox.Text))
                {
                    MessageBox.Show("Invalid address format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                Address = AddressTextBox.Text;
            }
            else
            {
                if (!CheckSyntax.Int32Value(AddressTextBox.Text, false))
                {
                    MessageBox.Show("Invalid address format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                Address = Conversions.ToHex(AddressTextBox.Text);
            }


            if (DescriptionTextBox.Text == "")
            {
                Description = "No Description";
            }
            else
            {
                Description = DescriptionTextBox.Text;
            }

            switch (ValueTypeComboBox.SelectedIndex)
            {
            case 0:
                ScanType = ScanDataType.Binary;
                break;

            case 1:
                ScanType = ScanDataType.Byte;
                break;

            case 2:
                ScanType = ScanDataType.Int16;
                break;

            case 3:
                ScanType = ScanDataType.Int32;
                break;

            case 4:
                ScanType = ScanDataType.Int64;
                break;

            case 5:
                ScanType = ScanDataType.Single;
                break;

            case 6:
                ScanType = ScanDataType.Double;
                break;

            case 7:
                ScanType = ScanDataType.Text;
                break;

            case 8:
                ScanType = ScanDataType.AOB;
                break;

            case 9:
                ScanType = ScanDataType.All;
                break;
            }
            this.Close();
        }
예제 #25
0
 private void txtCheckNumber_KeyUp(object sender, KeyRoutedEventArgs e)
 {
     CheckSyntax.checkOnlyNumber(sender, e);
 }