internal Hash(SerializationInfo info, StreamingContext context)
 {
     Dictionary<Type, byte[]> valueNoThrow = info.GetValueNoThrow("Hashes", typeof(Dictionary<Type, byte[]>)) as Dictionary<Type, byte[]>;
     if (valueNoThrow != null)
     {
         this.m_hashes = valueNoThrow;
     }
     else
     {
         this.m_hashes = new Dictionary<Type, byte[]>();
         byte[] buffer = info.GetValueNoThrow("Md5", typeof(byte[])) as byte[];
         if (buffer != null)
         {
             this.m_hashes[typeof(System.Security.Cryptography.MD5)] = buffer;
         }
         byte[] buffer2 = info.GetValueNoThrow("Sha1", typeof(byte[])) as byte[];
         if (buffer2 != null)
         {
             this.m_hashes[typeof(System.Security.Cryptography.SHA1)] = buffer2;
         }
         byte[] assemblyBytes = info.GetValueNoThrow("RawData", typeof(byte[])) as byte[];
         if (assemblyBytes != null)
         {
             this.GenerateDefaultHashes(assemblyBytes);
         }
     }
 }
Ejemplo n.º 2
0
 protected Exception(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     this._className = info.GetString("ClassName");
     this._message = info.GetString("Message");
     this._data = (IDictionary) info.GetValueNoThrow("Data", typeof(IDictionary));
     this._innerException = (Exception) info.GetValue("InnerException", typeof(Exception));
     this._helpURL = info.GetString("HelpURL");
     this._stackTraceString = info.GetString("StackTraceString");
     this._remoteStackTraceString = info.GetString("RemoteStackTraceString");
     this._remoteStackIndex = info.GetInt32("RemoteStackIndex");
     this._exceptionMethodString = (string) info.GetValue("ExceptionMethod", typeof(string));
     this.HResult = info.GetInt32("HResult");
     this._source = info.GetString("Source");
     if ((this._className == null) || (this.HResult == 0))
     {
         throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
     }
     if (context.State == StreamingContextStates.CrossAppDomain)
     {
         this._remoteStackTraceString = this._remoteStackTraceString + this._stackTraceString;
         this._stackTraceString = null;
     }
 }
Ejemplo n.º 3
0
        internal Hash(SerializationInfo info, StreamingContext context)
        {
            //
            // We have three serialization formats that we might be deserializing, the Whidbey format which
            // contains hash values directly, the Whidbey format which contains a pointer to a PEImage, and
            // the v4 format which contains a dictionary of calculated hashes.
            // 
            // If we have the Whidbey version that has built in hash values, we can convert that, but we
            // cannot do anything with the PEImage format since that is a serialized pointer into another
            // runtime's VM.
            // 

            Dictionary<Type, byte[]> hashes = info.GetValueNoThrow("Hashes", typeof(Dictionary<Type, byte[]>)) as Dictionary<Type, byte[]>;
            if (hashes != null)
            {
                m_hashes = hashes;
            }
            else
            {
                // If there is no hash value dictionary, then check to see if we have the Whidbey multiple
                // hashes version of the evidence.
                m_hashes = new Dictionary<Type, byte[]>();

                byte[] md5 = info.GetValueNoThrow("Md5", typeof(byte[])) as byte[];
                if (md5 != null)
                {
                    m_hashes[typeof(MD5)] = md5;
                }

                byte[] sha1 = info.GetValueNoThrow("Sha1", typeof(byte[])) as byte[];
                if (sha1 != null)
                {
                    m_hashes[typeof(SHA1)] = sha1;
                }

                byte[] rawData = info.GetValueNoThrow("RawData", typeof(byte[])) as byte[];
                if (rawData != null)
                {
                    GenerateDefaultHashes(rawData);
                }
            }
        }
