Exemple #1
0
        void PacketList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (PacketList.SelectedIndex == -1)
            {
                return;
            }
            HexBox.Document.Blocks.Clear();
            ArcheAgePacket packet  = m_Packets[PacketList.SelectedIndex];
            StringBuilder  builder = new StringBuilder();
            int            offset  = 0;

            if (packet.direction.Equals("[GP]"))
            {
                offset += 4;
            }
            else
            {
                offset += 2;
            }
            for (int i = offset; i < packet.data.Length; i++)
            {
                builder.AppendFormat("{0:X2} ", packet.data[i]);
            }
            HexBox.AppendText(builder.ToString());
            HighlightTextAndShowParts(packet);
            PacketsCurrent.Content = "Текущий: " + PacketList.SelectedIndex;
            if (packet.isDefined && !packet.name.Contains("Undefined Packet"))
            {
                DefinePacket.Content = "Изменить";
            }
            else
            {
                DefinePacket.Content = "Определить";
            }
        }
Exemple #2
0
        private void DefinePacket_Click(object sender, RoutedEventArgs e)
        {
            if (PacketList.SelectedIndex == -1)
            {
                PacketList.SelectedIndex = 0;
            }
            DefinePacket   packet = new DefinePacket();
            ArcheAgePacket p      = m_Packets[PacketList.SelectedIndex];

            if (!p.direction.Equals("[GP]"))
            {
                packet.m_PacketId = "0x" + BitConverter.ToInt16(p.data, 0).ToString("X2");
            }
            else
            {
                packet.m_PacketId = "0x" + BitConverter.ToInt16(p.data, 2).ToString("X2");
            }
            packet.m_PacketType = p.type;
            packet.m_Direction  = p.direction;
            packet.m_Level      = p.PacketLevel;
            packet.Show();
            packet = null;
        }
