Пример #1
0
        private object ReadObject()
        {
            int handle = ReadInt();
            bool inline = ((handle & 1) != 0);
            handle = handle >> 1;

            if (inline)
            {
                bool inlineDefine = ((handle & 1) != 0);
                handle = handle >> 1;

                ClassDefinition cd;
                if (inlineDefine)
                {
                    cd = new ClassDefinition();
                    cd.type = ReadString();

                    cd.externalizable = ((handle & 1) != 0);
                    handle = handle >> 1;
                    cd.dynamic = ((handle & 1) != 0);
                    handle = handle >> 1;

                    for (int i = 0; i < handle; i++)
                        cd.members.Add(ReadString());

                    classDefinitions.Add(cd);
                }
                else
                {
                    cd = classDefinitions[handle];
                }

                TypedObject ret = new TypedObject(cd.type);

                // Need to add reference here due to circular references
                objectReferences.Add(ret);

                if (cd.externalizable)
                {
                    if (cd.type.Equals("DSK"))
                        ret = ReadDSK();
                    else if (cd.type.Equals("DSA"))
                        ret = ReadDSA();
                    else if (cd.type.Equals("flex.messaging.io.ArrayCollection"))
                    {
                        object obj = Decode();
                        ret = TypedObject.MakeArrayCollection((object[])obj);
                    }
                    else if (cd.type.Equals("com.riotgames.platform.systemstate.ClientSystemStatesNotification") ||
                             cd.type.Equals("com.riotgames.platform.broadcast.BroadcastNotification"))
                    {
                        int size = 0;
                        for (int i = 0; i < 4; i++)
                            size = size * 256 + ReadByteAsInt();

                        byte[] data = ReadBytes(size);
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < data.Length; i++)
                            sb.Append(Convert.ToChar(data[i]));

                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        ret = serializer.Deserialize<TypedObject>(sb.ToString());
                        ret.type = cd.type;
                    }
                    else
                    {
                        //for (int i = dataPos; i < dataBuffer.length; i++)
                        //System.out.print(String.format("%02X", dataBuffer[i]));
                        //System.out.println();
                        throw new NotImplementedException("Externalizable not handled for " + cd.type);
                    }
                }
                else
                {
                    for (int i = 0; i < cd.members.Count; i++)
                    {
                        String key = cd.members[i];
                        object value = Decode();
                        ret.Add(key, value);
                    }

                    if (cd.dynamic)
                    {
                        String key;
                        while ((key = ReadString()).Length != 0)
                        {
                            object value = Decode();
                            ret.Add(key, value);
                        }
                    }
                }

                return ret;
            }
            else
            {
                return objectReferences[handle];
            }
        }
Пример #2
0
        private object ReadObject()
        {
            int  handle = ReadInt();
            bool inline = ((handle & 1) != 0);

            handle = handle >> 1;

            if (inline)
            {
                bool inlineDefine = ((handle & 1) != 0);
                handle = handle >> 1;

                ClassDefinition cd;
                if (inlineDefine)
                {
                    cd      = new ClassDefinition();
                    cd.type = ReadString();

                    cd.externalizable = ((handle & 1) != 0);
                    handle            = handle >> 1;
                    cd.dynamic        = ((handle & 1) != 0);
                    handle            = handle >> 1;

                    for (int i = 0; i < handle; i++)
                    {
                        cd.members.Add(ReadString());
                    }

                    classDefinitions.Add(cd);
                }
                else
                {
                    cd = classDefinitions[handle];
                }

                TypedObject ret = new TypedObject(cd.type);

                // Need to add reference here due to circular references
                objectReferences.Add(ret);

                if (cd.externalizable)
                {
                    if (cd.type.Equals("DSK"))
                    {
                        ret = ReadDSK();
                    }
                    else if (cd.type.Equals("DSA"))
                    {
                        ret = ReadDSA();
                    }
                    else if (cd.type.Equals("flex.messaging.io.ArrayCollection"))
                    {
                        object obj = Decode();
                        ret = TypedObject.MakeArrayCollection((object[])obj);
                    }
                    else if (cd.type.Equals("com.riotgames.platform.systemstate.ClientSystemStatesNotification") ||
                             cd.type.Equals("com.riotgames.platform.broadcast.BroadcastNotification"))
                    {
                        int size = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            size = size * 256 + ReadByteAsInt();
                        }

                        byte[]        data = ReadBytes(size);
                        StringBuilder sb   = new StringBuilder();
                        for (int i = 0; i < data.Length; i++)
                        {
                            sb.Append(Convert.ToChar(data[i]));
                        }

                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        ret      = serializer.Deserialize <TypedObject>(sb.ToString());
                        ret.type = cd.type;
                    }
                    else
                    {
                        //for (int i = dataPos; i < dataBuffer.length; i++)
                        //System.out.print(String.format("%02X", dataBuffer[i]));
                        //System.out.println();
                        throw new NotImplementedException("Externalizable not handled for " + cd.type);
                    }
                }
                else
                {
                    for (int i = 0; i < cd.members.Count; i++)
                    {
                        String key   = cd.members[i];
                        object value = Decode();
                        ret.Add(key, value);
                    }

                    if (cd.dynamic)
                    {
                        String key;
                        while ((key = ReadString()).Length != 0)
                        {
                            object value = Decode();
                            ret.Add(key, value);
                        }
                    }
                }

                return(ret);
            }
            else
            {
                return(objectReferences[handle]);
            }
        }