-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm.cs
166 lines (134 loc) · 5.08 KB
/
Form.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace IconChanger
{
public partial class Form : System.Windows.Forms.Form
{
private bool found = false;
private UInt16 port { get; set; }
private String token { get; set; }
private const String _LocalBaseUrl = @"https://127.0.0.1:{0}/{1}";
private WebClient Client = new WebClient();
private void SetHeaders()
{
Client.Headers.Clear();
Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
Client.Headers.Add(HttpRequestHeader.Accept, "application/json");
String username = "riot";
String password = token;
String hash = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
Client.Headers.Add(HttpRequestHeader.Authorization, $"Basic {hash}");
}
public Form()
{
InitializeComponent();
lblStatus.Text = @"Waiting/Searching for League Client...";
txtInput.Enabled = false;
timer.Start();
}
private void TxtLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://share.aecx.cc/LxlSRe");
}
private void TxtCopy_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("http://aecx.cc");
}
private void Timer_Tick(object sender, EventArgs e)
{
Process[] pname = Process.GetProcessesByName("LeagueClientUx");
if (!found && pname.Length > 0)
{
// Client is running
String CLI = Program.GetCommandLine(pname[0]);
// Parse the CLI call
String key = null;
String val = null;
foreach (String param in CLI.Split(@""" """.ToCharArray()))
{
try
{
key = param.Split('=')[0];
val = param.Split('=')[1];
if (key == @"--remoting-auth-token")
{
token = val;
}
else if (key == @"--app-port")
{
port = UInt16.Parse(val);
}
if (token != null && port != 0)
break;
}
catch (Exception ex)
{
continue;
}
}
found = true;
lblStatus.Text = @"League client attached!";
txtInput.Enabled = true;
richTextBox1.Text += "port: " + port + "\r\ntoken: " + token + "\r\n";
return;
}
}
private void BtnSet_Click(object sender, EventArgs e)
{
try
{
int iconID = -1;
if(!int.TryParse(txtInput.Text, out iconID))
{
throw new Exception("Invalid ID format. Please use whole natural numbers!");
}
if(iconID < 0)
{
throw new Exception("Invalid ID. Make sure it's >= 0");
}
SetHeaders();
String iconAPIpath = @"lol-summoner/v1/current-summoner/icon";
String url = String.Format(_LocalBaseUrl, port, iconAPIpath);
String Body = "{\r\n" + @"""profileIconId"": " + iconID + "\r\n}";
richTextBox1.Text += Client.Headers.ToString();
richTextBox1.Text += "PUT " + url;
richTextBox1.Text += "\r\n" + Body + "\r\n";
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Client.UploadData(url, "PUT", ASCIIEncoding.ASCII.GetBytes(Body));
}
catch(Exception ex)
{
richTextBox1.Text += $"Exception at {ex.Source} :: {ex.Message}\r\n";
}
}
private void ToggleLog_CheckedChanged(object sender, EventArgs e)
{
if(ToggleLog.Checked)
{
this.Height = 550;
}
else
{
this.Height = 140;
}
}
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
return true;
}
}
}