public static void Clear()
 {
     _instance = null;
     if (_clearActions==null)
         return;
     _clearActions.ForEach(a => a());
 }
        public static ProxyModule GetProxyModule()
        {
            if (_instance!=null)
                return _instance;

            _instance = ProxyFooPolicies.CreateProxyModule();
            return _instance;
        }
Example #3
0
 public static void Clear()
 {
     _instance = null;
     if (_clearActions == null)
     {
         return;
     }
     _clearActions.ForEach(a => a());
 }
Example #4
0
        public static ProxyModule GetProxyModule()
        {
            if (_instance != null)
            {
                return(_instance);
            }

            _instance = ProxyFooPolicies.CreateProxyModule();
            return(_instance);
        }
Example #5
0
        public void CustomFactoryIsStoredPerProxyModule()
        {
            CustomFactory.Register();
            Assert.That(CustomFactory.Default, Is.Not.Null);
            var proxyModule   = new ProxyModule();
            var customFactory = CustomFactory.FromProxyModule(proxyModule);

            Assert.That(customFactory, Is.Not.Null);
            Assert.That(customFactory, Is.Not.SameAs(CustomFactory.Default));
            ProxyFooPolicies.ClearProxyModule();
            Assert.That(CustomFactory.IsClear);
            Assert.That(CustomFactory.FromProxyModule(proxyModule), Is.Not.Null);
        }
Example #6
0
        public object GetOrCreateFrom(ProxyModule proxyModule, Func<ProxyModule, object> factoryCtor)
        {
            if (_regIndex==0)
                throw new InvalidOperationException("Factory type is not registered.");

            var factory = Get(proxyModule);
            if (factory==null)
            {
                factory = factoryCtor(proxyModule);
                Set(proxyModule, factory);
            }
            return factory;
        }
Example #7
0
        public void CustomGetDefaultFuncIsCalled()
        {
            var  proxyModule = new ProxyModule();
            bool getCalled   = false;

            ProxyFooPolicies.GetDefaultProxyModule = () =>
            {
                getCalled = true;
                return(proxyModule);
            };
            Assert.That(ProxyModule.Default, Is.SameAs(proxyModule));
            Assert.That(getCalled);
            ProxyFooPolicies.GetDefaultProxyModule = OnDemandProxyModule.GetProxyModule;
        }
Example #8
0
        public object GetOrCreateFrom(ProxyModule proxyModule, Func <ProxyModule, object> factoryCtor)
        {
            if (_regIndex == 0)
            {
                throw new InvalidOperationException("Factory type is not registered.");
            }

            var factory = Get(proxyModule);

            if (factory == null)
            {
                factory = factoryCtor(proxyModule);
                Set(proxyModule, factory);
            }
            return(factory);
        }
Example #9
0
 object Get(ProxyModule proxyModule)
 {
     return proxyModule.GetFactory(_regIndex - 1);
 }
Example #10
0
 public static CustomFactory FromProxyModule(ProxyModule proxyModule)
 {
     return (CustomFactory)_accessor.GetOrCreateFrom(proxyModule, pm => new CustomFactory());
 }
Example #11
0
 public void CustomGetDefaultFuncIsCalled()
 {
     var proxyModule = new ProxyModule();
     bool getCalled = false;
     ProxyFooPolicies.GetDefaultProxyModule = () =>
     {
         getCalled = true;
         return proxyModule;
     };
     Assert.That(ProxyModule.Default, Is.SameAs(proxyModule));
     Assert.That(getCalled);
     ProxyFooPolicies.GetDefaultProxyModule = OnDemandProxyModule.GetProxyModule;
 }
Example #12
0
 public void CustomFactoryIsStoredPerProxyModule()
 {
     CustomFactory.Register();
     Assert.That(CustomFactory.Default, Is.Not.Null);
     var proxyModule = new ProxyModule();
     var customFactory = CustomFactory.FromProxyModule(proxyModule);
     Assert.That(customFactory, Is.Not.Null);
     Assert.That(customFactory, Is.Not.SameAs(CustomFactory.Default));
     ProxyFooPolicies.ClearProxyModule();
     Assert.That(CustomFactory.IsClear);
     Assert.That(CustomFactory.FromProxyModule(proxyModule), Is.Not.Null);
 }
 public MethodIndexFactory(ProxyModule proxyModule)
 {
     _proxyModule = proxyModule;
 }
 public static MethodIndexFactory FromProxyModule(ProxyModule proxyModule)
 {
     return((MethodIndexFactory)_accessor.GetOrCreateFrom(proxyModule, pm => new MethodIndexFactory(pm)));
 }
Example #15
0
 void Set(ProxyModule proxyModule, object factory)
 {
     proxyModule.SetFactory(_regIndex - 1, factory);
 }
Example #16
0
 void Set(ProxyModule proxyModule, object factory)
 {
     proxyModule.SetFactory(_regIndex - 1, factory);
 }
