コード例 #1
0
        protected static object FixupArg(object arg, ref ArrayList argsToSerialize)
        {
            int count;

            if (arg == null)
            {
                return(null);
            }
            MarshalByRefObject proxy = arg as MarshalByRefObject;

            if (proxy != null)
            {
                if (!RemotingServices.IsTransparentProxy(proxy) || (RemotingServices.GetRealProxy(proxy) is RemotingProxy))
                {
                    ObjRef ref2 = RemotingServices.MarshalInternal(proxy, null, null);
                    if (ref2.CanSmuggle())
                    {
                        if (!RemotingServices.IsTransparentProxy(proxy))
                        {
                            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(proxy);
                            identity.SetHandle();
                            ref2.SetServerIdentity(identity.GetHandle());
                            ref2.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ObjRef objRef = ref2.CreateSmuggleableCopy();
                        objRef.SetMarshaledObject();
                        return(new SmuggledObjRef(objRef));
                    }
                }
                if (argsToSerialize == null)
                {
                    argsToSerialize = new ArrayList();
                }
                count = argsToSerialize.Count;
                argsToSerialize.Add(arg);
                return(new SerializedArg(count));
            }
            if (CanSmuggleObjectDirectly(arg))
            {
                return(arg);
            }
            Array array = arg as Array;

            if (array != null)
            {
                Type elementType = array.GetType().GetElementType();
                if (elementType.IsPrimitive || (elementType == typeof(string)))
                {
                    return(array.Clone());
                }
            }
            if (argsToSerialize == null)
            {
                argsToSerialize = new ArrayList();
            }
            count = argsToSerialize.Count;
            argsToSerialize.Add(arg);
            return(new SerializedArg(count));
        }
コード例 #2
0
        protected static object FixupArg(object arg, ref ArrayList argsToSerialize)
        {
            if (arg == null)
            {
                return((object)null);
            }
            if (arg is MarshalByRefObject marshalByRefObject)
            {
                if (!RemotingServices.IsTransparentProxy((object)marshalByRefObject) || RemotingServices.GetRealProxy((object)marshalByRefObject) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal(marshalByRefObject, (string)null, (Type)null);
                    if (objRef.CanSmuggle())
                    {
                        if (!RemotingServices.IsTransparentProxy((object)marshalByRefObject))
                        {
                            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(marshalByRefObject);
                            identity.SetHandle();
                            objRef.SetServerIdentity(identity.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ObjRef smuggleableCopy = objRef.CreateSmuggleableCopy();
                        smuggleableCopy.SetMarshaledObject();
                        return((object)new SmuggledObjRef(smuggleableCopy));
                    }
                }
                if (argsToSerialize == null)
                {
                    argsToSerialize = new ArrayList();
                }
                int count = argsToSerialize.Count;
                argsToSerialize.Add(arg);
                return((object)new MessageSmuggler.SerializedArg(count));
            }
            if (MessageSmuggler.CanSmuggleObjectDirectly(arg))
            {
                return(arg);
            }
            if (arg is Array array)
            {
                Type elementType = array.GetType().GetElementType();
                if (elementType.IsPrimitive || elementType == typeof(string))
                {
                    return(array.Clone());
                }
            }
            if (argsToSerialize == null)
            {
                argsToSerialize = new ArrayList();
            }
            int count1 = argsToSerialize.Count;

            argsToSerialize.Add(arg);
            return((object)new MessageSmuggler.SerializedArg(count1));
        }
コード例 #3
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
        {
            Type   objectType = null;
            object retObj     = null;

            if (RemotingServices.IsTransparentProxy(serObj))
            {
                objectType = typeof(MarshalByRefObject);
            }
            else
            {
                objectType = serObj.GetType();
            }

            SerializationInfo si = new SerializationInfo(objectType, s_converter);

            if (serObj is ObjRef)
            {
                s_ObjRefRemotingSurrogate.GetObjectData(serObj, si, s_cloneContext);
            }
            else if (RemotingServices.IsTransparentProxy(serObj) || serObj is MarshalByRefObject)
            {
#if !MONO
                // We can only try to smuggle objref's for actual CLR objects
                //   or for RemotingProxy's.
                if (!RemotingServices.IsTransparentProxy(serObj) ||
                    RemotingServices.GetRealProxy(serObj) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, null, null);
                    if (objRef.CanSmuggle())
                    {
                        if (RemotingServices.IsTransparentProxy(serObj))
                        {
                            RealProxy rp = RemotingServices.GetRealProxy(serObj);
                            objRef.SetServerIdentity(rp._srvIdentity);
                            objRef.SetDomainID(rp._domainID);
                        }
                        else
                        {
                            ServerIdentity srvId = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
                            srvId.SetHandle();
                            objRef.SetServerIdentity(srvId.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        objRef.SetMarshaledObject();
                        retObj = objRef;
                    }
                }
#endif
                if (retObj == null)
                {
                    // Deal with the non-smugglable remoting objects
                    s_RemotingSurrogate.GetObjectData(serObj, si, s_cloneContext);
                }
            }
            else if (serObj is ISerializable)
            {
                ((ISerializable)serObj).GetObjectData(si, s_cloneContext);
            }
            else
            {
                // Getting here means a bug in cloner
                throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
            }

            if (retObj == null)
            {
                typeName    = si.FullTypeName;
                assemName   = si.AssemblyName;
                fieldNames  = si.MemberNames;
                fieldValues = si.MemberValues;
            }
            else
            {
                typeName    = null;
                assemName   = null;
                fieldNames  = null;
                fieldValues = null;
            }

            return(retObj);
        }
コード例 #4
0
        internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
        {
            object            obj  = (object)null;
            SerializationInfo info = new SerializationInfo(!RemotingServices.IsTransparentProxy(serObj) ? serObj.GetType() : typeof(MarshalByRefObject), ObjectCloneHelper.s_converter);

            if (serObj is ObjRef)
            {
                ObjectCloneHelper.s_ObjRefRemotingSurrogate.GetObjectData(serObj, info, ObjectCloneHelper.s_cloneContext);
            }
            else if (RemotingServices.IsTransparentProxy(serObj) || serObj is MarshalByRefObject)
            {
                if (!RemotingServices.IsTransparentProxy(serObj) || RemotingServices.GetRealProxy(serObj) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, (string)null, (Type)null);
                    if (objRef.CanSmuggle())
                    {
                        if (RemotingServices.IsTransparentProxy(serObj))
                        {
                            RealProxy realProxy = RemotingServices.GetRealProxy(serObj);
                            objRef.SetServerIdentity(realProxy._srvIdentity);
                            objRef.SetDomainID(realProxy._domainID);
                        }
                        else
                        {
                            ServerIdentity serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
                            serverIdentity.SetHandle();
                            objRef.SetServerIdentity(serverIdentity.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        objRef.SetMarshaledObject();
                        obj = (object)objRef;
                    }
                }
                if (obj == null)
                {
                    ObjectCloneHelper.s_RemotingSurrogate.GetObjectData(serObj, info, ObjectCloneHelper.s_cloneContext);
                }
            }
            else
            {
                if (!(serObj is ISerializable))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
                }
                ((ISerializable)serObj).GetObjectData(info, ObjectCloneHelper.s_cloneContext);
            }
            if (obj == null)
            {
                typeName    = info.FullTypeName;
                assemName   = info.AssemblyName;
                fieldNames  = info.MemberNames;
                fieldValues = info.MemberValues;
            }
            else
            {
                typeName    = (string)null;
                assemName   = (string)null;
                fieldNames  = (string[])null;
                fieldValues = (object[])null;
            }
            return(obj);
        }
コード例 #5
0
        internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
        {
            Type   type = null;
            object obj2 = null;

            if (RemotingServices.IsTransparentProxy(serObj))
            {
                type = typeof(MarshalByRefObject);
            }
            else
            {
                type = serObj.GetType();
            }
            SerializationInfo info = new SerializationInfo(type, s_converter);

            if (serObj is ObjRef)
            {
                s_ObjRefRemotingSurrogate.GetObjectData(serObj, info, s_cloneContext);
            }
            else if (RemotingServices.IsTransparentProxy(serObj) || (serObj is MarshalByRefObject))
            {
                if (!RemotingServices.IsTransparentProxy(serObj) || (RemotingServices.GetRealProxy(serObj) is RemotingProxy))
                {
                    ObjRef ref2 = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, null, null);
                    if (ref2.CanSmuggle())
                    {
                        if (RemotingServices.IsTransparentProxy(serObj))
                        {
                            RealProxy realProxy = RemotingServices.GetRealProxy(serObj);
                            ref2.SetServerIdentity(realProxy._srvIdentity);
                            ref2.SetDomainID(realProxy._domainID);
                        }
                        else
                        {
                            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
                            identity.SetHandle();
                            ref2.SetServerIdentity(identity.GetHandle());
                            ref2.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ref2.SetMarshaledObject();
                        obj2 = ref2;
                    }
                }
                if (obj2 == null)
                {
                    s_RemotingSurrogate.GetObjectData(serObj, info, s_cloneContext);
                }
            }
            else
            {
                if (!(serObj is ISerializable))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
                }
                ((ISerializable)serObj).GetObjectData(info, s_cloneContext);
            }
            if (obj2 == null)
            {
                typeName    = info.FullTypeName;
                assemName   = info.AssemblyName;
                fieldNames  = info.MemberNames;
                fieldValues = info.MemberValues;
                return(obj2);
            }
            typeName    = null;
            assemName   = null;
            fieldNames  = null;
            fieldValues = null;
            return(obj2);
        }
コード例 #6
0
        } // FixupArgs

        protected static Object FixupArg(Object arg, ref ArrayList argsToSerialize)
        {
            // This method examines an argument and sees if it can be smuggled in some form.
            //   If it can directly be smuggled (i.e. it is a primitive or string), we
            //   just return the same object. If it's a marshal by ref object, we
            //   see if we can smuggle the obj ref. If it's a primitive or string array,
            //   we can smuggle a cloned copy of the array. In all other cases,
            //   we add it to the list of args we want serialized, and return a
            //   placeholder element (SerializedArg).

            if (arg == null)
            {
                return(null);
            }

            int index;

            // IMPORTANT!!! This should be done first because CanSmuggleObjectDirectly
            //   calls GetType() and that would slow this down.
            MarshalByRefObject mbo = arg as MarshalByRefObject;

            if (mbo != null)
            {
                // We can only try to smuggle objref's for actual CLR objects
                //   or for RemotingProxy's.
                if (!RemotingServices.IsTransparentProxy(mbo) ||
                    RemotingServices.GetRealProxy(mbo) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal(mbo, null, null);
                    if (objRef.CanSmuggle())
                    {
                        if (!RemotingServices.IsTransparentProxy(mbo))
                        {
                            ServerIdentity srvId = (ServerIdentity)MarshalByRefObject.GetIdentity(mbo);
                            srvId.SetHandle();
                            objRef.SetServerIdentity(srvId.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ObjRef smugObjRef = objRef.CreateSmuggleableCopy();
                        smugObjRef.SetMarshaledObject();
                        return(new SmuggledObjRef(smugObjRef));
                    }
                }

                // Add this arg to list of one's to serialize and return a placeholder
                //   since we couldn't smuggle the objref.
                if (argsToSerialize == null)
                {
                    argsToSerialize = new ArrayList();
                }
                index = argsToSerialize.Count;
                argsToSerialize.Add(arg);
                return(new SerializedArg(index));
            }

            if (CanSmuggleObjectDirectly(arg))
            {
                return(arg);
            }

            // if this is a primitive array, we can just make a copy.
            //   (IMPORTANT: We can directly use this copy from the
            //    other app domain, there is no reason to make another
            //    copy once we are on the other side)
            Array array = arg as Array;

            if (array != null)
            {
                Type elementType = array.GetType().GetElementType();
                if (elementType.IsPrimitive || (elementType == typeof(String)))
                {
                    return(array.Clone());
                }
            }


            // Add this arg to list of one's to serialize and return a placeholder.
            if (argsToSerialize == null)
            {
                argsToSerialize = new ArrayList();
            }
            index = argsToSerialize.Count;
            argsToSerialize.Add(arg);
            return(new SerializedArg(index));
        } // FixupArg