Ejemplo n.º 4
0
        private SafeSerializationManager(SerializationInfo info, StreamingContext context)
        {
            RuntimeType runtimeType = info.GetValueNoThrow("CLR_SafeSerializationManager_RealType", typeof(RuntimeType)) as RuntimeType;

            if (runtimeType == null)
            {
                this.m_serializedStates = (info.GetValue("m_serializedStates", typeof(List <object>)) as List <object>);
                return;
            }
            this.m_realType = runtimeType;
            this.m_savedSerializationInfo = info;
        }
Ejemplo n.º 5
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        protected Exception(SerializationInfo info, StreamingContext context) 
        {
            if (info==null)
                throw new ArgumentNullException("info");
            Contract.EndContractBlock();
    
            _className = info.GetString("ClassName");
            _message = info.GetString("Message");
            _data = (IDictionary)(info.GetValueNoThrow("Data",typeof(IDictionary)));
            _innerException = (Exception)(info.GetValue("InnerException",typeof(Exception)));
            _helpURL = info.GetString("HelpURL");
            _stackTraceString = info.GetString("StackTraceString");
            _remoteStackTraceString = info.GetString("RemoteStackTraceString");
            _remoteStackIndex = info.GetInt32("RemoteStackIndex");

            _exceptionMethodString = (String)(info.GetValue("ExceptionMethod",typeof(String)));
            HResult = info.GetInt32("HResult");
            _source = info.GetString("Source");
    
            // Get the WatsonBuckets that were serialized - this is particularly
            // done to support exceptions going across AD transitions.
            // 
            // We use the no throw version since we could be deserializing a pre-V4
            // exception object that may not have this entry. In such a case, we would
            // get null.
            _watsonBuckets = (Object)info.GetValueNoThrow("WatsonBuckets", typeof(byte[]));

#if FEATURE_SERIALIZATION
            _safeSerializationManager = info.GetValueNoThrow("SafeSerializationManager", typeof(SafeSerializationManager)) as SafeSerializationManager;
#endif // FEATURE_SERIALIZATION

            if (_className == null || HResult==0)
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
            
            // If we are constructing a new exception after a cross-appdomain call...
            if (context.State == StreamingContextStates.CrossAppDomain)
            {
                // ...this new exception may get thrown.  It is logically a re-throw, but 
                //  physically a brand-new exception.  Since the stack trace is cleared 
                //  on a new exception, the "_remoteStackTraceString" is provided to 
                //  effectively import a stack trace from a "remote" exception.  So,
                //  move the _stackTraceString into the _remoteStackTraceString.  Note
                //  that if there is an existing _remoteStackTraceString, it will be 
                //  preserved at the head of the new string, so everything works as 
                //  expected.
                // Even if this exception is NOT thrown, things will still work as expected
                //  because the StackTrace property returns the concatenation of the
                //  _remoteStackTraceString and the _stackTraceString.
                _remoteStackTraceString = _remoteStackTraceString + _stackTraceString;
                _stackTraceString = null;
            }
        }
 private SafeSerializationManager(SerializationInfo info, StreamingContext context)
 {
     RuntimeType valueNoThrow = info.GetValueNoThrow("CLR_SafeSerializationManager_RealType", typeof(RuntimeType)) as RuntimeType;
     if (valueNoThrow == null)
     {
         this.m_serializedStates = info.GetValue("m_serializedStates", typeof(List<object>)) as List<object>;
     }
     else
     {
         this.m_realType = valueNoThrow;
         this.m_savedSerializationInfo = info;
     }
 }
 private DelegateSerializationHolder(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     bool flag = true;
     try
     {
         this.m_delegateEntry = (DelegateEntry) info.GetValue("Delegate", typeof(DelegateEntry));
     }
     catch
     {
         this.m_delegateEntry = this.OldDelegateWireFormat(info, context);
         flag = false;
     }
     if (flag)
     {
         DelegateEntry delegateEntry = this.m_delegateEntry;
         int num = 0;
         while (delegateEntry != null)
         {
             if (delegateEntry.target != null)
             {
                 string target = delegateEntry.target as string;
                 if (target != null)
                 {
                     delegateEntry.target = info.GetValue(target, typeof(object));
                 }
             }
             num++;
             delegateEntry = delegateEntry.delegateEntry;
         }
         MethodInfo[] infoArray = new MethodInfo[num];
         int index = 0;
         while (index < num)
         {
             string name = "method" + index;
             infoArray[index] = (MethodInfo) info.GetValueNoThrow(name, typeof(MethodInfo));
             if (infoArray[index] == null)
             {
                 break;
             }
             index++;
         }
         if (index == num)
         {
             this.m_methods = infoArray;
         }
     }
 }
