-
Notifications
You must be signed in to change notification settings - Fork 0
/
Proxy.cs
92 lines (72 loc) · 3.25 KB
/
Proxy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.Net;
using Titanium.Web.Proxy;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Models;
using Game.Providers.Hacksaw;
using Game.Providers.Pragmatic;
namespace AppProxy;
public class Proxy
{
public static void Start()
{
var proxyServer = new ProxyServer();
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 6798, true);
proxyServer.EnableHttp2 = true;
proxyServer.CertificateManager.CreateRootCertificate(false);
proxyServer.CertificateManager.TrustRootCertificate();
proxyServer.AddEndPoint(explicitEndPoint);
explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest;
proxyServer.BeforeRequest += OnRequest;
proxyServer.BeforeResponse += OnResponse;
proxyServer.Start();
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
}
public static async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{
string hostname = e.HttpClient.Request.RequestUri.Host;
//e.DecryptSsl = true;
if (hostname.Contains("hacksaw") || hostname.Contains("pragmatic"))
e.DecryptSsl = true;
await Task.Delay(10);
}
public static async Task OnRequest(object sender, SessionEventArgs e)
{
string method = e.HttpClient.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH"))
{
byte[] bodyBytes = await e.GetRequestBody();
e.SetRequestBody(bodyBytes);
string bodyString = await e.GetRequestBodyAsString();
e.SetRequestBodyString(bodyString);
}
}
public static async Task OnResponse(object sender, SessionEventArgs e)
{
if (e.HttpClient.Request.Method == "GET" || e.HttpClient.Request.Method == "POST")
{
if (e.HttpClient.Response.StatusCode == 200 || e.HttpClient.Response.StatusCode == 404)
{
if (e.HttpClient.Response.ContentType != null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
byte[] bodyBytes = await e.GetResponseBody();
e.SetResponseBody(bodyBytes);
string body = await e.GetResponseBodyAsString();
e.SetResponseBodyString(body);
}