private void LoadConfigPart_Data(XmlElement xml_node) { if (xml_node == null) { return; } var newobj = new SendFrameConfig(); /* === パラメータ読み込み === */ /* protocol_decoder_id */ newobj.ProtocolDecoderID = Guid.Parse(GetAttribute(xml_node, "protocol_decoder_id", "")); /* frame_type */ newobj.FrameType = UInt16.Parse(GetAttribute(xml_node, "frame_type", "0")); /* frame_bitdata */ newobj.FrameBitData = HexTextEncoder.ToBinary(GetAttribute(xml_node, "frame_bitdata", "")); /* frame_bitlength */ newobj.FrameBitLength = uint.Parse(GetAttribute(xml_node, "frame_bitlength", "0")); /* === 設定リストへ追加 === */ Value.Add(newobj); }
private void UpdateEditStatus(DataGridViewCell cell) { var error_text = ""; var cmd_target = TBox_CommonTarget.Text; /* エラー判定 */ switch ((ColumnId)cell.OwningColumn.Tag) { case ColumnId.SendData: { if (cell.Value is string value_str) { if (value_str.Length > 0) { if (HexTextEncoder.ToByteArray(value_str) != null) { cell.Style.BackColor = COLOR_COMMAND_FORMAT_OK; } else { cell.Style.BackColor = COLOR_COMMAND_FORMAT_NG; error_text = "Command incorrect"; } } } } break; default: break; } /* エラーテキストを設定 */ cell.ErrorText = error_text; }
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); }
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 }
public void ChangeDevice(GateProperty gatep, DeviceConfig devconf, Guid devc_id, DeviceProperty devp) { if (gatep != null) { gatep_ = gatep; } if (devconf != null) { devconf_ = devconf; } /* いずれかの状態が変化したらデバイスを再構築 */ if ((devi_ == null) || (devc_id != devi_.Class.ID) || (!ClassUtil.Compare(devi_.Config, devconf)) || (!ClassUtil.Compare(devi_.Property, devp)) ) { SetupDevice(DeviceManager.Instance.CreateDeviceObject(devconf, devc_id, devp)); } ApplyGateProperty(); /* 接続コマンドを再構築 */ connect_command_ = HexTextEncoder.ToByteArray(gatep_.ConnectCommand); }
public string DataToBitString(int offset, int size, string separator = "") { var raw_data = Data; if (raw_data == null) { return(""); } return(HexTextEncoder.ToBitText(raw_data, offset, size, separator)); }
public string DataToBitString(string separator = "") { var raw_data = Data; if (raw_data == null) { return(""); } return(HexTextEncoder.ToBitText(raw_data, 0, raw_data.Length, separator)); }
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(""); } }
private void UpdateLFCodeView() { /* 改行パターン取得 */ lf_code_ = HexTextEncoder.ToByteArray(TBox_LFCode.Text); /* 背景色設定 */ if (TBox_LFCode.Text.Length == 0) { TBox_LFCode.BackColor = Color.White; } else { TBox_LFCode.BackColor = (lf_code_ != null) ? (Color.SkyBlue) : (Color.Pink); } }
private void UpdateConnectCommand() { var exp = TBox_ConnectCommand.Text; if (exp.Length > 0) { TBox_ConnectCommand.BackColor = (HexTextEncoder.ToByteArray(exp) != null) ? (Ratatoskr.Resource.AppColors.Ok) : (Ratatoskr.Resource.AppColors.Ng); } else { TBox_ConnectCommand.BackColor = Color.White; } }
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)); } }
private void UpdateView() { var text = TBox_Value.Text; TBox_Value.ForeColor = (text == Property.DataContentsMatchProperty.Pattern.Value) ? (Color.Black) : (Color.Gray); if (text.Length > 0) { TBox_Value.BackColor = (HexTextEncoder.ToByteArray(TBox_Value.Text) != null) ? (Ratatoskr.Resource.AppColors.Ok) : (Ratatoskr.Resource.AppColors.Ng); } else { TBox_Value.BackColor = Color.White; } }
private PatternMatchObject[] CreateMatchObjects(string pattern) { /* パターンコードからパターン一覧を作成 */ var patterns = HexTextEncoder.ToByteArrayMap(pattern); if (patterns == null) { return(null); } /* マッチオブジェクトに変換 */ var match_objs = new List <PatternMatchObject>(); foreach (var pattern_data in patterns) { match_objs.Add(new PatternMatchObject(pattern_data)); } return(match_objs.ToArray()); }
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); }
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 }
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); }
private void LoadConfigPart_Data(XmlElement xml_node) { if (xml_node == null) { return; } var newobj = new PacketObjectConfig(); /* === パラメータ読み込み === */ /* protocol-name */ newobj.ProtocolName = GetAttribute(xml_node, "protocol-name", ""); /* bit-data */ newobj.BitData = HexTextEncoder.ToByteArray(GetAttribute(xml_node, "bit-data", "")); /* bit-size */ newobj.BitSize = uint.Parse(GetAttribute(xml_node, "bit-size", "")); /* === 設定リストへ追加 === */ Value.Add(newobj); }
private void UpdateExpListView() { send_data_exp_ = CBox_ExpList.Text; if (send_data_exp_.Length > 0) { #if BINARY_CODE_PARSER send_data_bin_ = BinaryTextCompiler.Build(send_data_exp_); #else send_data_bin_ = HexTextEncoder.ToByteArray(send_data_exp_); #endif CBox_ExpList.BackColor = (send_data_bin_ != null) ? (Ratatoskr.Resource.AppColors.Ok) : (Ratatoskr.Resource.AppColors.Ng); } else { send_data_bin_ = null; CBox_ExpList.BackColor = Color.White; } }
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, " ")); }
private void UpdateView() { /* 表示中の変換式をコンパイル */ target_codes_exp_new_ = TBox_Target.Text; target_codes_obj_new_ = HexTextEncoder.ToByteArrayMap(target_codes_exp_new_); replace_code_exp_new_ = TBox_Replace.Text; replace_code_obj_new_ = HexTextEncoder.ToByteArray(replace_code_exp_new_); /* 表示更新 */ if (target_codes_exp_new_.Length > 0) { TBox_Target.BackColor = (target_codes_obj_new_ != null) ? (Ratatoskr.Resource.AppColors.Ok) : (Ratatoskr.Resource.AppColors.Ng); } else { TBox_Target.BackColor = Color.White; } if (replace_code_exp_new_.Length > 0) { TBox_Replace.BackColor = (replace_code_obj_new_ != null) ? (Ratatoskr.Resource.AppColors.Ok) : (Ratatoskr.Resource.AppColors.Ng); } else { TBox_Replace.BackColor = Color.White; } /* 変更状態確認 */ TBox_Target.ForeColor = (target_codes_exp_busy_ != target_codes_exp_new_) ? (Color.Gray) : (Color.Black); TBox_Replace.ForeColor = (replace_code_exp_busy_ != replace_code_exp_new_) ? (Color.Gray) : (Color.Black); }
public Term_Binary(string text) { value_ = HexTextEncoder.ToByteArray(text); }
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); }
private PacketObject ReadContentsRecord(FileFormatOptionImpl option, string[] items) { try { /* 要素解析 */ var item = (string)null; var class_n = "Csv"; var fac = PacketFacility.Device; var alias = ""; var prio = PacketPriority.Standard; var attr = PacketAttribute.Data; var mt = DateTime.UtcNow; var info = ""; var dir = PacketDirection.Recv; var src = ""; var dst = ""; var mark = (byte)0; var message = (string)null; var data_s = ""; var data = (byte[])null; foreach (var(order_value, order_index) in option.ItemOrder.Select((v, i) => (v, i))) { item = items[order_index].TrimEnd(); switch (order_value) { case PacketElementID.Class: { class_n = item; } break; case PacketElementID.Facility: { fac = (PacketFacility)Enum.Parse(typeof(PacketFacility), item); } break; case PacketElementID.Alias: { alias = item; } break; case PacketElementID.Priority: { prio = (PacketPriority)Enum.Parse(typeof(PacketPriority), item); } break; case PacketElementID.Attribute: { attr = (PacketAttribute)Enum.Parse(typeof(PacketAttribute), item); } break; case PacketElementID.DateTime_UTC_Display: { mt = DateTime.ParseExact(item, PacketObject.DATETIME_FORMAT_UTC_DISPLAY, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal); } break; case PacketElementID.DateTime_Local_Display: { mt = DateTime.ParseExact(item, PacketObject.DATETIME_FORMAT_LOCAL_DISPLAY, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeLocal); } break; case PacketElementID.Information: { info = item; } break; case PacketElementID.Direction: { dir = (PacketDirection)Enum.Parse(typeof(PacketDirection), item); } break; case PacketElementID.Source: { src = item; } break; case PacketElementID.Destination: { dst = item; } break; case PacketElementID.Mark: { mark = byte.Parse(item); } break; case PacketElementID.Message: { message = item; } break; case PacketElementID.Data_HexString: { data_s = item; } break; } } /* パケット生成 */ switch (attr) { case PacketAttribute.Message: { if (message == null) { message = data_s; } } break; case PacketAttribute.Data: { data = HexTextEncoder.ToByteArray(data_s); } break; default: break; } return(new PacketObject(class_n, fac, alias, prio, attr, mt, info, dir, src, dst, mark, message, data)); } catch { return(null); } }
public override string ToString() { return(HexTextEncoder.ToHexText(GetBytes())); }
public BinaryTextData(string hex_string) { data_buffer_ = HexTextEncoder.ToBinary(hex_string); data_size_ = data_buffer_.Length; }