Ejemplo n.º 8
0
        private SafeSerializationManager(SerializationInfo info, StreamingContext context)
        {
            RuntimeType valueNoThrow = info.GetValueNoThrow("CLR_SafeSerializationManager_RealType", typeof(RuntimeType)) as RuntimeType;

            if (valueNoThrow == null)
            {
                this.m_serializedStates = info.GetValue("m_serializedStates", typeof(List <object>)) as List <object>;
            }
            else
            {
                this.m_realType = valueNoThrow;
                this.m_savedSerializationInfo = info;
            }
        }
 protected SecurityException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     try
     {
         this.m_action = (SecurityAction) info.GetValue("Action", typeof(SecurityAction));
         this.m_permissionThatFailed = (string) info.GetValueNoThrow("FirstPermissionThatFailed", typeof(string));
         this.m_demanded = (string) info.GetValueNoThrow("Demanded", typeof(string));
         this.m_granted = (string) info.GetValueNoThrow("GrantedSet", typeof(string));
         this.m_refused = (string) info.GetValueNoThrow("RefusedSet", typeof(string));
         this.m_denied = (string) info.GetValueNoThrow("Denied", typeof(string));
         this.m_permitOnly = (string) info.GetValueNoThrow("PermitOnly", typeof(string));
         this.m_assemblyName = (AssemblyName) info.GetValueNoThrow("Assembly", typeof(AssemblyName));
         this.m_serializedMethodInfo = (byte[]) info.GetValueNoThrow("Method", typeof(byte[]));
         this.m_strMethodInfo = (string) info.GetValueNoThrow("Method_String", typeof(string));
         this.m_zone = (SecurityZone) info.GetValue("Zone", typeof(SecurityZone));
         this.m_url = (string) info.GetValueNoThrow("Url", typeof(string));
     }
     catch
     {
         this.m_action = (SecurityAction) 0;
         this.m_permissionThatFailed = "";
         this.m_demanded = "";
         this.m_granted = "";
         this.m_refused = "";
         this.m_denied = "";
         this.m_permitOnly = "";
         this.m_assemblyName = null;
         this.m_serializedMethodInfo = null;
         this.m_strMethodInfo = null;
         this.m_zone = SecurityZone.NoZone;
         this.m_url = "";
     }
 }
Ejemplo n.º 10
0
        private SafeSerializationManager(SerializationInfo info, StreamingContext context)
        {
            // We need to determine if we're being called to really deserialize a SafeSerializationManager,
            // or if we're being called because we've intercepted the deserialization callback for the real
            // object being deserialized.  We use the presence of the RealTypeSerializationName field in the
            // serialization info to indicate that this is the interception callback and we just need to
            // safe the info.  If that field is not present, then we should be in a real deserialization
            // construction.
            RuntimeType realType = info.GetValueNoThrow(RealTypeSerializationName, typeof(RuntimeType)) as RuntimeType;

            if (realType == null)
            {
                m_serializedStates = info.GetValue("m_serializedStates", typeof(List <object>)) as List <object>;
            }
            else
            {
                m_realType = realType;
                m_savedSerializationInfo = info;
            }
        }
