// // System.Runtime.Remoting.Messaging.CADMessages.cs // // Author: // Patrik Torstensson // // (C) Patrik Torstensson // // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections; using System.IO; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Proxies; namespace System.Runtime.Remoting.Messaging { internal class CADArgHolder { public int index; public CADArgHolder (int i) { index = i; } } internal class CADObjRef { internal ObjRef objref; internal int SourceDomain; internal byte[] TypeInfo; public CADObjRef (ObjRef o, int sourceDomain) { objref = o; TypeInfo = o.SerializeType (); SourceDomain = sourceDomain; } public string TypeName { get { return objref.TypeInfo.TypeName; } } public string URI { get { return objref.URI; } } } [Serializable] internal class CADMethodRef { Type[] GetTypes (string[] typeArray) { Type[] res = new Type [typeArray.Length]; for (int i = 0; i < typeArray.Length; ++i) res [i] = Type.GetType (typeArray [i], true); return res; } bool ctor; string typeName; string methodName; string[] param_names; string[] generic_arg_names; public MethodBase Resolve () { Type type = Type.GetType (typeName, true); MethodBase sig_cand = null; Type[] param_types = GetTypes (param_names); if (ctor) sig_cand = type.GetConstructor (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, param_types, null); else sig_cand = type.GetMethod (methodName, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, param_types, null); if (sig_cand != null && generic_arg_names != null && !sig_cand.IsGenericMethodDefinition) sig_cand = null; if (sig_cand != null && generic_arg_names != null) sig_cand = ((MethodInfo)sig_cand).MakeGenericMethod (GetTypes (generic_arg_names)); // We have a generic method with parameters that contain generic arguments if (sig_cand == null && generic_arg_names != null) { foreach (var method in type.GetMethods ()) { if (method.Name != methodName) continue; if (!method.IsGenericMethodDefinition || method.GetGenericArguments().Length != generic_arg_names.Length) continue; sig_cand = ((MethodInfo)method).MakeGenericMethod (GetTypes (generic_arg_names)); var parameters = sig_cand.GetParameters (); if (param_names.Length != parameters.Length) continue; for (int i=0; i < parameters.Length; i++) { if (parameters [i].ParameterType.AssemblyQualifiedName != param_names [i]) { sig_cand = null; break; } } if (sig_cand != null) break; } } if (sig_cand == null) throw new RemotingException ($"Method '{methodName}' not found in type '{typeName}'"); return sig_cand; } public CADMethodRef (IMethodMessage msg) { MethodBase method = msg.MethodBase; typeName = method.DeclaringType.AssemblyQualifiedName; ctor = method.IsConstructor; methodName = method.Name; var param_types = method.GetParameters (); param_names = new string [param_types.Length]; for (int i = 0; i < param_types.Length; ++i) param_names [i] = param_types [i].ParameterType.AssemblyQualifiedName; if (!ctor && method.IsGenericMethod) { var ga = method.GetGenericArguments (); generic_arg_names = new string [ga.Length]; for (int i = 0; i < ga.Length; ++i) generic_arg_names [i] = ga [i].AssemblyQualifiedName; } } } internal class CADMessageBase { protected object [] _args; protected byte [] _serializedArgs = null; protected int _propertyCount = 0; protected CADArgHolder _callContext; internal byte[] serializedMethod; public CADMessageBase (IMethodMessage msg) { CADMethodRef methodRef = new CADMethodRef (msg); serializedMethod = CADSerializer.SerializeObject (methodRef).GetBuffer (); } internal MethodBase GetMethod () { CADMethodRef methRef = (CADMethodRef)CADSerializer.DeserializeObjectSafe (serializedMethod); return methRef.Resolve (); } static protected Type [] GetSignature (MethodBase methodBase, bool load) { ParameterInfo[] pars = methodBase.GetParameters (); Type[] signature = new Type [pars.Length]; for (int n=0; n