Exemple #3
0
        void HighlightTextAndShowParts(ArcheAgePacket packet)
        {
            PartView.Items.Clear();
            int          m_GeneralOffset  = 0;
            TextPointer  m_DocStart       = HexBox.Document.ContentStart;
            PacketReader reader           = new PacketReader(packet.data, 0);
            bool         m_BreakExtremely = false;
            TreeViewItem m_Header         = new TreeViewItem();

            if (packet.direction.Equals("[GP]"))
            {
                m_Header.Header = "Packet - Level: " + packet.data[1] + " Opcode: 0x" + BitConverter.ToInt16(packet.data, 2).ToString("X2") + " Undefined: 0x" + packet.data[0].ToString("X2");
                reader.Offset  += 4;
            }
            else
            {
                m_Header.Header = "Packet - Opcode 0x" + BitConverter.ToInt16(packet.data, 0).ToString("X2");
                reader.Offset  += 2;
            }

            if (packet.parts != null)
            {
                foreach (PacketPart part in packet.parts)
                {
                    if (m_BreakExtremely)
                    {
                        break;
                    }
                    dynamic value = null;
                    if (part.Type == PartType.None)
                    {
                        MessageBox.Show("Part Type Cannot Be Null - Packet [" + packet.name + "]");
                        Environment.Exit(0);
                        break;
                    }
                    if (part.Type == PartType.ByteArray)
                    {
                        value = "Byte[]: " + part.ByteArrayLength;
                        reader.ReadByteArray(part.ByteArrayLength);
                    }
                    if (value == null)
                    {
                        value = ReadDynamicValue(part.Type, reader);
                    }
                    bool m_BeenAtArray = false;
                    if (part.ArrayId != null && !part.ArrayId.Equals("0"))
                    {
                        //Read As Array.
                        PacketArray m_CurrentArray = packet.arrays.FirstOrDefault(n => n.ArrayId == part.ArrayId);
                        if (m_CurrentArray == null)
                        {
                            continue;
                        }
                        if (value is string)
                        {
                            continue;
                        }

                        bool         m_BreakCurrentIteration = false;
                        TreeViewItem i = new TreeViewItem();
                        i.Header = "Iterations";
                        for (int iterations = 0; iterations < (int)value; iterations++)
                        {
                            if (reader.Offset > reader.Size)
                            {
                                PartView.Items.Clear();
                                m_BreakExtremely = true;
                                MessageBox.Show("Specified Position More Than Data Length");
                                break;
                            }
                            TreeViewItem m_CurrentIteration = new TreeViewItem();
                            m_CurrentIteration.Header = "Iteration #" + iterations;
                            foreach (PacketPart p2 in m_CurrentArray.parts)
                            {
                                dynamic m_Dynamic = null;
                                if (p2.Type == PartType.ByteArray)
                                {
                                    m_Dynamic = "Byte[]: " + reader.ReadByteArray(part.ByteArrayLength).Length;
                                }
                                if (m_Dynamic == null)
                                {
                                    m_Dynamic = ReadDynamicValue(p2.Type, reader);
                                }
                                int   m_StringOffset   = 0;
                                Color m_ByteArrayColor = Colors.White;
                                if (m_Dynamic is string)
                                {
                                    if (((string)m_Dynamic).StartsWith("Byte[]"))
                                    {
                                        m_StringOffset   = part.ByteArrayLength;
                                        m_ByteArrayColor = Colors.MistyRose;
                                    }
                                    else
                                    {
                                        m_StringOffset = ((string)m_Dynamic).Length;
                                        if (p2.Type == PartType.FixedString)
                                        {
                                            m_StringOffset += 2;
                                        }
                                    }
                                }
                                HighlighterObject m_SecondHighlighter = m_StringOffset != 0 ? new HighlighterObject(m_StringOffset, m_ByteArrayColor != Colors.White ? m_ByteArrayColor : Colors.Purple) : GetNativeHighlighter(p2.Type.ToString());
                                TextRange         range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += (m_SecondHighlighter.offset * 3 + 1)));
                                range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(m_SecondHighlighter.color));
                                m_CurrentIteration.Items.Add("Segment " + p2.Name + " (" + p2.Type.ToString() + ") - Value: " + m_Dynamic);
                                m_SecondHighlighter = null;
                                range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += 3));
                                range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.White));
                                range = null;
                            }
                            i.Items.Add(m_CurrentIteration);
                            if (m_BreakCurrentIteration)
                            {
                                break;
                            }
                        }
                        m_Header.Items.Add(i);
                        m_BeenAtArray = true;
                    }

                    int   m_String       = 0;
                    Color bytearrayColor = Colors.White;
                    if (value is string)
                    {
                        if (((string)value).StartsWith("Byte[]"))
                        {
                            m_String       = part.ByteArrayLength;
                            bytearrayColor = Colors.MistyRose;
                        }
                        else
                        {
                            m_String = ((string)value).Length;
                            if (part.Type == PartType.FixedString)
                            {
                                m_String += 2;
                            }
                        }
                    }

                    HighlighterObject highlighter = m_String != 0 ? new HighlighterObject(m_String, bytearrayColor != Colors.White ? bytearrayColor : Colors.Purple) : GetNativeHighlighter(part.Type.ToString());
                    TextRange         h_Range     = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += (highlighter.offset * 3 + 1)));
                    h_Range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(highlighter.color));
                    if (!m_BeenAtArray)
                    {
                        m_Header.Items.Add("Segment " + part.Name + " (" + part.Type.ToString() + ") - Value: " + value);
                    }
                    h_Range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += 3));
                    h_Range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.White));
                    h_Range = null;
                }
            }
            PartView.Items.Add(m_Header);
            reader = null;
        }
