Exemplo n.º 1
0
        private object ReverseObject(object src)
        {
            object      retVal = src;
            ProxyResult prs    = src as ProxyResult;

            if (prs != null)
            {
                var fx = new Func <string, IObjectProxy>(s =>
                {
                    IObjectProxy retObj = null;
                    if (!CustomProxy.IsProxyAvailable(prs.Type))
                    {
                        ObjectProxy proxy = CreateProxyInternal(s, prs.Type);
                        retObj            = proxy.ActLike <IObjectProxy>(prs.Type);
                    }
                    else
                    {
                        retObj = CustomProxy.GetCustomProxy(prs.Type, this, s);
                    }

                    return(retObj);
                });

                retVal = abandonnableProxies.AddOrUpdate(prs.UniqueName, fx, (s, o) => o ?? fx(s));
            }

            return(retVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a proxy object for the requested objectName
        /// </summary>
        /// <typeparam name="T">the Client-interface type for the given objectName</typeparam>
        /// <param name="objectName">the name of the remote-Object to wrap</param>
        /// <returns>a Proxy - object that wraps the requested object</returns>
        public T CreateProxy <T>(string objectName) where T : class
        {
            ObjectAvailabilityResult result;

            try
            {
                result = CheckRemoteObjectAvailability(objectName);
            }
            catch (Exception ex)
            {
                LogEnvironment.LogDebugEvent(
                    null, $"Error checking Object-Availability:",
                    (int)LogSeverity.Error, null);
                LogException(ex, true);
                throw;
            }

            if (!result.Available)
            {
                throw new InvalidOperationException(
                          $"The requested object is not present on the connected service. Server-Message: {result.Message}");
            }

            Type t = typeof(T);

            LogEnvironment.LogDebugEvent(null, $"Creating proxy for Type: {t.FullName}", (int)LogSeverity.Report, null);
            if (!CustomProxy.IsProxyAvailable(typeof(T)))
            {
                ObjectProxy proxy = CreateProxyInternal(objectName, typeof(T));
                LogEnvironment.LogDebugEvent(null, "Proxy successfully created", (int)LogSeverity.Report, null);
                return(proxy.ActLike <T>(typeof(IObjectProxy)));
            }

            return(CustomProxy.GetCustomProxy <T>(this, objectName));
        }
Exemplo n.º 3
0
        public void Test()
        {
            var uesr = CustomProxy <User> .Create(new User());

            uesr.SetUserInfo("joe", "manager");//成功

            try
            {
                uesr.SetUserInfo(20, "manager");
            }
            catch (Exception exception)
            {
                //因第一个参数类型异常被拦截后抛出异常
                //Assert.IsInstanceOf(exception, typeof(ArgumentException));
            }

            try
            {
                uesr.SetUserInfo("", "manager");
            }
            catch (Exception exception)
            {
                //因name为空被拦截后抛出异常
                //Assert.IsInstanceOf(e,typeof(ArgumentException));
            }
        }
Exemplo n.º 4
0
        public void WriteXML(XmlDocument document, XmlElement element)
        {
            XmlElement customProxyElement = document.CreateElement(ourCustomProxyTag);

            customProxyElement.InnerText = CustomProxy.ToString();
            element.AppendChild(customProxyElement);

            XmlElement hostElement = document.CreateElement(ourHostTag);

            hostElement.InnerText = Host.ToString();
            element.AppendChild(hostElement);

            XmlElement portElement = document.CreateElement(ourPortTag);

            portElement.InnerText = Port.ToString();
            element.AppendChild(portElement);

            XmlElement authenticationElement = document.CreateElement(ourAuthenticationTag);

            authenticationElement.InnerText = Authentication.ToString();
            element.AppendChild(authenticationElement);

            XmlElement loginElement = document.CreateElement(ourLoginTag);

            loginElement.InnerText = Login.ToString();
            element.AppendChild(loginElement);

            XmlElement passwordElement = document.CreateElement(ourPasswordTag);

            passwordElement.InnerText = Password.ToString();
            element.AppendChild(passwordElement);
        }
Exemplo n.º 5
0
    public void WatchEvent(Action <T> eventToWatch)
    {
        CustomProxy <T> proxy = new CustomProxy <T>(InvocationType.Event);
        T tester = (T)proxy.GetTransparentProxy();

        eventToWatch(tester);
        Console.WriteLine(string.Format("Event to watch = {0}", proxy.Invocations.First()));
    }
Exemplo n.º 6
0
        public override HttpMessageHandler CreateHttpHandler()
        {
            CustomProxy proxy = new CustomProxy(Proxy);

            proxy.Credentials = Credentials;
            HttpClientHandler handler = new HttpClientHandler();

            handler.Proxy = proxy;
            Utils.SetAntiFingerprint(handler);
            return(handler);
        }
Exemplo n.º 7
0
        public void SendAsync_UseCustomProxyWithBypass_ExpectedWinHttpProxySettings()
        {
            var handler     = new WinHttpHandler();
            var customProxy = new CustomProxy(true);

            SendRequestHelper.Send(
                handler,
                delegate
            {
                handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy;
                handler.Proxy = customProxy;
            });

            Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
            Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.RequestProxySettings.AccessType);
        }
Exemplo n.º 8
0
        public void TrackingAndCustomProxy()
        {
            TrackingServices.RegisterTrackingHandler(new TrackingHandler());

            var channel = new TcpChannel(8080);
            ChannelServices.RegisterChannel(channel, false);
            var service = new ServiceClass();
            ObjRef obj = RemotingServices.Marshal(service, "TcpService");

            var url="tcp://localhost:8080/TcpService";
            service = RemotingServices.Connect(typeof(ServiceClass), url) as ServiceClass;
            Console.WriteLine("client received: {0}", service.Echo("hello"));

            service = new CustomProxy(typeof(ServiceClass), url).GetTransparentProxy() as ServiceClass;
            Console.WriteLine("client received: {0}", service.Echo("hello"));

            RemotingServices.Unmarshal(obj);
            RemotingServices.Disconnect(service);
        }
Exemplo n.º 9
0
        public void Inject()
        {
            StartupConfiguration configuration = ConfigurationManager.Instance.Startup;

            if (configuration is null)
            {
                logger.Error("startup configuration is null");
                return;
            }

            int port = ProxyPort;

            _hook = new HookElement();
            {
                _hook.IpcServer = RemoteHooking.IpcCreateServer <BotoxHookInterface <T> >(ref _hook.ChannelName, WellKnownObjectMode.Singleton);
            }

            RemoteHooking.CreateAndInject(
                configuration.game_location,
                string.Empty,
                0x00000004,
                InjectionOptions.DoNotRequireStrongName,
                configuration.dll_location,
                configuration.dll_location,
                out _hook.ProcessId,
                _hook.ChannelName,
                port);

            Proxy = new CustomProxy <T>(ProxyPort, _hook.ProcessId);

            Process process = Process.GetProcessById(_hook.ProcessId);

            process.EnableRaisingEvents = true;

            if (process.WaitForInputIdle())
            {
                logger.Info($"process opened : {process.ProcessName} {process.Id}");
                OnProcessStarted?.Invoke(this);
            }

            process.Exited += Process_Exited;
        }
        public void TrackingAndCustomProxy()
        {
            TrackingServices.RegisterTrackingHandler(new TrackingHandler());

            var channel = new TcpChannel(8080);

            ChannelServices.RegisterChannel(channel, false);
            var    service = new ServiceClass();
            ObjRef obj     = RemotingServices.Marshal(service, "TcpService");

            var url = "tcp://localhost:8080/TcpService";

            service = RemotingServices.Connect(typeof(ServiceClass), url) as ServiceClass;
            Console.WriteLine("client received: {0}", service.Echo("hello"));

            //use custom RealProxy
            service = new CustomProxy(typeof(ServiceClass), url).GetTransparentProxy() as ServiceClass;
            Console.WriteLine("client received: {0}", service.Echo("hello"));

            RemotingServices.Unmarshal(obj);
            RemotingServices.Disconnect(service);
        }
Exemplo n.º 11
0
        public void SendAsync_UseCustomProxyWithBypass_ExpectedWinHttpProxySettings()
        {
            var handler = new WinHttpHandler();
            var customProxy = new CustomProxy(true);

            SendRequestHelper.Send(
                handler,
                delegate
                {
                    handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy;
                    handler.Proxy = customProxy;
                });

            Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
            Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.RequestProxySettings.AccessType);
        }