コード例 #1
0
        internal static RegistryWatcher WatchKey(RegistryHive registryHive, string subKey, EventHandler oToNotify)
        {
            RegistryWatcher registryWatcher = new RegistryWatcher(registryHive, subKey);

            registryWatcher.KeyChanged += oToNotify;
            registryWatcher.Start();
            return(registryWatcher);
        }
コード例 #2
0
        private void WatchAndNotify()
        {
            IntPtr intPtr;
            int    num = RegistryWatcher.RegOpenKeyEx(this._hiveToWatch, this._sSubKey, 0u, 131089, out intPtr);

            if (num != 0)
            {
                throw new Win32Exception(num);
            }
            try
            {
                AutoResetEvent autoResetEvent = new AutoResetEvent(false);
                WaitHandle[]   waitHandles    = new WaitHandle[]
                {
                    autoResetEvent,
                    this._eventTerminate
                };
                while (!this._eventTerminate.WaitOne(0, true))
                {
                    num = RegistryWatcher.RegNotifyChangeKeyValue(intPtr, false, this._regFilter, autoResetEvent.SafeWaitHandle.DangerousGetHandle(), true);
                    if (num != 0)
                    {
                        throw new Win32Exception(num);
                    }
                    if (WaitHandle.WaitAny(waitHandles) == 0)
                    {
                        this.OnKeyChanged();
                    }
                }
            }
            finally
            {
                if (IntPtr.Zero != intPtr)
                {
                    RegistryWatcher.RegCloseKey(intPtr);
                }
            }
        }
コード例 #3
0
        internal bool Attach(bool bCollectGWInfo)
        {
            if (this._bIsAttached)
            {
                return(true);
            }
            if (CONFIG.bIsViewOnly)
            {
                return(false);
            }
            if (bCollectGWInfo)
            {
                this.CollectConnectoidAndGatewayInfo();
            }
            WinINETProxyInfo winINETProxyInfo = new WinINETProxyInfo();

            winINETProxyInfo.bUseManualProxies = true;
            winINETProxyInfo.bAllowDirect      = true;
            winINETProxyInfo.sHttpProxy        = CONFIG.sFiddlerListenHostPort;
            if (CONFIG.bCaptureCONNECT)
            {
                winINETProxyInfo.sHttpsProxy = CONFIG.sFiddlerListenHostPort;
            }
            else
            {
                if (this.piSystemGateway != null && this.piSystemGateway.bUseManualProxies)
                {
                    winINETProxyInfo.sHttpsProxy = this.piSystemGateway.sHttpsProxy;
                }
            }
            if (CONFIG.bCaptureFTP)
            {
                winINETProxyInfo.sFtpProxy = CONFIG.sFiddlerListenHostPort;
            }
            else
            {
                if (this.piSystemGateway != null && this.piSystemGateway.bUseManualProxies)
                {
                    winINETProxyInfo.sFtpProxy = this.piSystemGateway.sFtpProxy;
                }
            }
            if (this.piSystemGateway != null && this.piSystemGateway.bUseManualProxies)
            {
                winINETProxyInfo.sSocksProxy = this.piSystemGateway.sSocksProxy;
            }
            winINETProxyInfo.sHostsThatBypass = CONFIG.sHostsThatBypassFiddler;
            if (CONFIG.bHookWithPAC)
            {
                if (FiddlerApplication.Prefs.GetBoolPref("fiddler.proxy.pacfile.usefileprotocol", true))
                {
                    winINETProxyInfo.sPACScriptLocation = "file://" + CONFIG.GetPath("Pac");
                }
                else
                {
                    winINETProxyInfo.sPACScriptLocation = "http://" + CONFIG.sFiddlerListenHostPort + "/proxy.pac";
                }
            }
            if (this.oAllConnectoids == null)
            {
                this.CollectConnectoidAndGatewayInfo();
            }
            if (this.oAllConnectoids.HookConnections(winINETProxyInfo))
            {
                this._bIsAttached = true;
                FiddlerApplication.OnFiddlerAttach();
                this.WriteAutoProxyPACFile(true);
                if (this.oRegistryWatcher == null && FiddlerApplication.Prefs.GetBoolPref("fiddler.proxy.WatchRegistry", true))
                {
                    this.oRegistryWatcher = RegistryWatcher.WatchKey(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", new EventHandler(this.ProxyRegistryKeysChanged));
                }
                Proxy._setDynamicRegistryKey(true);
                return(true);
            }
            FiddlerApplication.DoNotifyUser("Failed to register Fiddler as the system proxy.", "Error");
            Proxy._setDynamicRegistryKey(false);
            return(false);
        }