Exemple #4
0
        void HighlightTextAndShowParts(ArcheAgePacket packet)
        {
            PartView.Items.Clear();
            int m_GeneralOffset = 0;
            TextPointer m_DocStart = HexBox.Document.ContentStart;
            PacketReader reader = new PacketReader(packet.data, 0);
            bool m_BreakExtremely = false;
            TreeViewItem m_Header = new TreeViewItem();
            if (packet.direction.Equals("[GP]"))
            {
                m_Header.Header = "Packet - Level: " + packet.data[1] + " Opcode: 0x" + BitConverter.ToInt16(packet.data, 2).ToString("X2") + " Undefined: 0x" + packet.data[0].ToString("X2");
                reader.Offset += 4;
            }
            else
            {
                m_Header.Header = "Packet - Opcode 0x" + BitConverter.ToInt16(packet.data, 0).ToString("X2");
                reader.Offset += 2;
            }

            if (packet.parts != null)
            {
                foreach (PacketPart part in packet.parts)
                {
                    if (m_BreakExtremely)
                        break;
                    dynamic value = null;
                    if (part.Type == PartType.None)
                    {
                        MessageBox.Show("Part Type Cannot Be Null - Packet [" + packet.name + "]");
                        Environment.Exit(0);
                        break;
                    }
                    if (part.Type == PartType.ByteArray)
                    {
                        value = "Byte[]: " + part.ByteArrayLength;
                        reader.ReadByteArray(part.ByteArrayLength);
                    }
                    if (value == null)
                        value = ReadDynamicValue(part.Type, reader);
                    bool m_BeenAtArray = false;
                    if (part.ArrayId != null && !part.ArrayId.Equals("0"))
                    {
                        //Read As Array.
                        PacketArray m_CurrentArray = packet.arrays.FirstOrDefault(n => n.ArrayId == part.ArrayId);
                        if (m_CurrentArray == null)
                            continue;
                        if (value is string)
                            continue;

                        bool m_BreakCurrentIteration = false;
                        TreeViewItem i = new TreeViewItem();
                        i.Header = "Iterations";
                        for (int iterations = 0; iterations < (int)value; iterations++)
                        {
                            if (reader.Offset > reader.Size)
                            {
                                PartView.Items.Clear();
                                m_BreakExtremely = true;
                                MessageBox.Show("Specified Position More Than Data Length");
                                break;
                            }
                            TreeViewItem m_CurrentIteration = new TreeViewItem();
                            m_CurrentIteration.Header = "Iteration #" + iterations;
                            foreach (PacketPart p2 in m_CurrentArray.parts)
                            {
                                dynamic m_Dynamic = null;
                                if (p2.Type == PartType.ByteArray)
                                {
                                    m_Dynamic = "Byte[]: " + reader.ReadByteArray(part.ByteArrayLength).Length;
                                }
                                if (m_Dynamic == null)
                                    m_Dynamic = ReadDynamicValue(p2.Type, reader);
                                int m_StringOffset = 0;
                                Color m_ByteArrayColor = Colors.White;
                                if (m_Dynamic is string)
                                {
                                    if (((string)m_Dynamic).StartsWith("Byte[]"))
                                    {
                                        m_StringOffset = part.ByteArrayLength;
                                        m_ByteArrayColor = Colors.MistyRose;
                                    }
                                    else
                                    {
                                        m_StringOffset = ((string)m_Dynamic).Length;
                                        if (p2.Type == PartType.FixedString)
                                            m_StringOffset += 2;
                                    }
                                }
                                HighlighterObject m_SecondHighlighter = m_StringOffset != 0 ? new HighlighterObject(m_StringOffset, m_ByteArrayColor != Colors.White ? m_ByteArrayColor : Colors.Purple) : GetNativeHighlighter(p2.Type.ToString());
                                TextRange range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += (m_SecondHighlighter.offset * 3 + 1)));
                                range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(m_SecondHighlighter.color));
                                m_CurrentIteration.Items.Add("Segment " + p2.Name + " (" + p2.Type.ToString() + ") - Value: " + m_Dynamic);
                                m_SecondHighlighter = null;
                                range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += 3));
                                range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.White));
                                range = null;
                            }
                            i.Items.Add(m_CurrentIteration);
                            if (m_BreakCurrentIteration)
                                break;
                        }
                        m_Header.Items.Add(i);
                        m_BeenAtArray = true;
                    }

                    int m_String = 0;
                    Color bytearrayColor = Colors.White;
                    if (value is string)
                    {
                        if (((string)value).StartsWith("Byte[]"))
                        {
                            m_String = part.ByteArrayLength;
                            bytearrayColor = Colors.MistyRose;
                        }
                        else
                        {
                            m_String = ((string)value).Length;
                            if (part.Type == PartType.FixedString)
                                m_String += 2;
                        }
                    }

                    HighlighterObject highlighter = m_String != 0 ? new HighlighterObject(m_String, bytearrayColor != Colors.White ? bytearrayColor : Colors.Purple) : GetNativeHighlighter(part.Type.ToString());
                    TextRange h_Range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += (highlighter.offset * 3 + 1)));
                    h_Range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(highlighter.color));
                    if (!m_BeenAtArray)
                        m_Header.Items.Add("Segment " + part.Name + " (" + part.Type.ToString() + ") - Value: " + value);
                    h_Range = new TextRange(m_DocStart.GetPositionAtOffset(m_GeneralOffset), m_DocStart.GetPositionAtOffset(m_GeneralOffset += 3));
                    h_Range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.White));
                    h_Range = null;
                }
            }
            PartView.Items.Add(m_Header);
            reader = null;
        }