private void PacketListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (PacketListView.SelectedIndex == -1) { return; } var item = (PacketEntry)PacketListView.Items[PacketListView.SelectedIndex]; var data = item.Data; if (Properties.Settings.Default.HideHexBoxActorId) { byte[] noIdData = new byte[data.Length]; Array.Copy(data, 0, noIdData, 0, 3); Array.Copy(data, 12, noIdData, 12, data.Length - 12); data = noIdData; } _currentPacketStream = new MemoryStream(data); try { HexEditor.ByteProvider = new DynamicByteProvider(data); } catch (Exception exception) { new ExtendedErrorView("Failed to load packet.", exception.ToString(), "Error").ShowDialog(); } StructListView.Items.Clear(); try { if (item.Direction == "S") { var structText = _db.GetServerZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)); if (structText == null) { StructListItem infoItem = new StructListItem(); infoItem.NameCol = "No Struct found"; StructListView.Items.Add(infoItem); return; } var structProvider = new Struct(); var structEntries = structProvider.Parse(structText, item.Data); var colours = Struct.TypeColours; var i = 0; foreach (var entry in structEntries.Item1) { System.Drawing.Color colour; if (!colours.TryGetValue(string.IsNullOrEmpty(entry.DataTypeCol) ? "unknown" : entry.DataTypeCol, out colour)) { colour = System.Drawing.Color.White; } StructListView.Items.Add(entry); HexEditor.HighlightBytes(entry.offset, entry.typeLength, System.Drawing.Color.Black, colour); } if (_mainWindow.ShowObjectMapCheckBox.IsChecked) { new ExtendedErrorView("Object map for " + item.Name, structEntries.Item2.Print(), "FFXIVMon Reborn").ShowDialog(); } } else { StructListItem infoItem = new StructListItem(); infoItem.NameCol = "Client Packet"; StructListView.Items.Add(infoItem); return; } } catch (Exception exc) { new ExtendedErrorView($"[XivMonTab] Struct error! Could not get struct for {item.Name} - {item.Message}", exc.ToString(), "Error").ShowDialog(); } UpdateInfoLabel(); }
public void Apply(byte[] data, int offset) { Reset(); foreach (var type in _structs) { StructListItem thisItem = new StructListItem(); thisItem.DataTypeCol = type.DataTypeCol; thisItem.ValueCol = type.ValueCol; if (offset <= data.Length && data.Length - offset >= type.typeLength) { thisItem.OffsetCol = offset.ToString("X"); try { if (thisItem.DataTypeCol == "int8_t") { thisItem.ValueCol = String.Format("{0}", Convert.ToSByte(data[offset])); } else if (thisItem.DataTypeCol == "uint8_t") { thisItem.ValueCol = String.Format("{0}", data[offset].ToString()); } else if (thisItem.DataTypeCol == "int16_t") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToInt16(data, offset)); } else if (thisItem.DataTypeCol == "uint16_t") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToUInt16(data, offset)); } else if (thisItem.DataTypeCol == "int32_t") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToInt32(data, offset)); } else if (thisItem.DataTypeCol == "uint32_t") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToUInt32(data, offset)); } else if (thisItem.DataTypeCol == "int64_t") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToInt64(data, offset)); } else if (thisItem.DataTypeCol == "uint64_t") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToUInt64(data, offset)); } else if (thisItem.DataTypeCol == "float") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToSingle(data, offset)); } else if (thisItem.DataTypeCol == "double") { thisItem.ValueCol = String.Format("{0}", BitConverter.ToDouble(data, offset)); } else if (thisItem.DataTypeCol == "time_t") { thisItem.ValueCol = String.Format("{0}", DateTimeOffset.FromUnixTimeSeconds(BitConverter.ToUInt32(data, offset)).ToLocalTime()); } else if (thisItem.DataTypeCol == "string (ascii)") { var str = Encoding.ASCII.GetString(data); var terminatorOffset = str.IndexOf((char)0, offset); thisItem.ValueCol = str.Substring(offset, terminatorOffset - offset); } else if (thisItem.DataTypeCol == "string (utf8)") { var str = Encoding.UTF8.GetString(data); var terminatorOffset = str.IndexOf((char)0, offset); thisItem.ValueCol = str.Substring(offset, terminatorOffset - offset); } else if (thisItem.DataTypeCol == "binary") { var str = ""; var j = 0; for (var i = offset; i < data.Length; ++i, ++j) { str += Convert.ToString(data[i], 2).PadLeft(8, '0') + ((j + 1) % 2 == 0 ? Environment.NewLine : " "); // stop at 8 bytes if (j == 7 || (i + 1 < data.Length && data[i + 1] == 0)) { break; } } thisItem.ValueCol = str; } } catch (OverflowException) { thisItem.ValueCol = String.Format("{0}", Convert.ToSByte(127 - data[offset])); } catch (ArgumentOutOfRangeException e) { } catch (Exception exc) { //new ExtendedErrorView("Failed to update DataTypeView component.", exc.ToString(), "Error").ShowDialog(); } } DataTypeListView.Items.Add(thisItem); } }
private void PacketListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (PacketListView.SelectedIndex == -1) { return; } var item = (PacketEntry)PacketListView.Items[PacketListView.SelectedIndex]; var data = item.Data; if (Properties.Settings.Default.HideHexBoxActorId) { byte[] noIdData = new byte[data.Length]; Array.Copy(data, 0, noIdData, 0, 3); Array.Copy(data, 12, noIdData, 12, data.Length - 12); data = noIdData; } _currentPacketStream = new MemoryStream(data); try { HexEditor.ByteProvider = new DynamicByteProvider(data); } catch (Exception exception) { new ExtendedErrorView("Failed to load packet.", exception.ToString(), "Error").ShowDialog(); } StructListView.Items.Clear(); try { string structText = null; structText = item.Direction == "S" ? _db.GetServerZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)) : _db.GetClientZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)); if (structText == null) { StructListItem infoItem = new StructListItem { NameCol = "No Struct found" }; StructListView.Items.Add(infoItem); return; } var structProvider = new Struct(); var structEntries = structProvider.Parse(structText, item.Data); var colours = Struct.TypeColours; int i = 0; // Highlight the IPC header lightly grey HexEditor.HighlightBytes(0, 0x20, System.Drawing.Color.Black, System.Drawing.Color.LightGray); foreach (var entry in structEntries.Item1) { System.Drawing.Color colour = Struct.TypeColours.ElementAt(i).Value; StructListView.Items.Add(entry); HexEditor.HighlightBytes(entry.offset, entry.typeLength, System.Drawing.Color.Black, colour); ++i; if (i == colours.Count) { i = 1; } } if (_mainWindow.ShowObjectMapCheckBox.IsChecked) { new ExtendedErrorView("Object map for " + item.Name, structEntries.Item2.Print(), "FFXIVMon Reborn").ShowDialog(); } } catch (Exception exc) { #if !DEBUG if (_erroredOpcodes.Contains(item.Message)) { #endif new ExtendedErrorView($"Struct error! Could not get struct for {item.Name} - {item.Message}", exc.ToString(), "Error").ShowDialog(); #if !DEBUG _erroredOpcodes.Add(item.Message); } #endif StructListItem infoItem = new StructListItem { NameCol = "Parsing failed" } ; StructListView.Items.Add(infoItem); return; } UpdateInfoLabel(); }