Esempio n. 1
0
        public string DataToHexString(string separator = "")
        {
            var raw_data = Data;

            if (raw_data == null)
            {
                return("");
            }

#if CONVERT_CACHE_ENABLE
            var raw_data_text = (string)null;

            if ((separator.Length == 0) && (cache_ != null))
            {
                raw_data_text = cache_.DataToHexString_NoDiv;
            }

            if (raw_data_text == null)
            {
                raw_data_text = HexTextEncoder.ToHexText(raw_data, 0, raw_data.Length, separator);
            }

            if ((separator.Length == 0) && (cache_ != null))
            {
                cache_.DataToHexString_NoDiv = raw_data_text;
            }

            return(raw_data_text);
#else
            return(HexTextEncoder.ToHexText(raw_data, 0, raw_data.Length, separator));
#endif
        }
Esempio n. 2
0
        public bool SaveConfigData(XmlElement xml_own)
        {
            foreach (var info in Value)
            {
                var xml_data = xml_own.OwnerDocument.CreateElement(XML_NODE_DATA);

                /* === パラメータ書き込み === */
                /* protocol_decoder_id */
                xml_data.SetAttribute("protocol_decoder_id", info.ProtocolDecoderID.ToString("D"));

                /* frame_type */
                xml_data.SetAttribute("frame_type", info.FrameType.ToString());

                /* frame_bitdata */
                xml_data.SetAttribute("frame_bitdata", HexTextEncoder.ToHexText(info.FrameBitData));

                /* frame_bitlength */
                xml_data.SetAttribute("frame_bitlength", info.FrameBitLength.ToString());

                /* === ノード追加 === */
                xml_own.AppendChild(xml_data);
            }

            return(true);
        }
Esempio n. 3
0
        private string GetPacketListItemText(PacketObjectConfig config, ListViewDataType type)
        {
            switch (type)
            {
            case ListViewDataType.Protocol:     return(config.ProtocolName);

            case ListViewDataType.BitData:      return(HexTextEncoder.ToHexText(config.BitData));

            case ListViewDataType.BitSize:      return(config.BitSize.ToString());

            default:                            return("");
            }
        }
Esempio n. 4
0
        public string DataToHexString(int offset, int size, string separator = "")
        {
            var raw_data = Data;

            if (raw_data == null)
            {
                return("");
            }

            if ((offset == 0) && (size >= raw_data.Length))
            {
                return(DataToHexString(separator));
            }
            else
            {
                return(HexTextEncoder.ToHexText(raw_data, offset, size, separator));
            }
        }
Esempio n. 5
0
        private ProtocolParseInfo.InformationObject ParsePacketDetails_Ethernet(EthernetPacket packet)
        {
            var info = new ProtocolParseInfo.InformationObject("Ethernet");

            /* MAC - Destination */
            info.Add(string.Format("DstMAC: {0}", packet.DestinationHardwareAddress.ToString()));

            /* MAC - Source */
            info.Add(string.Format("SrcMAC: {0}", packet.SourceHardwareAddress.ToString()));

            /* EtherType */
            info.Add(string.Format("EtherType: {0}({1:X4})", packet.Type, (uint)packet.Type));

            /* Payload */
            if (packet.HasPayloadData)
            {
                info.Add(string.Format("Data: {0}", HexTextEncoder.ToHexText(packet.PayloadData)));
            }

            return(info);
        }
Esempio n. 6
0
        private void UpdatePreviewWindow()
        {
            var visible = (ChkBox_Preview.Checked && CBox_ExpList.Focused);

#if true
            if (preview_label_.Visible != visible)
            {
                preview_label_.Visible = visible;
            }

            if (visible)
            {
                var view_pos = CBox_ExpList.PointToScreen(Point.Empty);

                view_pos.X += PREVIEW_DISP_MARGIN.X;
                view_pos.Y += PREVIEW_DISP_MARGIN.Y - preview_label_.Height;

                preview_label_.Location = view_pos;

                var view_str  = new StringBuilder();
                var view_data = (send_data_bin_ != null) ? (HexTextEncoder.ToHexText(send_data_bin_, " ")) : ("");

                view_str.AppendLine(string.Format("<Data Preview> size = {0} bytes", (send_data_bin_ != null) ? (send_data_bin_.Length) : (0)));
                view_str.AppendLine((send_data_bin_ != null) ? (HexTextEncoder.ToHexText(send_data_bin_, " ")) : ("Format error."));

                preview_label_.Label_Text = view_str.ToString();
            }
#endif
#if false
            if (visible)
            {
                ttip_preview_.SetToolTip(CBox_ExpList, HexTextEncoder.ToHexText(send_data_bin_));
                ttip_preview_.Active = true;
            }
            else
            {
                ttip_preview_.Active = false;
            }
#endif
        }
Esempio n. 7
0
        public bool SaveConfigData(XmlElement xml_own)
        {
            foreach (var info in Value)
            {
                var xml_data = xml_own.OwnerDocument.CreateElement(XML_NODE_DATA);

                /* === パラメータ書き込み === */
                /* protocol-name */
                xml_data.SetAttribute("protocol-name", info.ProtocolName);

                /* bit-data */
                xml_data.SetAttribute("bit-data", HexTextEncoder.ToHexText(info.BitData));

                /* bit-size */
                xml_data.SetAttribute("bit-size", info.BitSize.ToString());

                /* === ノード追加 === */
                xml_own.AppendChild(xml_data);
            }

            return(true);
        }
