void IViewTab.Fill(Protocol protocol, ViewerItem item) { ((IViewTab)this).Reset(); m_strings = ParsingHelper.ExtractStrings(protocol, item); m_binaryDatas = ParsingHelper.ExtractBinaryDatas(protocol, item); int nStrings = m_strings.Length; int count = nStrings + m_binaryDatas.Length; if (count > 0) { ui_cbDatas.Items.Clear(); for (int i = 0; i < count; i++) { var obj = i >= nStrings ? m_binaryDatas[i - nStrings].Item1 : m_strings[i].Item1; ui_cbDatas.Items.Add(ParsingHelper.GetContentName(obj, i)); } ui_cbDatas.SelectedIndex = 0; if (count > 1) ui_cbDatas.IsEnabled = true; //this.SelectData(0); } this.IsFilled = true; }
void IViewTab.Fill(Protocol protocol, ViewerItem item) { var header = protocol.PacketContentsViewHeader(item); if (header != null && header != string.Empty) ui_tbMain.Text = header + Environment.NewLine + item.Packet.Data.ToHexDump(); else ui_tbMain.Text = item.Packet.Data.ToHexDump(); this.IsFilled = true; }
void IViewTab.Fill(Protocol protocol, ViewerItem item) { var parser = item.Parser; if (parser == null) { protocol.CreateParser(item); parser = item.Parser; } if (!parser.IsParsed) parser.Parse(); ui_tbMain.Text = parser.ParsedText ?? string.Empty; this.IsFilled = true; }
void IViewTab.Fill(Protocol protocol, ViewerItem item) { ((IViewTab)this).Reset(); m_datas = ParsingHelper.ExtractBinaryDatas(protocol, item); int count = m_datas.Length; if (count > 0) { ui_cbDatas.Items.Clear(); for (int i = 0; i < count; i++) ui_cbDatas.Items.Add(ParsingHelper.GetContentName(m_datas[i].Item1, i)); ui_cbDatas.SelectedIndex = 0; if (count > 1) ui_cbDatas.IsEnabled = true; //this.SelectData(0); } this.IsFilled = true; }
internal void SetProtocol(Protocol value) { var old = m_currentProtocol; if (old == value) return; if (old != null && value != null && old.Wrapper == value.Wrapper) { Console.WriteLine("Error: Got same protocol {0}", value.Name); return; } this.StopParsing(); // We should allow the protocol to integrate with viewer in viewer's thread. m_window.ThreadSafe(_ => { if (old != null) old.Unload(); m_currentProtocol = value; if (value != null) value.Load(this); this.DropCache(); }); Console.WriteLine("Debug: Switching Protocol:{0} Old: {1}{2} New: {3}", Environment.NewLine, old != null ? old.Name : "null", Environment.NewLine, value != null ? value.Name : "null"); if (this.ProtocolChanged != null) this.ProtocolChanged(this, EventArgs.Empty); }
static PacketParser ParseIfNeed(Protocol protocol, ViewerItem item) { if (item == null) throw new ArgumentNullException("item"); if (protocol == null) throw new ArgumentNullException("protocol"); if (item.Parser == null) protocol.CreateParser(item); var parser = item.Parser; if (!parser.IsParsed) parser.Parse(); return parser; }
public static ValueTuple<object, byte[]>[] ExtractBinaryDatas(Protocol protocol, ViewerItem item, Encoding stringEncoding = null, Type imageEncoderType = null) { var parser = ParseIfNeed(protocol, item); ConstructorInfo ctor = null; object[] ctorArgs = null; if (imageEncoderType != null) { ctor = imageEncoderType.GetConstructor(BindingFlags.Public, null, new[] { typeof(Stream), typeof(BitmapCreateOptions), typeof(BitmapCacheOption) }, null); if (ctor == null) { ctor = imageEncoderType.GetConstructor(BindingFlags.Public, null, new[] { typeof(Stream) }, null); ctorArgs = new object[] { null, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default }; } else { ctorArgs = new object[] { null }; } if (ctor == null) throw new ArgumentException("imageEncoderType"); } var result = new List<ValueTuple<object, byte[]>>(parser.ContainedData.Count); foreach (var obj in parser.ContainedData) { var bytes = obj as byte[]; if (bytes != null) { result.Add(new ValueTuple<object, byte[]>(obj, bytes)); continue; } if (stringEncoding != null) { var str = obj as string; if (str != null) { try { result.Add(new ValueTuple<object, byte[]>(obj, stringEncoding.GetBytes(str))); } catch { } continue; } } if (imageEncoderType != null) { var img = obj as ImageSource; if (img != null) { try { using (var stream = new MemoryStream()) { ctorArgs[0] = stream; var encoder = (BitmapEncoder)ctor.Invoke(ctorArgs); encoder.Save(stream); result.Add(new ValueTuple<object, byte[]>(obj, stream.ToArray())); } } catch { } continue; } } // cannot interpret this } return result.ToArray(); }
public static ValueTuple<object, string>[] ExtractStrings(Protocol protocol, ViewerItem item, Encoding stringEncoding = null) { var parser = ParseIfNeed(protocol, item); var result = new List<ValueTuple<object, string>>(parser.ContainedData.Count); foreach (var obj in parser.ContainedData) { var str = obj as string; if (str != null) { result.Add(new ValueTuple<object, string>(obj, str)); continue; } var chars = obj as char[]; if (chars != null) { result.Add(new ValueTuple<object, string>(obj, new string(chars))); continue; } if (stringEncoding != null) { var bytes = obj as byte[]; if (bytes != null) { try { result.Add(new ValueTuple<object, string>(obj, stringEncoding.GetString(bytes))); continue; } catch { } } } // cannot interpret this } return result.ToArray(); }
public static ValueTuple<object, ImageSource>[] ExtractImages(Protocol protocol, ViewerItem item, bool convertImages = false) { var parser = ParseIfNeed(protocol, item); var result = new List<ValueTuple<object, ImageSource>>(parser.ContainedData.Count); foreach (var obj in parser.ContainedData) { var img = obj as ImageSource; if (img != null) { result.Add(new ValueTuple<object, ImageSource>(obj, img)); continue; } if (convertImages) { var bytes = obj as byte[]; if (bytes != null) { try { using (var stream = new MemoryStream(bytes)) { var decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); result.Add(new ValueTuple<object, ImageSource>(obj, decoder.Frames[0])); } } catch { } continue; } } // cannot interpret this } return result.ToArray(); }