弹幕域名校验放宽
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Fiddler;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BarrageGrab.Proxy
|
||||
{
|
||||
@@ -8,6 +9,11 @@ namespace BarrageGrab.Proxy
|
||||
{
|
||||
event EventHandler<WsMessageEventArgs> OnWebSocketData;
|
||||
|
||||
/// <summary>
|
||||
/// 域名过滤器
|
||||
/// </summary>
|
||||
Func<string, bool> HostNameFilter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始监听
|
||||
/// </summary>
|
||||
|
||||
@@ -13,17 +13,10 @@ namespace BarrageGrab.Proxy
|
||||
{
|
||||
internal abstract class SystemProxy : ISystemProxy
|
||||
{
|
||||
//弹幕服务域名
|
||||
protected string[] barrageWsHostNames = new string[]
|
||||
{
|
||||
"webcast3-ws-web-hl.douyin.com",
|
||||
"webcast3-ws-web-lf.douyin.com",
|
||||
"frontier-im.douyin.com",
|
||||
"webcast100-ws-web-lq.amemv.com"
|
||||
};
|
||||
|
||||
|
||||
//https://live.douyin.com/webcast/gift/list/
|
||||
/// <summary>
|
||||
/// 域名过滤器
|
||||
/// </summary>
|
||||
public Func<string, bool> HostNameFilter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 接收到websocket消息事件
|
||||
@@ -33,17 +26,42 @@ namespace BarrageGrab.Proxy
|
||||
/// <summary>
|
||||
/// 代理端口
|
||||
/// </summary>
|
||||
public int ProxyPort { get => Appsetting.Instanse.ProxyPort; }
|
||||
public int ProxyPort { get => Appsetting.Current.ProxyPort; }
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public abstract void Start();
|
||||
|
||||
protected void SendWebSocketData(WsMessageEventArgs args)
|
||||
//https://live.douyin.com/webcast/gift/list/ [礼物数据接口]
|
||||
|
||||
/// <summary>
|
||||
/// 检测是否是业务相关链接
|
||||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
/// <returns></returns>
|
||||
protected bool CheckHost(string host)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
if (HostNameFilter != null) return HostNameFilter(host);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 触发websocket消息事件
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected void FireWsEvent(WsMessageEventArgs args)
|
||||
{
|
||||
OnWebSocketData?.Invoke(this, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取进程名称
|
||||
/// </summary>
|
||||
/// <param name="processID"></param>
|
||||
/// <returns></returns>
|
||||
protected string GetProcessName(int processID)
|
||||
{
|
||||
var process = Process.GetProcessById(processID);
|
||||
@@ -54,7 +72,9 @@ namespace BarrageGrab.Proxy
|
||||
return $"<{processID}>";
|
||||
}
|
||||
|
||||
//注册系统代理
|
||||
/// <summary>
|
||||
/// 注册系统代理
|
||||
/// </summary>
|
||||
protected void RegisterSystemProxy()
|
||||
{
|
||||
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace BarrageGrab.Proxy
|
||||
proxyServer.ServerCertificateValidationCallback += ProxyServer_ServerCertificateValidationCallback; ;
|
||||
proxyServer.BeforeResponse += ProxyServer_BeforeResponse;
|
||||
|
||||
explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any,ProxyPort, true);
|
||||
explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, ProxyPort, true);
|
||||
explicitEndPoint.BeforeTunnelConnectRequest += ExplicitEndPoint_BeforeTunnelConnectRequest;
|
||||
proxyServer.AddEndPoint(explicitEndPoint);
|
||||
}
|
||||
@@ -57,7 +57,6 @@ namespace BarrageGrab.Proxy
|
||||
{
|
||||
e.IsValid = true;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -65,20 +64,16 @@ namespace BarrageGrab.Proxy
|
||||
private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e)
|
||||
{
|
||||
string hostname = e.HttpClient.Request.RequestUri.Host;
|
||||
if (!barrageWsHostNames.Contains(hostname)) return;
|
||||
|
||||
if (e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Websocket)
|
||||
{
|
||||
e.DataReceived += WebSocket_DataReceived;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//List<string> hostlist = new List<string>();
|
||||
|
||||
private async Task ExplicitEndPoint_BeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
|
||||
{
|
||||
string hostname = e.HttpClient.Request.RequestUri.Host;
|
||||
if (!barrageWsHostNames.Contains(hostname))
|
||||
if (!CheckHost(hostname))
|
||||
{
|
||||
e.DecryptSsl = false;
|
||||
}
|
||||
@@ -93,12 +88,10 @@ namespace BarrageGrab.Proxy
|
||||
var processid = args.HttpClient.ProcessId.Value;
|
||||
|
||||
var frames = args.WebSocketDecoderReceive.Decode(e.Buffer, e.Offset, e.Count).ToList();
|
||||
//Console.WriteLine(frames.Count);
|
||||
|
||||
|
||||
foreach (var frame in frames)
|
||||
{
|
||||
//Console.WriteLine(frame.GetText());
|
||||
base.SendWebSocketData(new WsMessageEventArgs()
|
||||
{
|
||||
base.FireWsEvent(new WsMessageEventArgs()
|
||||
{
|
||||
ProcessID = processid,
|
||||
HostName = hostname,
|
||||
@@ -106,9 +99,6 @@ namespace BarrageGrab.Proxy
|
||||
ProcessName = base.GetProcessName(processid)
|
||||
});
|
||||
}
|
||||
//Console.WriteLine("获取到弹幕信息:" + hostname);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user