private static bool IsExecuteMessageValid2(MemberInfo m) { if (ReflectionCache.ConvertToInterfaceMI(m) == null) { return(false); } MethodInfo info2 = m as MethodInfo; if (info2 == null) { return(false); } foreach (ParameterInfo info3 in info2.GetParameters()) { if (!IsTypeExecuteMethodValid(info3.ParameterType)) { return(false); } } if (!IsTypeExecuteMethodValid(info2.ReturnType)) { return(false); } return(true); }
private IMessage CrossCtxInvoke(IMessage reqMsg) { IMessage message = null; this.AssertValid(); message = this.HandleDispose(reqMsg); if (message != null) { return(message); } message = this.HandleSetCOMIUnknown(reqMsg); if (message != null) { return(message); } message = this.HandleSpecialMethods(reqMsg); if (message != null) { return(message); } object transparentProxy = this.GetTransparentProxy(); MethodBase methodBase = ((IMethodMessage)reqMsg).MethodBase; MemberInfo mi = methodBase; MemberInfo mb = mi; MemberInfo info3 = null; MemberInfo m = ReflectionCache.ConvertToClassMI(base.GetProxiedType(), mi); bool fIsAutoDone = false; int num = ServicedComponentInfo.MICachedLookup(m); if (reqMsg is IConstructionCallMessage) { ComMemberType method = ComMemberType.Method; mb = Marshal.GetMethodInfoForComSlot(typeof(IManagedObject), 3, ref method); } else { info3 = this.AliasCall(methodBase as MethodInfo); if (info3 != null) { mb = info3; } else if (this._fUseIntfDispatch || ((num & 4) != 0)) { mb = ReflectionCache.ConvertToInterfaceMI(mi); if (mb == null) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } } else { fIsAutoDone = (num & 2) != 0; } } return(this._callback.DoCallback(transparentProxy, reqMsg, this._context, fIsAutoDone, mb, this._gitCookie != 0)); }
public void CheckAssemblySCValidity(Assembly asm) { Type[] types = null; bool flag = true; ArrayList list = null; RegistrationServices services = new RegistrationServices(); try { types = asm.GetTypes(); } catch (ReflectionTypeLoadException exception) { types = exception.Types; } foreach (Type type in types) { if (((null != type) && type.IsClass) && type.IsSubclassOf(typeof(ServicedComponent))) { if (!services.TypeRequiresRegistration(type) && !type.IsAbstract) { flag = false; if (list == null) { list = new ArrayList(); } RegistrationErrorInfo info = new RegistrationErrorInfo(null, null, type.ToString(), -2147467259); list.Add(info); } ClassInterfaceType classInterfaceType = ServicedComponentInfo.GetClassInterfaceType(type); foreach (MethodInfo info2 in type.GetMethods()) { if (ReflectionCache.ConvertToInterfaceMI(info2) == null) { if (ServicedComponentInfo.HasSpecialMethodAttributes(info2)) { this.ReportWarning(Resource.FormatString("Reg_NoClassInterfaceSecure", type.FullName, info2.Name)); } if ((classInterfaceType == ClassInterfaceType.AutoDispatch) && ServicedComponentInfo.IsMethodAutoDone(info2)) { this.ReportWarning(Resource.FormatString("Reg_NoClassInterface", type.FullName, info2.Name)); } } } } } if (!flag) { RegistrationErrorInfo[] errorInfo = (RegistrationErrorInfo[])list.ToArray(typeof(RegistrationErrorInfo)); throw new RegistrationException(Resource.FormatString("Reg_InvalidServicedComponents"), errorInfo); } }
private bool SendMethodCall(IMessage req) { bool flag = false; if (this._tracker != null) { IntPtr zero = IntPtr.Zero; try { IMethodCallMessage message = req as IMethodCallMessage; if (!this.IsRealCall(message.MethodBase)) { return(false); } if (Util.ExtendedLifetime) { zero = this.SupportsInterface(ref _s_IID_IManagedObjectInfo); } else { zero = this.GetOuterIUnknown(); } MethodBase method = ReflectionCache.ConvertToInterfaceMI(message.MethodBase) as MethodBase; if (method != null) { this._tracker.SendMethodCall(zero, method); flag = true; } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } return(flag); } finally { if (zero != IntPtr.Zero) { Marshal.Release(zero); } } } return(flag); }
// Implement Invoke public override IMessage Invoke(IMessage reqMsg) { AssertValid(); IMessage retMsg = null; // CHECK FOR CTOR if (reqMsg is IConstructionCallMessage) { DBG.Info(DBG.SC, "RSCP: Short circuiting constructor call."); if (((IConstructionCallMessage)reqMsg).ArgCount > 0) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments")); } // WE don't need dispatch the constructor message, the default .ctor is called // by CoCI // Create the return message MarshalByRefObject retObj = (MarshalByRefObject)GetTransparentProxy(); return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, retObj)); } // NON CTOR MESSAGE MethodBase mb = ((IMethodMessage)reqMsg).MethodBase; MemberInfo m = (MemberInfo)mb; DBG.Assert(m != null, "member info should not be null"); if (mb == _getTypeMethod) { DBG.Info(DBG.SC, "RSCP: Hijacking call to GetType"); IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(ProxiedType, null, 0, mcm.LogicalCallContext, mcm)); } if (mb == _getHashCodeMethod) { int hashCode = this.GetHashCode(); DBG.Info(DBG.SC, "RSCP: Hijacking call to GetHashCode, returning " + hashCode); IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(hashCode, null, 0, mcm.LogicalCallContext, mcm)); } DBG.Info(DBG.SC, "RSCP: Delivering call to " + mb.Name); // convert to class member info MemberInfo clsMemInfo = ReflectionCache.ConvertToClassMI(ProxiedType, m); DBG.Assert(!clsMemInfo.ReflectedType.IsInterface, "Failed to convert interface member info to class member info"); // dispatch the call #if _DEBUG if (clsMemInfo != m) { DBG.Info(DBG.SC, "RSCP: converted interface to class call: " + clsMemInfo.Name); } #endif try { int iMethodInfo; // check for rolebased security if (_fUseIntfDispatch || (((iMethodInfo = ServicedComponentInfo.MICachedLookup(clsMemInfo)) & ServicedComponentInfo.MI_HASSPECIALATTRIBUTES) != 0) || ((iMethodInfo & ServicedComponentInfo.MI_EXECUTEMESSAGEVALID) != 0) ) { // role based security implies we dispatch through an interface MemberInfo intfMemInfo = ReflectionCache.ConvertToInterfaceMI(m); if (intfMemInfo == null) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } //retMsg = EnterpriseServicesHelper.DispatchRemoteCall(reqMsg, intfMemInfo, _server); MethodCallMessageWrapperEx msgex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)intfMemInfo); retMsg = RemotingServices.ExecuteMessage((MarshalByRefObject)_server, (IMethodCallMessage)msgex); } else { // check for AutoDone bool fAutoDone = (iMethodInfo & ServicedComponentInfo.MI_AUTODONE) != 0; String s = ComponentServices.ConvertToString(reqMsg); IRemoteDispatch iremDisp = (IRemoteDispatch)_server; String sret; if (fAutoDone) { sret = iremDisp.RemoteDispatchAutoDone(s); } else { sret = iremDisp.RemoteDispatchNotAutoDone(s); } retMsg = ComponentServices.ConvertToReturnMessage(sret, reqMsg); } } catch (COMException e) { if (!(e.ErrorCode == Util.CONTEXT_E_ABORTED || e.ErrorCode == Util.CONTEXT_E_ABORTING)) { throw; } if (IsDisposeRequest(reqMsg)) { IMethodCallMessage mcm = reqMsg as IMethodCallMessage; retMsg = new ReturnMessage(null, null, 0, mcm.LogicalCallContext, mcm); } else { throw; } } // if disposing, we need to release this side of the world. if (IsDisposeRequest(reqMsg)) { Dispose(true); } return(retMsg); }
public override IMessage Invoke(IMessage reqMsg) { this.AssertValid(); IMessage message = null; if (reqMsg is IConstructionCallMessage) { if (((IConstructionCallMessage)reqMsg).ArgCount > 0) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments")); } MarshalByRefObject transparentProxy = (MarshalByRefObject)this.GetTransparentProxy(); return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, transparentProxy)); } MethodBase methodBase = ((IMethodMessage)reqMsg).MethodBase; MemberInfo mi = methodBase; if (methodBase == _getTypeMethod) { IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(this.ProxiedType, null, 0, mcm.LogicalCallContext, mcm)); } if (methodBase == _getHashCodeMethod) { int hashCode = this.GetHashCode(); IMethodCallMessage message3 = (IMethodCallMessage)reqMsg; return(new ReturnMessage(hashCode, null, 0, message3.LogicalCallContext, message3)); } if (methodBase == _isInstanceOfTypeMethod) { IMethodCallMessage message4 = (IMethodCallMessage)reqMsg; Type inArg = (Type)message4.GetInArg(0); return(new ReturnMessage(inArg.IsInstanceOfType(this.ProxiedType), null, 0, message4.LogicalCallContext, message4)); } MemberInfo m = ReflectionCache.ConvertToClassMI(this.ProxiedType, mi); try { int num2; if ((this._fUseIntfDispatch || (((num2 = ServicedComponentInfo.MICachedLookup(m)) & 4) != 0)) || ((num2 & 8) != 0)) { MemberInfo info3 = ReflectionCache.ConvertToInterfaceMI(mi); if (info3 == null) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } MethodCallMessageWrapperEx ex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)info3); message = RemotingServices.ExecuteMessage((MarshalByRefObject)this._server, ex); } else { string str2; bool flag = (num2 & 2) != 0; string s = ComponentServices.ConvertToString(reqMsg); IRemoteDispatch dispatch = (IRemoteDispatch)this._server; if (flag) { str2 = dispatch.RemoteDispatchAutoDone(s); } else { str2 = dispatch.RemoteDispatchNotAutoDone(s); } message = ComponentServices.ConvertToReturnMessage(str2, reqMsg); } } catch (COMException exception) { if ((exception.ErrorCode != -2147164158) && (exception.ErrorCode != -2147164157)) { throw; } if (!this.IsDisposeRequest(reqMsg)) { throw; } IMethodCallMessage message5 = reqMsg as IMethodCallMessage; message = new ReturnMessage(null, null, 0, message5.LogicalCallContext, message5); } if (this.IsDisposeRequest(reqMsg)) { this.Dispose(true); } return(message); }