Exemplo n.º 1
0
        private void InitSiWrite()
        {
            SerTrace.Log(this, objectInfoId, " InitSiWrite Entry ");

            SerializationInfoEnumerator siEnum = null;

            isSi   = true;
            siEnum = si.GetEnumerator();
            int infoLength = 0;

            infoLength = si.MemberCount;

            int count = infoLength;

            // For ISerializable cache cannot be saved because each object instance can have different values
            // BinaryWriter only puts the map on the wire if the ISerializable map cannot be reused.
            TypeInformation typeInformation      = null;
            string          fullTypeName         = si.FullTypeName;
            string          assemblyString       = si.AssemblyName;
            bool            hasTypeForwardedFrom = false;

            if (!si.IsFullTypeNameSetExplicit)
            {
                typeInformation      = BinaryFormatter.GetTypeInformation(si.ObjectType);
                fullTypeName         = typeInformation.FullTypeName;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }

            if (!si.IsAssemblyNameSetExplicit)
            {
                if (typeInformation == null)
                {
                    typeInformation = BinaryFormatter.GetTypeInformation(si.ObjectType);
                }
                assemblyString       = typeInformation.AssemblyString;
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }

            cache = new SerObjectInfoCache(fullTypeName, assemblyString, hasTypeForwardedFrom);

            cache.memberNames = new String[count];
            cache.memberTypes = new Type[count];
            memberData        = new Object[count];

            siEnum = si.GetEnumerator();
            for (int i = 0; siEnum.MoveNext(); i++)
            {
                cache.memberNames[i] = siEnum.Name;
                cache.memberTypes[i] = siEnum.ObjectType;
                memberData[i]        = siEnum.Value;
                SerTrace.Log(this, objectInfoId + " ", objectType, " InitSiWrite ", cache.memberNames[i], " Type ", cache.memberTypes[i], " data ", memberData[i]);
            }

            isNamed = true;
            isTyped = false;

            SerTrace.Log(this, objectInfoId, " InitSiWrite Exit ");
        }
Exemplo n.º 2
0
 private void InitNoMembers()
 {
     cache = (SerObjectInfoCache)serObjectInfoInit.seenBeforeTable[objectType];
     if (cache == null)
     {
         SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo new cache");
         cache = new SerObjectInfoCache(objectType);
         serObjectInfoInit.seenBeforeTable.Add(objectType, cache);
     }
 }
Exemplo n.º 3
0
        // Write Constructor used for array types or null members
        // [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType        = objectType;
            this.context           = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache(objectType);

                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                si    = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
                cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);

                isSi = true;
            }

            if (!isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
Exemplo n.º 4
0
        private static void CheckTypeForwardedFrom(SerObjectInfoCache cache, Type objectType, string binderAssemblyString)
        {
            // If we're about to use the [TypeForwardedFrom] attribute for the assembly name
            if (cache.hasTypeForwardedFrom && binderAssemblyString == null)
            {
                if (!FormatterServices.UnsafeTypeForwardersIsEnabled())
                {
                    Assembly objectAssembly = objectType.Assembly;

                    // cache.assemblyString will be set to the value of the AssemblyFullName set on the TypeForwardedFrom attribute
                    if (!SerializationInfo.IsAssemblyNameAssignmentSafe(objectAssembly.FullName, cache.assemblyString) &&
                        !objectAssembly.IsFullyTrusted)
                    {
                        // if the object assembly is partially trusted, we will block the TypeForwardedFrom case
                        throw new SecurityException(Ssz.Runtime.Serialization.Environment.GetResourceString("Serialization_RequireFullTrust", objectType));
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void InternalInit()
        {
            SerTrace.Log(this, objectInfoId, " objectType ", objectType, " InternalInit");
            obj        = null;
            objectType = null;
            isSi       = false;
            isNamed    = false;
            isTyped    = false;
            isArray    = false;
            si         = null;
            cache      = null;
            memberData = null;

            // Writing and Parsing information
            objectId = 0;
            assemId  = 0;

            // Binder information
            binderTypeName       = null;
            binderAssemblyString = null;
        }
Exemplo n.º 6
0
        // [System.Security.SecurityCritical]  // auto-generated
        private void InitMemberInfo()
        {
            SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo Entry");

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo new cache");
            cache             = new SerObjectInfoCache(objectType);
            cache.memberInfos = FormatterServices.GetSerializableMembers(objectType, context);
            count             = cache.memberInfos.Length;
            cache.memberNames = new String[count];
            cache.memberTypes = new Type[count];

            // Calculate new arrays
            for (int i = 0; i < count; i++)
            {
                cache.memberNames[i] = cache.memberInfos[i].Name;
                cache.memberTypes[i] = GetMemberType(cache.memberInfos[i]);
                SerTrace.Log(this, objectInfoId, " InitMemberInfo name ", cache.memberNames[i], ", type ", cache.memberTypes[i], ", memberInfoType ", cache.memberInfos[i].GetType());
            }

            isTyped = true;
            isNamed = true;
            SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo Exit");
        }
Exemplo n.º 7
0
        // [System.Security.SecurityCritical]  // auto-generated
        private void InitMemberInfo()
        {
            SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo Entry");


            cache = (SerObjectInfoCache)serObjectInfoInit.seenBeforeTable[objectType];
            if (cache == null)
            {
                SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo new cache");
                cache = new SerObjectInfoCache(objectType);

                cache.memberInfos = FormatterServices.GetSerializableMembers(objectType, context);
                int count = cache.memberInfos.Length;
                cache.memberNames = new String[count];
                cache.memberTypes = new Type[count];

                // Calculate new arrays
                for (int i = 0; i < count; i++)
                {
                    cache.memberNames[i] = cache.memberInfos[i].Name;
                    cache.memberTypes[i] = GetMemberType(cache.memberInfos[i]);
                    SerTrace.Log(this, objectInfoId, " InitMemberInfo name ", cache.memberNames[i], ", type ", cache.memberTypes[i], ", memberInfoType ", cache.memberInfos[i].GetType());
                }
                serObjectInfoInit.seenBeforeTable.Add(objectType, cache);
            }

            if (obj != null)
            {
                memberData = FormatterServices.GetObjectData(obj, cache.memberInfos);
                DumpMemberInfo();
            }

            isTyped = true;
            isNamed = true;
            SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo Exit");
        }
Exemplo n.º 8
0
 private void InitNoMembers()
 {
     SerTrace.Log(this, objectInfoId, " ", objectType, " InitMemberInfo new cache");
     cache = new SerObjectInfoCache(objectType);
 }