From 9ba8d5dab8653d1a21415fe6aa81fffc178b796a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E7=8C=BF?= <1083092844@qq.com> Date: Sat, 4 Mar 2023 14:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8E=E9=A1=B9=E7=9B=AE=E6=8E=92=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BarrageGrab/FiddlerProxy.cs | 146 ------------------------------------ 1 file changed, 146 deletions(-) delete mode 100644 BarrageGrab/FiddlerProxy.cs diff --git a/BarrageGrab/FiddlerProxy.cs b/BarrageGrab/FiddlerProxy.cs deleted file mode 100644 index 2fd68bf..0000000 --- a/BarrageGrab/FiddlerProxy.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; -using ColorConsole; -using Fiddler; -using Microsoft.Win32; - -namespace BarrageGrab -{ - /// - /// FiddlerCore 代理程序 - /// - internal class FiddlerProxy : IDisposable - { - bool disposed = false; - public event EventHandler OnWebSocketData; - ConsoleWriter console = new ConsoleWriter(); - - public FiddlerProxy() - { - InitFiddler(); - } - - /// - /// 启动代理监听 - /// - public void Start() - { - FiddlerApplication.Startup(8827, FiddlerCoreStartupFlags.Default); - console.WriteLine("Fiddler代理已启动", ConsoleColor.Green); - } - - //初始化Fiddler - private void InitFiddler() - { - //这个名字随便 - FiddlerApplication.SetAppDisplayName("FiddlerCore"); - FiddlerApplication.OnWebSocketMessage += FiddlerApplication_OnWebSocketMessage; - - X509Certificate2 oRootCert; - if (null == CertMaker.GetRootCertificate()) - { - CertMaker.createRootCert(); - oRootCert = CertMaker.GetRootCertificate(); - X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine); - certStore.Open(OpenFlags.ReadWrite); - try - { - certStore.Add(oRootCert); - } - finally - { - certStore.Close(); - } - } - else - { - oRootCert = CertMaker.GetRootCertificate(); - } - //信任证书 - CertMaker.trustRootCert(); - - FiddlerApplication.oDefaultClientCertificate = oRootCert; - //忽略服务器证书错误 - CONFIG.IgnoreServerCertErrors = true; - CONFIG.bEnableIPv6 = false; - //CONFIG.bCaptureCONNECT = true; - //CONFIG.bUseEventLogForExceptions = false; - //CONFIG.bAutoProxyLogon = false; - //CONFIG.bMITM_HTTPS = false; - ////CONFIG.SetNoDecryptList("*"); - } - - private void FiddlerApplication_OnWebSocketMessage(object sender, WebSocketMessageEventArgs e) - { - var msg = e.oWSM; - OnWebSocketData?.Invoke(this, new WsMessageEventArgs(msg)); - } - - [DllImport(@"wininet", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "InternetSetOption", CallingConvention = CallingConvention.StdCall)] - private static extern bool InternetSetOption(int hInternet, int dmOption, IntPtr lpBuffer, int dwBufferLength); - private static void CloseSystemProxy() - { - //打开注册表 - var regKey = Registry.CurrentUser; - - const string subKeyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; - var optionKey = regKey.OpenSubKey(subKeyPath, true); - //更改健值,设置代理, - if (optionKey != null) optionKey.SetValue("ProxyEnable", 0); - - //激活代理设置 - InternetSetOption(0, 39, IntPtr.Zero, 0); - InternetSetOption(0, 37, IntPtr.Zero, 0); - } - - public void Dispose() - { - if (disposed) return; - FiddlerApplication.Shutdown(); - CloseSystemProxy(); - console.WriteLine("Fiddler代理已关闭"); - disposed = true; - } - - - public class WsMessageEventArgs - { - /// - /// 消息体 - /// - public WebSocketMessage Message { get; set; } - - /// - /// 进程ID - /// - public int ProcessID { get; set; } - - /// - /// 进程名 - /// - public string ProcessName { get; set; } - - - public WsMessageEventArgs(WebSocketMessage msg) - { - this.Message = msg; - - FieldInfo field = msg.GetType().GetField("_wsOwner", BindingFlags.NonPublic | BindingFlags.Instance); - WebSocket obj = (WebSocket)field.GetValue(msg); - field = obj.GetType().GetField("oCP", BindingFlags.NonPublic | BindingFlags.Instance); - ClientPipe ocp = (ClientPipe)field.GetValue(obj); - - this.ProcessID = ocp.LocalProcessID; - this.ProcessName = ocp.LocalProcessName; - } - } - } -}