Ejemplo n.º 11
0
        internal MemberInfoSerializationHolder(SerializationInfo info, StreamingContext context) 
        {
            if (info == null)
                throw new ArgumentNullException(nameof(info));
            Contract.EndContractBlock();

            String assemblyName = info.GetString("AssemblyName");
            String typeName = info.GetString("ClassName");
            
            if (assemblyName == null || typeName == null)
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));

            Assembly assem = FormatterServices.LoadAssemblyFromString(assemblyName);
            m_reflectedType = assem.GetType(typeName, true, false) as RuntimeType;
            m_memberName = info.GetString("Name");
            m_signature = info.GetString("Signature");
            // Only v4.0 and later generates and consumes Signature2
            m_signature2 = (string)info.GetValueNoThrow("Signature2", typeof(string));
            m_memberType = (MemberTypes)info.GetInt32("MemberType");
            m_info = info;
        }
Ejemplo n.º 12
0
			public Delegate DeserializeDelegate (SerializationInfo info, int index)
			{
				object realTarget = null;
				if (target != null)
					realTarget = info.GetValue (target.ToString(), typeof(object));

				var key = "method" + index;
				var method = (MethodInfo)info.GetValueNoThrow (key, typeof(MethodInfo));

				Assembly dasm = Assembly.Load (assembly);
				Type dt = dasm.GetType (type);

				if (realTarget != null) {
#if !DISABLE_REMOTING
					if (RemotingServices.IsTransparentProxy (realTarget)) {
						// The call to IsInstanceOfType will force the proxy
						// to load the real type of the remote object. This is
						// needed to make sure that subsequent calls to
						// GetType() return the expected type.
						Assembly tasm = Assembly.Load (targetTypeAssembly);
						Type tt = tasm.GetType (targetTypeName);
						if (!tt.IsInstanceOfType (realTarget))
							throw new RemotingException ("Unexpected proxy type.");
					}
#endif
					return method == null ?
						Delegate.CreateDelegate (dt, realTarget, methodName) :
						Delegate.CreateDelegate (dt, realTarget, method);
				}

				if (method != null)
					return Delegate.CreateDelegate (dt, realTarget, method);

				Type tt2 = Assembly.Load (targetTypeAssembly).GetType (targetTypeName);
				return Delegate.CreateDelegate (dt, tt2, methodName);
			}
Ejemplo n.º 13
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        protected SecurityException(SerializationInfo info, StreamingContext context) : base (info, context)
        {
            if (info==null) 
                throw new ArgumentNullException("info");
            Contract.EndContractBlock(); 
 
            try
            { 
                m_action = (SecurityAction)info.GetValue(ActionName, typeof(SecurityAction));
                m_permissionThatFailed = (String)info.GetValueNoThrow(FirstPermissionThatFailedName, typeof(String));
                m_demanded = (String)info.GetValueNoThrow(DemandedName, typeof(String));
                m_granted = (String)info.GetValueNoThrow(GrantedSetName, typeof(String)); 
                m_refused = (String)info.GetValueNoThrow(RefusedSetName, typeof(String));
                m_denied = (String)info.GetValueNoThrow(DeniedName, typeof(String)); 
                m_permitOnly = (String)info.GetValueNoThrow(PermitOnlyName, typeof(String)); 
                m_assemblyName = (AssemblyName)info.GetValueNoThrow(Assembly_Name, typeof(AssemblyName));
                m_serializedMethodInfo = (byte[])info.GetValueNoThrow(MethodName_Serialized, typeof(byte[])); 
                m_strMethodInfo = (String)info.GetValueNoThrow(MethodName_String, typeof(String));
                m_zone = (SecurityZone)info.GetValue(ZoneName, typeof(SecurityZone));
                m_url = (String)info.GetValueNoThrow(UrlName, typeof(String));
            } 
            catch
            { 
                m_action = 0; 
                m_permissionThatFailed = "";
                m_demanded = ""; 
                m_granted = "";
                m_refused = "";
                m_denied = "";
                m_permitOnly = ""; 
                m_assemblyName = null;
                m_serializedMethodInfo = null; 
                m_strMethodInfo = null; 
                m_zone = SecurityZone.NoZone;
                m_url = ""; 
            }
        }
