Esempio n. 1
0
        private void ParseValue(TreeListNode pNode, ERiftPacketFieldType pType, RiftPacketFieldValue pValue)
        {
            switch (pType)
            {
                case ERiftPacketFieldType.False: pNode.SubItems.Add("False"); break;
                case ERiftPacketFieldType.True: pNode.SubItems.Add("True"); break;
                case ERiftPacketFieldType.Unsigned7BitEncoded: pNode.SubItems.Add(pValue.Long.ToString()); break;
                case ERiftPacketFieldType.Signed7BitEncoded: pNode.SubItems.Add(pValue.Long.ToString()); break;
                case ERiftPacketFieldType.Raw4Bytes: pNode.SubItems.Add(BitConverter.ToString(pValue.Bytes).Replace('-', ' ')); break;
                case ERiftPacketFieldType.Raw8Bytes: pNode.SubItems.Add(BitConverter.ToString(pValue.Bytes).Replace('-', ' ')); break;
                case ERiftPacketFieldType.ByteArray: pNode.SubItems.Add(BitConverter.ToString(pValue.Bytes, 0, Math.Min(8, pValue.Bytes.Length)).Replace('-', ' ') + (pValue.Bytes.Length > 8 ? " ..." : "")); break;
                case ERiftPacketFieldType.Packet:
                    {
                        pNode.SubItems.Add("0x" + pValue.Packet.Opcode.ToString("X8"));
                        Parse(pNode, pValue.Packet);
                        break;
                    }
                case ERiftPacketFieldType.List:
                    {
                        pNode.SubItems.Add("Type = " + pValue.List.Type.ToString());
                        for (int index = 0; index < pValue.List.Count; ++index)
                        {
                            RiftPacketFieldValue value = pValue.List[index];
                            TreeListNode listValueNode = new TreeListNode();
                            listValueNode.Text = "";
                            listValueNode.SubItems.Add("");
                            listValueNode.SubItems.Add(value.Type.ToString());
                            if (value.Type == ERiftPacketFieldType.Packet)
                            {
                                PacketDescriptions.PacketDescription description = PacketDescriptions.Instance.Descriptions.Find(d => d.Outbound == value.Packet.Outbound && d.Opcode == value.Packet.Opcode);
                                if (description != null && description.Name.Trim().Length > 0) listValueNode.SubItems.Add(description.Name + " (Index " + index.ToString() + ")");
                                else listValueNode.SubItems.Add("Index " + index.ToString());
                                listValueNode.Tag = value.Packet;
                            }
                            else
                            {
                                listValueNode.SubItems.Add("Index " + index.ToString());
                                listValueNode.Tag = value;
                            }
                            ParseValue(listValueNode, value.Type, value);
                            pNode.Nodes.Add(listValueNode);
                        }
                        break;
                    }
                case ERiftPacketFieldType.Dictionary:
                    {
                        pNode.SubItems.Add("Key Type = " + pValue.Dictionary.KeyType.ToString() + ", Value Type = " + pValue.Dictionary.ValueType.ToString());
                        for (int index = 0; index < pValue.Dictionary.Count; ++index)
                        {
                            TreeListNode dictionaryKeyValueNode = new TreeListNode();
                            dictionaryKeyValueNode.Text = "";
                            dictionaryKeyValueNode.SubItems.Add("");
                            dictionaryKeyValueNode.SubItems.Add("");
                            dictionaryKeyValueNode.SubItems.Add("Index " + index.ToString());

                            RiftPacketFieldValue keyValue = pValue.Dictionary[index].Key;
                            RiftPacketFieldValue valueValue = pValue.Dictionary[index].Value;
                            dictionaryKeyValueNode.SubItems.Add("");

                            TreeListNode dictionaryKeyNode = new TreeListNode();
                            dictionaryKeyNode.Text = "";
                            dictionaryKeyNode.SubItems.Add("");
                            dictionaryKeyNode.SubItems.Add(keyValue.Type.ToString());
                            if (keyValue.Type == ERiftPacketFieldType.Packet)
                            {
                                PacketDescriptions.PacketDescription description = PacketDescriptions.Instance.Descriptions.Find(d => d.Outbound == keyValue.Packet.Outbound && d.Opcode == keyValue.Packet.Opcode);
                                if (description != null && description.Name.Trim().Length > 0) dictionaryKeyNode.SubItems.Add(description.Name + " (Key)");
                                else dictionaryKeyNode.SubItems.Add("Key");
                                dictionaryKeyNode.Tag = keyValue.Packet;
                            }
                            else
                            {
                                dictionaryKeyNode.SubItems.Add("Key");
                                dictionaryKeyNode.Tag = keyValue;
                            }

                            ParseValue(dictionaryKeyNode, keyValue.Type, keyValue);
                            dictionaryKeyValueNode.Nodes.Add(dictionaryKeyNode);

                            if (valueValue != null)
                            {
                                TreeListNode dictionaryValueNode = new TreeListNode();
                                dictionaryValueNode.Text = "";
                                dictionaryValueNode.SubItems.Add("");
                                dictionaryValueNode.SubItems.Add(valueValue.Type.ToString());
                                if (valueValue.Type == ERiftPacketFieldType.Packet)
                                {
                                    PacketDescriptions.PacketDescription description = PacketDescriptions.Instance.Descriptions.Find(d => d.Outbound == valueValue.Packet.Outbound && d.Opcode == valueValue.Packet.Opcode);
                                    if (description != null && description.Name.Trim().Length > 0) dictionaryValueNode.SubItems.Add(description.Name + " (Value)");
                                    else dictionaryValueNode.SubItems.Add("Value");
                                    dictionaryValueNode.Tag = valueValue.Packet;
                                }
                                else
                                {
                                    dictionaryValueNode.SubItems.Add("Value");
                                    dictionaryValueNode.Tag = valueValue;
                                }
                                ParseValue(dictionaryValueNode, valueValue.Type, valueValue);
                                dictionaryKeyValueNode.Nodes.Add(dictionaryValueNode);
                            }

                            pNode.Nodes.Add(dictionaryKeyValueNode);
                        }
                        break;
                    }
                default: pNode.SubItems.Add(""); break;
            }
        }
