From 5057a1df07ffe59dbd10ff60b314f96d7ce097b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E7=8C=BF?= <1083092844@qq.com> Date: Thu, 17 Aug 2023 20:34:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=87=BAFiddler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BarrageGrab/Proxy/FiddlerProxy.cs | 116 ------------------------------ 1 file changed, 116 deletions(-) delete mode 100644 BarrageGrab/Proxy/FiddlerProxy.cs diff --git a/BarrageGrab/Proxy/FiddlerProxy.cs b/BarrageGrab/Proxy/FiddlerProxy.cs deleted file mode 100644 index afadd4c..0000000 --- a/BarrageGrab/Proxy/FiddlerProxy.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -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.Proxy -{ - /// - /// FiddlerCore 代理程序 - /// - [Obsolete("由于框架存在内存泄漏,已弃用,请使用TitaniumProxy)", false)] - internal class FiddlerProxy : SystemProxy - { - bool disposed = false; - ConsoleWriter console = new ConsoleWriter(); - - public FiddlerProxy() - { - InitFiddler(); - } - - //初始化Fiddler - private void InitFiddler() - { - //这个名字随便 - FiddlerApplication.SetAppDisplayName("FiddlerCore"); - FiddlerApplication.OnWebSocketMessage += FiddlerApplication_OnWebSocketMessage; - //FiddlerApplication.OnReadResponseBuffer += OnReadResponseBuffer; - //设置pac规则,匹配douyin且排除douyincdn的host走代理,其余的直连 - FiddlerApplication.Prefs.SetStringPref("fiddler.proxy.pacfile.text", $"if (/douyin(?!cdn)/.test(host)) {{return 'PROXY 127.0.0.1:{base.ProxyPort}' }} return 'DIRECT'"); - - - 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; - - 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); - - var sessionField = obj.GetType().GetField("_mySession", BindingFlags.NonPublic | BindingFlags.Instance); - - ClientPipe ocp = (ClientPipe)field.GetValue(obj); - Session session = (Session)sessionField.GetValue(obj); - - this.SendWebSocketData(new WsMessageEventArgs() - { - Payload = msg.PayloadData, - ProcessID = ocp.LocalProcessID, - ProcessName = ocp.LocalProcessName, - HostName = session.hostname, - }); - } - - - public override void Start() - { - FiddlerApplication.Startup(Appsetting.Instanse.ProxyPort, FiddlerCoreStartupFlags.Default); - console.WriteLine("Fiddler代理已启动", ConsoleColor.Green); - } - - public override void Dispose() - { - if (disposed) return; - FiddlerApplication.Shutdown(); - CloseSystemProxy(); - console.WriteLine("Fiddler代理已关闭"); - disposed = true; - } - } -}