Ejemplo n.º 14
0
        [System.Security.SecurityCritical]  // auto-generated
        private DelegateSerializationHolder(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
                throw new ArgumentNullException("info");
            Contract.EndContractBlock();
    
            bool bNewWire = true;

            try
            {
                m_delegateEntry = (DelegateEntry)info.GetValue("Delegate", typeof(DelegateEntry));
            }
            catch
            {
                // Old wire format
                m_delegateEntry = OldDelegateWireFormat(info, context);
                bNewWire = false;
            }

            if (bNewWire)
            {
                // retrieve the targets
                DelegateEntry deiter = m_delegateEntry;
                int count = 0;
                while (deiter != null)
                {
                    if (deiter.target != null)
                    {
                        string stringTarget = deiter.target as string; //need test to pass older wire format
                        if (stringTarget != null)
                            deiter.target = info.GetValue(stringTarget, typeof(Object));
                    }
                    count++;
                    deiter = deiter.delegateEntry;
                }

                // If the sender is as recent as us they'll have provided MethodInfos for each delegate. Look for these and pack
                // them into an ordered array if present.
                MethodInfo[] methods = new MethodInfo[count];
                int i;
                for (i = 0; i < count; i++)
                {
                    String methodInfoName = "method" + i;
                    methods[i] = (MethodInfo)info.GetValueNoThrow(methodInfoName, typeof(MethodInfo));
                    if (methods[i] == null)
                        break;
                }

                // If we got the info then make the array available for deserialization.
                if (i == count)
                    m_methods = methods;
            }
        }
        private SafeSerializationManager(SerializationInfo info, StreamingContext context)
        {
            // We need to determine if we're being called to really deserialize a SafeSerializationManager,
            // or if we're being called because we've intercepted the deserialization callback for the real
            // object being deserialized.  We use the presence of the RealTypeSerializationName field in the
            // serialization info to indicate that this is the interception callback and we just need to
            // safe the info.  If that field is not present, then we should be in a real deserialization
            // construction.
            RuntimeType realType = info.GetValueNoThrow(RealTypeSerializationName, typeof(RuntimeType)) as RuntimeType;

            if (realType == null)
            {
                m_serializedStates = info.GetValue("m_serializedStates", typeof(List<object>)) as List<object>;
            }
            else
            {
                m_realType = realType;
                m_savedSerializationInfo = info;
            }
        }
Ejemplo n.º 16
0
        protected Exception(SerializationInfo info, StreamingContext context) 
        {
            if (info==null)
                throw new ArgumentNullException("info");
    
            _className = info.GetString("ClassName");
            _message = info.GetString("Message");
            _data = (IDictionary)(info.GetValueNoThrow("Data",typeof(IDictionary)));
            _innerException = (Exception)(info.GetValue("InnerException",typeof(Exception)));
            _helpURL = info.GetString("HelpURL");
            _stackTraceString = info.GetString("StackTraceString");
            _remoteStackTraceString = info.GetString("RemoteStackTraceString");
            _remoteStackIndex = info.GetInt32("RemoteStackIndex");

            _exceptionMethodString = (String)(info.GetValue("ExceptionMethod",typeof(String)));
            HResult = info.GetInt32("HResult");
            _source = info.GetString("Source");
    
            if (_className == null || HResult==0)
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
            
            // If we are constructing a new exception after a cross-appdomain call...
            if (context.State == StreamingContextStates.CrossAppDomain)
            {
                // ...this new exception may get thrown.  It is logically a re-throw, but 
                //  physically a brand-new exception.  Since the stack trace is cleared 
                //  on a new exception, the "_remoteStackTraceString" is provided to 
                //  effectively import a stack trace from a "remote" exception.  So,
                //  move the _stackTraceString into the _remoteStackTraceString.  Note
                //  that if there is an existing _remoteStackTraceString, it will be 
                //  preserved at the head of the new string, so everything works as 
                //  expected.
                // Even if this exception is NOT thrown, things will still work as expected
                //  because the StackTrace property returns the concatenation of the
                //  _remoteStackTraceString and the _stackTraceString.
                _remoteStackTraceString = _remoteStackTraceString + _stackTraceString;
                _stackTraceString = null;
            }

        }