Ejemplo n.º 1
0
    public void WriteAMF3Object(AMF3Object Value)
    {
        Enter();

        if (_DebugLevel > 2)
            AddDebugMessage("{0}{1}: \r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name);

        uint ReferencePtr = 0;

        ReferencePtr |= Value.IsInLine;

        if (_DebugLevel > 2)
            AddDebugMessage("{0} IsInLine: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, Value.IsInLine);

        if (Value.IsInLine == 1)
        {
            ReferencePtr |= Value.IsInLineClassDef << 1;

            if (_DebugLevel > 2)
                AddDebugMessage("{0} IsInLineClassDef: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, Value.IsInLineClassDef);

            if (Value.IsInLineClassDef == 1)
            {
                ReferencePtr |= Value.IsExternalizable << 2;
                ReferencePtr |= Value.IsDynamic << 3;
                ReferencePtr |= Value.ClassMemberCount << 4;

                WriteAMF3UInt( (uint) ReferencePtr);
                WriteAMF3String( (string) Value.TypeIdentifier);

                for (int i = 0; i < Value.ClassMemberCount; i++)
                {
                    if (_DebugLevel > 2)
                        AddDebugMessage("{0} ClassMemberDefinition: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, Value.ClassMemberDefinitions[i]);

                    WriteAMF3String( (string) Value.ClassMemberDefinitions[i]);
                }

                NewClassDefinitions.Add(
                    new ClassDefinition(
                        Value.TypeIdentifier,
                        Value.ClassMemberDefinitions,
                        Value.IsExternalizable,
                        Value.IsDynamic
                    )
                );
            }
            else
            {
                if (_DebugLevel > 2)
                    AddDebugMessage("{0} Finding Index {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReferencePtr);

                for (int index = 0; index < NewClassDefinitions.Count; index++)
                {
                    ClassDefinition OneClassDefinition = (ClassDefinition)NewClassDefinitions[index];

                    if (Value.TypeIdentifier == OneClassDefinition.TypeIdentifier)
                    {
                        ReferencePtr |= (uint)(index << 2);

                        if (_DebugLevel > 2)
                            AddDebugMessage("{0} Found Index: 0x{2:x} ReferencePtr: 0x{3:x}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, index, ReferencePtr);

                        
                        break;
                    }
                }

                WriteAMF3UInt((uint)ReferencePtr);
            }
        }
        else
        {
            WriteAMF3UInt((uint)ReferencePtr);
        }

        if (Value.IsExternalizable == 1)
        {
            //TODO: Write
            AddDebugMessage(Prefix + "TODO: Write Externalizable Object\r\n");
            switch (Value.TypeIdentifier)
            {
                case "flex.messaging.io.ArrayCollection":
                case "flex.messaging.io.ObjectProxy":
                    //MetaObject DataArray = WriteAMF3();
                    //Value.Parameters.Add(DataArray);
                    break;

                case "DSK":
                    // skip two bytes
                    //Offset += 2;

                    // Write the inner type and add it
                    //MetaObject StartType = WriteAMF3();
                    //String StartClass = ((AMF3Object)StartType.Data).TypeIdentifier;
                    //Value.ClassMemberDefinitions.Add(StartClass);
                    //Value.Parameters.Add(StartType);
                    break;

                default:
                    AddDebugMessage(Prefix + "Can't read " + Value.TypeIdentifier);
                    break;
            }
        }
        else
        {
            //TODO:
            if (_DebugLevel > 2)
                AddDebugMessage("{0} Value.ClassMemberDefinitions.Count: 0x{2:x}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, Value.ClassMemberDefinitions.Count);

            foreach (MetaObject CurrentMetaObject in Value.Parameters)
            {
                if (_DebugLevel > 0)
                    AddDebugMessage("{0} WriteAMF3 for {2}\r\n", 
                            Prefix, 
                            System.Reflection.MethodBase.GetCurrentMethod().Name, 
                            CurrentMetaObject
                        );
                WriteAMF3(CurrentMetaObject);
            }

            if (Value.IsDynamic == 1)
            {
                foreach(KeyValuePair<string, Object> kvp in Value.DynamicMembers)
                {
                    if (_DebugLevel > 2)
                        AddDebugMessage("{0} Key: {2:G} - {3}\r\n",
                                Prefix,
                                System.Reflection.MethodBase.GetCurrentMethod().Name,
                                kvp.Key,
                                kvp.Value);

                    WriteAMF3String( (string) kvp.Key );
                    WriteAMF3( (MetaObject) kvp.Value );
                }

                WriteAMF3String("");
            }
        }
        Exit();
    }
Ejemplo n.º 2
0
    public AMF3Object ReadAMF3Object()
    {
        AMF3Object ReturnValue = new AMF3Object();

        Enter();

        if (_DebugLevel > 2)
            AddDebugMessage("{0}{1}: @0x{2:x}\r\n", 
                Prefix, 
                System.Reflection.MethodBase.GetCurrentMethod().Name, 
                Offset);

        uint ReferencePtr = ReadAMF3UInt();

        if (_DebugLevel > 2)
            AddDebugMessage("{0} ReferencePtr: 0x{2:x}\r\n",
                    Prefix,
                    System.Reflection.MethodBase.GetCurrentMethod().Name,
                    ReferencePtr
                );

        ReturnValue.TypeIdentifier = "";
        ReturnValue.IsExternalizable = 0;
        ReturnValue.IsDynamic = 0;
        ReturnValue.ClassMemberCount = 0;
        ReturnValue.IsInLine = (ReferencePtr & 1);
        ReferencePtr >>= 1;

        if (_DebugLevel > 2)
            AddDebugMessage("{0} IsInLine: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReturnValue.IsInLine);

        if (ReturnValue.IsInLine == 1)
        {
            ReturnValue.IsInLineClassDef = ReferencePtr & 1;
            ReferencePtr >>= 1;
            if (_DebugLevel > 2)
                AddDebugMessage("{0} IsInLineClassDef: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReturnValue.IsInLineClassDef);

            if (ReturnValue.IsInLineClassDef == 1)
            {
                ReturnValue.TypeIdentifier = ReadAMF3String();
                ReturnValue.IsExternalizable = ReferencePtr & 1;

                ReferencePtr >>= 1;
                ReturnValue.IsDynamic = ReferencePtr & 1;
                ReferencePtr >>= 1;
                ReturnValue.ClassMemberCount = ReferencePtr;

                if (_DebugLevel > 0)
                {
                    AddDebugMessage("{0} TypeIdentifier: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReturnValue.TypeIdentifier);
                    AddDebugMessage("{0} IsExternalizable: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReturnValue.IsExternalizable);
                    AddDebugMessage("{0} IsDynamic: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReturnValue.IsDynamic);
                    AddDebugMessage("{0} ClassMemberCount: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReturnValue.ClassMemberCount);
                }

                for (int i = 0; i < ReturnValue.ClassMemberCount; i++)
                {
                    string ClassMemberDefinition = ReadAMF3String();
                    ReturnValue.ClassMemberDefinitions.Add(ClassMemberDefinition);

                    if (_DebugLevel > 2)
                        AddDebugMessage("{0} ClassMemberDefinition: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ClassMemberDefinition);
                }

                ClassDefinitions.Add(
                    new ClassDefinition(
                        ReturnValue.TypeIdentifier,
                        ReturnValue.ClassMemberDefinitions,
                        ReturnValue.IsExternalizable,
                        ReturnValue.IsDynamic
                    )
                );
            }
            else
            {
                if (_DebugLevel > 2)
                    AddDebugMessage("{0} ReferencePtr: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, ReferencePtr);

                if (ClassDefinitions != null)
                {
                    ClassDefinition OneClassDefinition = (ClassDefinition)ClassDefinitions[(int)ReferencePtr];

                    if (_DebugLevel > 2)
                        AddDebugMessage("{0} OneClassDefinition Found\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name );

                    ReturnValue.TypeIdentifier = OneClassDefinition.TypeIdentifier;
                    ReturnValue.ClassMemberDefinitions = OneClassDefinition.ClassMemberDefinitions;
                    ReturnValue.IsExternalizable = OneClassDefinition.IsExternalizable;
                    ReturnValue.IsDynamic = OneClassDefinition.IsDynamic;
                }
            }
        }
        else
        {
            AddDebugMessage(Prefix + "TODO: Use ReferencePtr\r\n\r\n");

            Exit();
            return ReturnValue;
        }

        if (ReturnValue.IsExternalizable == 1)
        {
            switch (ReturnValue.TypeIdentifier)
            {
                case "flex.messaging.io.ArrayCollection":
                case "flex.messaging.io.ObjectProxy":
                    MetaObject DataArray = ReadAMF3();
                    ReturnValue.Parameters.Add(DataArray);
                    break;

                case "DSK":
                    // skip two bytes
                    Offset += 2;
                    AddDebugMessage(String.Format("{0} TODO: Skip 2 bytes in {1}", Prefix, ReturnValue.TypeIdentifier));

                    // Read the inner type and add it
                    MetaObject StartType = ReadAMF3();
                    String StartClass = ((AMF3Object)StartType.Data).TypeIdentifier;
                    ReturnValue.ClassMemberDefinitions.Add(StartClass);
                    ReturnValue.Parameters.Add(StartType);
                    break;

                default:
                    AddDebugMessage(Prefix + "Can't read " + ReturnValue.TypeIdentifier);
                    break;
            }
        }
        else
        {
            for (int i = 0; i < ReturnValue.ClassMemberDefinitions.Count; i++)
            {

                if (_DebugLevel > 0)
                    AddDebugMessage(Prefix + ReturnValue.ClassMemberDefinitions[i].ToString() + "\r\n");

                ReturnValue.Parameters.Add(ReadAMF3()); //Value
            }

            if (ReturnValue.IsDynamic == 1)
            {
                string Key = ReadAMF3String(); //Key
                while (Key.Length > 0)
                {
                    if (_DebugLevel > 2)
                        AddDebugMessage("{0} Key: {2:G}\r\n", Prefix, System.Reflection.MethodBase.GetCurrentMethod().Name, Key);

                    ReturnValue.DynamicMembers.Add(Key, ReadAMF3()); //Value                    
                    Key = ReadAMF3String(); //Key
                }
            }
        }

        AddDebugMessage("{0} End Offset: 0x{1:x}\r\n", Prefix, Offset );
        Exit();
        return ReturnValue;
    }