Esempio n. 8
0
        private void MenuAct_Copy_Hex(object sender, EventArgs e)
        {
            if (select_addr_top_ < 0)
            {
                return;
            }
            if (select_addr_end_ < 0)
            {
                return;
            }

            var data = DataPickUp(select_addr_top_, select_addr_end_ - select_addr_top_ + 1);

            if (data == null)
            {
                return;
            }
            if (data.Length == 0)
            {
                return;
            }

            Clipboard.SetData(DataFormats.Text, HexTextEncoder.ToHexText(data, " "));
        }
Esempio n. 9
0
 public override string ToString()
 {
     return(HexTextEncoder.ToHexText(GetBytes()));
 }
Esempio n. 10
0
        public string GetFormatString(string pattern)
        {
            var blocks = pattern.Split(':');

            /* 引数取得 */
            var format = "HEXTEXT";
            var type   = "BYTE";
            var offset = 0;
            var size   = int.MaxValue;

            if ((blocks.Length > (int)FormatArgument.Format) && (blocks[(int)FormatArgument.Format].Length > 0))
            {
                format = blocks[(int)FormatArgument.Format];
            }

            if ((blocks.Length > (int)FormatArgument.Type) && (blocks[(int)FormatArgument.Type].Length > 0))
            {
                type = blocks[(int)FormatArgument.Type];
            }

            if ((blocks.Length > (int)FormatArgument.Offset) && (blocks[(int)FormatArgument.Offset].Length > 0))
            {
                try { offset = int.Parse(blocks[(int)FormatArgument.Offset]); } catch {}
            }

            if ((blocks.Length > (int)FormatArgument.Size) && (blocks[(int)FormatArgument.Size].Length > 0))
            {
                try { size = int.Parse(blocks[(int)FormatArgument.Size]); } catch {}
            }

            /* データ取得 */
            var data = (byte[])null;

            switch (type.ToUpper())
            {
            case "BYTE":     data = GetBytes(offset, size);                                break;

            case "BIT":      data = GetBits(offset, size);                                 break;

            case "ASCII":    data = TextToData(Encoding.ASCII, offset, size);              break;

            case "UTF8":     data = TextToData(Encoding.UTF8, offset, size);               break;

            case "UTF16BE":  data = TextToData(Encoding.BigEndianUnicode, offset, size);   break;

            case "UTF16LE":  data = TextToData(Encoding.Unicode, offset, size);            break;

            case "SHIFTJIS": data = TextToData(Encoding.GetEncoding(932), offset, size);   break;

            case "EUCJP":    data = TextToData(Encoding.GetEncoding(20932), offset, size); break;

            default:         return(pattern);
            }

            /* データ変換 */
            var result = "";

            switch (format.ToUpper())
            {
            case "HEXTEXT":   result = HexTextEncoder.ToHexText(data);                   break;

            case "BITTEXT":   result = HexTextEncoder.ToBitText(data);                   break;

            case "ASCII":     result = Encoding.UTF8.GetString(data);                    break;

            case "UTF8":      result = Encoding.UTF8.GetString(data);                    break;

            case "UTF16BE":   result = Encoding.BigEndianUnicode.GetString(data);        break;

            case "UTF16LE":   result = Encoding.Unicode.GetString(data);                 break;

            case "SHIFTJIS":  result = Encoding.GetEncoding(932).GetString(data);        break;

            case "EUCJP":     result = Encoding.GetEncoding(20932).GetString(data);      break;

            case "INT8":      result = StructEncoder.ToSByte(data).ToString();           break;

            case "UINT8":     result = StructEncoder.ToByte(data).ToString();            break;

            case "INT16LE":   result = StructEncoder.ToInt16(data, true).ToString();     break;

            case "INT32LE":   result = StructEncoder.ToInt32(data, true).ToString();     break;

            case "INT64LE":   result = StructEncoder.ToInt64(data, true).ToString();     break;

            case "UINT16LE":  result = StructEncoder.ToUInt16(data, true).ToString();    break;

            case "UINT32LE":  result = StructEncoder.ToUInt32(data, true).ToString();    break;

            case "UINT64LE":  result = StructEncoder.ToUInt64(data, true).ToString();    break;

            case "INT16BE":   result = StructEncoder.ToInt16(data, false).ToString();    break;

            case "INT32BE":   result = StructEncoder.ToInt32(data, false).ToString();    break;

            case "INT64BE":   result = StructEncoder.ToInt64(data, false).ToString();    break;

            case "UINT16BE":  result = StructEncoder.ToUInt16(data, false).ToString();   break;

            case "UINT32BE":  result = StructEncoder.ToUInt32(data, false).ToString();   break;

            case "UINT64BE":  result = StructEncoder.ToUInt64(data, false).ToString();   break;

            default:          return(pattern);
            }

            return(result);
        }