Example #17
0
        public void ReConfig(bool silent, bool?forceState = null)
        {
            bool isListenerActive = this.listener != null &&
                                    this.listener.Status.HasFlag(ProxyController.ControllerStatus.Proxy);

            if (!forceState.HasValue || !forceState.Value)
            {
                if (!isListenerActive)
                {
                    ProxyModule.DisableProxy();
                    ProxyModule.DisableProxyAutoConfig();
                }

                if (isListenerActive && TapTunnelModule.IsRunning())
                {
                    TapTunnelModule.StopTunnel();
                }
                TapTunnelModule.CleanAllTunnelProcesses();

                if (isListenerActive && HookModule.IsHookProcessRunning())
                {
                    HookModule.StopHookProcess();
                }
                HookModule.CleanAllHookProcesses();
            }

            if ((forceState.HasValue && !forceState.Value) || !isListenerActive)
            {
                return;
            }

            switch ((GrabberType)Settings.Default.Grabber)
            {
            case GrabberType.Proxy:
                bool res        = ProxyModule.SetActiveProxy(new IPEndPoint(IPAddress.Loopback, this.listener.Port));
                bool firefoxRes = ProxyModule.ForceFirefoxToUseSystemSettings();

                if (!res)
                {
                    if (silent)
                    {
                        Program.Notify.ShowBalloonTip(
                            5000,
                            "Proxy Grabber",
                            "We failed to register PeaRoxy as active proxy for this system. You may need to do it manually or restart/re-logon your PC and let us try again.",
                            ToolTipIcon.Warning);
                    }
                    else
                    {
                        if (VDialog.Show(
                                this,
                                "We failed to register PeaRoxy as active proxy for this system. You may need to do it manually or restart/re-logon your PC and let us try again.\r\nDo want us to logoff your user account?! Please save your work in other applications before making a decision.",
                                "Proxy Grabber",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            WinCommon.LogOffUser();
                        }
                    }
                }
                else
                {
                    if (firefoxRes)
                    {
                        Program.Notify.ShowBalloonTip(
                            5000,
                            "Proxy Grabber",
                            "PeaRoxy successfully registered as active proxy of this system. You may need to restart your browser to be able to use it along with PeaRoxy.",
                            ToolTipIcon.Info);
                    }
                    else
                    {
                        Program.Notify.ShowBalloonTip(
                            5000,
                            "Proxy Grabber",
                            "PeaRoxy successfully registered as active proxy of this system. Firefox probably need some manual configurations, also you may need to restart your browser to be able to use it along with PeaRoxy.",
                            ToolTipIcon.Warning);
                    }
                }

                break;

            case GrabberType.Tap:
                if (this.listener != null && this.listener.Status.HasFlag(ProxyController.ControllerStatus.Proxy))
                {
                    TapTunnelModule.AdapterAddressRange     = IPAddress.Parse(Settings.Default.TAP_IPRange);
                    TapTunnelModule.DnsResolvingAddress     = IPAddress.Loopback;
                    TapTunnelModule.SocksProxyEndPoint      = new IPEndPoint(IPAddress.Loopback, this.listener.Port);
                    TapTunnelModule.AutoDnsResolving        = true;
                    TapTunnelModule.AutoDnsResolvingAddress = IPAddress.Parse(Settings.Default.DNS_IPAddress);
                    TapTunnelModule.TunnelName = "ZARA Tunnel";

                    if (TapTunnelModule.StartTunnel())
                    {
                        Program.Notify.ShowBalloonTip(
                            5000,
                            "TAP Grabber",
                            "TAP Adapter activated successfully. You are ready to go.",
                            ToolTipIcon.Info);
                    }
                    else
                    {
                        TapTunnelModule.StopTunnel();
                        if (silent)
                        {
                            Program.Notify.ShowBalloonTip(
                                5000,
                                "TAP Grabber",
                                "Failed to start TAP Adapter. Tap grabber disabled. Please go to control panel to see if network adapter is disable.",
                                ToolTipIcon.Warning);
                        }
                        else
                        {
                            VDialog.Show(
                                this,
                                "Failed to start TAP Adapter. Tap grabber disabled. Please go to control panel to see if network adapter is disable.",
                                "TAP Grabber",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                        }
                    }
                }
                break;

            case GrabberType.Hook:
                HookModule.StartHookProcess(
                    Settings.Default.Hook_Processes.Split(
                        new[] { Environment.NewLine },
                        StringSplitOptions.RemoveEmptyEntries),
                    new IPEndPoint(IPAddress.Loopback, this.listener.Port),
                    string.Empty);

                Program.Notify.ShowBalloonTip(
                    5000,
                    "Hook Grabber",
                    "Hook process started successfully and actively monitor running applications from now on. You are ready to go.",
                    ToolTipIcon.Info);
                break;
            }
        }
Example #18
0
 public static CustomFactory FromProxyModule(ProxyModule proxyModule)
 {
     return((CustomFactory)_accessor.GetOrCreateFrom(proxyModule, pm => new CustomFactory()));
 }
Example #19
0
        public static ISubjectMethodExists <T> SubjectMethodExistsFactory <T>(ProxyModule proxyModule, Type realSubjectType) where T : class
        {
            var duckFactory = DuckFactory.FromProxyModule(proxyModule);

            return(duckFactory.MakeSubjectMethodExistsForDuckProxy <T>(realSubjectType));
        }
Example #20
0
 object Get(ProxyModule proxyModule)
 {
     return(proxyModule.GetFactory(_regIndex - 1));
 }