Esempio n. 2
0
 private bool ReadFieldValue(ERiftPacketFieldType pFieldType, out RiftPacketFieldValue pFieldValue, out int pSizeOfFieldValue)
 {
     pFieldValue = null;
     pSizeOfFieldValue = 0;
     switch (pFieldType)
     {
         case ERiftPacketFieldType.False:
         case ERiftPacketFieldType.True:
         case ERiftPacketFieldType.Invalid:
         case ERiftPacketFieldType.Terminator:
             break;
         case ERiftPacketFieldType.Unsigned7BitEncoded:
         case ERiftPacketFieldType.Signed7BitEncoded:
             {
                 long value;
                 int sizeOfValue;
                 if (!Decode7BitValue(out value, out sizeOfValue, mBuffer, mCursor, mLength)) return false;
                 pSizeOfFieldValue += sizeOfValue;
                 mCursor += sizeOfValue;
                 mLength -= sizeOfValue;
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         case ERiftPacketFieldType.Raw4Bytes:
             {
                 if (mLength < 4) return false;
                 byte[] value = new byte[4];
                 Buffer.BlockCopy(mBuffer, mCursor, value, 0, 4);
                 pSizeOfFieldValue += 4;
                 mCursor += 4;
                 mLength -= 4;
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         case ERiftPacketFieldType.Raw8Bytes:
             {
                 if (mLength < 8) return false;
                 byte[] value = new byte[8];
                 Buffer.BlockCopy(mBuffer, mCursor, value, 0, 8);
                 pSizeOfFieldValue += 8;
                 mCursor += 8;
                 mLength -= 8;
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         case ERiftPacketFieldType.ByteArray:
             {
                 long length;
                 int sizeOfLength;
                 if (!Decode7BitValue(out length, out sizeOfLength, mBuffer, mCursor, mLength)) return false;
                 pSizeOfFieldValue += sizeOfLength;
                 mCursor += sizeOfLength;
                 mLength -= sizeOfLength;
                 if (mLength < length) return false;
                 byte[] value = new byte[length];
                 Buffer.BlockCopy(mBuffer, mCursor, value, 0, (int)length);
                 pSizeOfFieldValue += (int)length;
                 mCursor += (int)length;
                 mLength -= (int)length;
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         case ERiftPacketFieldType.Packet:
             {
                 RiftPacket value;
                 int sizeOfValue;
                 if (!ReadPacket(out value, out sizeOfValue)) return false;
                 pSizeOfFieldValue += sizeOfValue;
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         case ERiftPacketFieldType.List:
             {
                 long listData;
                 int sizeOfListData;
                 if (!Decode7BitValue(out listData, out sizeOfListData, mBuffer, mCursor, mLength)) return false;
                 pSizeOfFieldValue += sizeOfListData;
                 mCursor += sizeOfListData;
                 mLength -= sizeOfListData;
                 int listType;
                 int listCount;
                 if (!Decode2Parameters(listData, out listType, out listCount)) return false;
                 RiftPacketFieldValueList value = new RiftPacketFieldValueList((ERiftPacketFieldType)listType);
                 for (int listIndex = 0; listIndex < listCount; ++listIndex)
                 {
                     RiftPacketFieldValue listValue;
                     int sizeOfListValue;
                     if (!ReadFieldValue((ERiftPacketFieldType)listType, out listValue, out sizeOfListValue)) return false;
                     pSizeOfFieldValue += sizeOfListValue;
                     if (listValue != null) value.Add(listValue);
                 }
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         case ERiftPacketFieldType.Dictionary:
             {
                 long dictionaryData;
                 int sizeOfDictionaryData;
                 if (!Decode7BitValue(out dictionaryData, out sizeOfDictionaryData, mBuffer, mCursor, mLength)) return false;
                 pSizeOfFieldValue += sizeOfDictionaryData;
                 mCursor += sizeOfDictionaryData;
                 mLength -= sizeOfDictionaryData;
                 int dictionaryKeyType;
                 int dictionaryValueType;
                 int dictionaryCount;
                 if (!Decode3Parameters(dictionaryData, out dictionaryKeyType, out dictionaryValueType, out dictionaryCount)) return false;
                 RiftPacketFieldValueDictionary value = new RiftPacketFieldValueDictionary((ERiftPacketFieldType)dictionaryKeyType, (ERiftPacketFieldType)dictionaryValueType);
                 for (int dictionaryIndex = 0; dictionaryIndex < dictionaryCount; ++dictionaryIndex)
                 {
                     RiftPacketFieldValue dictionaryKeyValue = null;
                     if (Enum.IsDefined(typeof(ERiftPacketFieldType), dictionaryKeyType))
                     {
                         int sizeOfDictionaryKeyValue;
                         if (!ReadFieldValue((ERiftPacketFieldType)dictionaryKeyType, out dictionaryKeyValue, out sizeOfDictionaryKeyValue)) return false;
                         pSizeOfFieldValue += sizeOfDictionaryKeyValue;
                     }
                     RiftPacketFieldValue dictionaryValueValue = null;
                     if (Enum.IsDefined(typeof(ERiftPacketFieldType), dictionaryValueType))
                     {
                         int sizeOfDictionaryValueValue;
                         if (!ReadFieldValue((ERiftPacketFieldType)dictionaryValueType, out dictionaryValueValue, out sizeOfDictionaryValueValue)) return false;
                         pSizeOfFieldValue += sizeOfDictionaryValueValue;
                     }
                     if (dictionaryKeyValue != null || dictionaryValueValue != null) value.Add(new KeyValuePair<RiftPacketFieldValue, RiftPacketFieldValue>(dictionaryKeyValue, dictionaryValueValue));
                 }
                 pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                 break;
             }
         default: break;
     }
     return true;
 }