99#include " Auth.h"
1010#include " Utils.h"
1111
12- int Auth::GetPort (std::string cmdLine)
12+ ClientInfo Auth::GetClientInfo (const DWORD& pid)
13+ {
14+ if (!pid)
15+ return {};
16+
17+ std::string cmdLine = Utils::WstringToString (GetProcessCommandLine (pid));
18+ if (cmdLine.empty ())
19+ return {};
20+
21+ ClientInfo info;
22+ info.port = GetPort (cmdLine);
23+ info.token = GetToken (cmdLine);
24+ info.path = GetProcessPath (pid);
25+ info.version = GetFileVersion (info.path );
26+
27+ return info;
28+ }
29+
30+ int Auth::GetPort (const std::string& cmdLine)
1331{
1432 std::regex regexStr (" --app-port=(\\ d*)" );
1533 std::smatch m;
@@ -19,7 +37,7 @@ int Auth::GetPort(std::string cmdLine)
1937 return 0 ;
2038}
2139
22- std::string Auth::GetToken (std::string cmdLine)
40+ std::string Auth::GetToken (const std::string& cmdLine)
2341{
2442 std::regex regexStr (" --remoting-auth-token=([\\ w-]*)" );
2543 std::smatch m;
@@ -33,94 +51,48 @@ std::string Auth::GetToken(std::string cmdLine)
3351 return " " ;
3452}
3553
36- bool Auth::GetRiotClientInfo ( )
54+ std::string Auth::MakeLeagueHeader ( const ClientInfo& info )
3755{
38- DWORD pid = GetProcessId (L" RiotClientUx.exe" );
39- if (!pid)
40- return false ;
41-
42- std::string cmdLine = Utils::WstringToString (GetProcessCommandLine (pid));
43- if (cmdLine.empty ())
44- return false ;
45-
46- riotPort = GetPort (cmdLine);
47- riotToken = GetToken (cmdLine);
48- riotPath = GetProcessPath (pid);
49- riotVersion = GetFileVersion (riotPath);
50-
51- if (riotPort == 0 || riotToken == " " )
52- return false ;
53-
54- MakeRiotHeader ();
55-
56- return true ;
57- }
58-
59- void Auth::MakeRiotHeader ()
60- {
61- riotHeader = " Host: 127.0.0.1:" + std::to_string (riotPort) + " \r\n " +
56+ return " Host: 127.0.0.1:" + std::to_string (info.port ) + " \r\n " +
6257 " Connection: keep-alive" + " \r\n " +
63- " Authorization: Basic " + riotToken + " \r\n " +
58+ " Authorization: Basic " + info. token + " \r\n " +
6459 " Accept: application/json" + " \r\n " +
65- " Access-Control-Allow-Credentials: true" + " \r\n " +
66- " Access-Control-Allow-Origin: 127.0.0.1" + " \r\n " +
6760 " Content-Type: application/json" + " \r\n " +
68- " Origin: https://127.0.0.1:" + std::to_string (riotPort) + " \r\n " +
69- " Sec-Fetch-Dest: empty" + " \r\n " +
70- " Sec-Fetch-Mode: cors" + " \r\n " +
61+ " Origin: https://127.0.0.1:" + std::to_string (info.port ) + " \r\n " +
62+ " User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) LeagueOfLegendsClient/" + info.version + " (CEF 91) Safari/537.36" + " \r\n " +
63+ " X-Riot-Source: rcp-fe-lol-social" + " \r\n " +
64+ " sec-ch-ua: \" Chromium\" ;v=\" 91\" " + " \r\n " +
65+ " sec-ch-ua-mobile: ?0" + " \r\n " +
7166 " Sec-Fetch-Site: same-origin" + " \r\n " +
72- " Sec-Fetch-User: ?F" + " \r\n " +
73- " User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) RiotClient/" + riotVersion + " (CEF 74) Safari/537.36" + " \r\n " +
74- " sec-ch-ua: Chromium" + " \r\n " +
75- " Referer: https://127.0.0.1:" + std::to_string (riotPort) + " /index.html" + " \r\n " +
67+ " Sec-Fetch-Mode: cors" + " \r\n " +
68+ " Sec-Fetch-Dest: empty" + " \r\n " +
69+ " Referer: https://127.0.0.1:" + std::to_string (info.port ) + " /index.html" + " \r\n " +
7670 " Accept-Encoding: gzip, deflate, br" + " \r\n " +
7771 " Accept-Language: en-US,en;q=0.9" ;
7872}
7973
80- bool Auth::GetLeagueClientInfo ()
81- {
82- DWORD pid = GetProcessId (L" LeagueClientUx.exe" );
83- if (!pid)
84- return false ;
85-
86- std::string cmdLine = Utils::WstringToString (GetProcessCommandLine (pid));
87- if (cmdLine.empty ())
88- return false ;
89-
90- leaguePort = GetPort (cmdLine);
91- leagueToken = GetToken (cmdLine);
92- leaguePath = GetProcessPath (pid);
93- leagueVersion = GetFileVersion (leaguePath);
94-
95- if (leaguePort == 0 || leagueToken == " " )
96- return false ;
97-
98- MakeLeagueHeader ();
99-
100- return true ;
101- }
102-
103- void Auth::MakeLeagueHeader ()
74+ std::string Auth::MakeRiotHeader (const ClientInfo& info)
10475{
105- leagueHeader = " Host: 127.0.0.1:" + std::to_string (leaguePort ) + " \r\n " +
76+ return " Host: 127.0.0.1:" + std::to_string (info. port ) + " \r\n " +
10677 " Connection: keep-alive" + " \r\n " +
107- " Authorization: Basic " + leagueToken + " \r\n " +
78+ " Authorization: Basic " + info. token + " \r\n " +
10879 " Accept: application/json" + " \r\n " +
80+ " Access-Control-Allow-Credentials: true" + " \r\n " +
81+ " Access-Control-Allow-Origin: 127.0.0.1" + " \r\n " +
10982 " Content-Type: application/json" + " \r\n " +
110- " Origin: https://127.0.0.1:" + std::to_string (leaguePort) + " \r\n " +
111- " User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) LeagueOfLegendsClient/" + leagueVersion + " (CEF 91) Safari/537.36" + " \r\n " +
112- " X-Riot-Source: rcp-fe-lol-social" + " \r\n " +
113- " sec-ch-ua: \" Chromium\" ;v=\" 91\" " + " \r\n " +
114- " sec-ch-ua-mobile: ?0" + " \r\n " +
115- " Sec-Fetch-Site: same-origin" + " \r\n " +
116- " Sec-Fetch-Mode: cors" + " \r\n " +
83+ " Origin: https://127.0.0.1:" + std::to_string (info.port ) + " \r\n " +
11784 " Sec-Fetch-Dest: empty" + " \r\n " +
118- " Referer: https://127.0.0.1:" + std::to_string (leaguePort) + " /index.html" + " \r\n " +
85+ " Sec-Fetch-Mode: cors" + " \r\n " +
86+ " Sec-Fetch-Site: same-origin" + " \r\n " +
87+ " Sec-Fetch-User: ?F" + " \r\n " +
88+ " User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) RiotClient/" + info.version + " (CEF 74) Safari/537.36" + " \r\n " +
89+ " sec-ch-ua: Chromium" + " \r\n " +
90+ " Referer: https://127.0.0.1:" + std::to_string (info.port ) + " /index.html" + " \r\n " +
11991 " Accept-Encoding: gzip, deflate, br" + " \r\n " +
12092 " Accept-Language: en-US,en;q=0.9" ;
12193}
12294
123- DWORD Auth::GetProcessId (std::wstring processName)
95+ DWORD Auth::GetProcessId (const std::wstring& processName)
12496{
12597 HANDLE snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, NULL );
12698 if (snapshot != INVALID_HANDLE_VALUE)
@@ -143,7 +115,30 @@ DWORD Auth::GetProcessId(std::wstring processName)
143115 return 0 ;
144116}
145117
146- std::wstring Auth::GetProcessCommandLine (DWORD processId)
118+ std::vector<DWORD> Auth::GetAllProcessIds (const std::wstring& processName)
119+ {
120+ std::vector<DWORD>pids;
121+ HANDLE snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, NULL );
122+ if (snapshot != INVALID_HANDLE_VALUE)
123+ {
124+ PROCESSENTRY32W entry;
125+ entry.dwSize = sizeof (PROCESSENTRY32W);
126+ if (Process32FirstW (snapshot, &entry))
127+ {
128+ do
129+ {
130+ if (std::wstring (entry.szExeFile ) == processName)
131+ {
132+ pids.emplace_back (entry.th32ProcessID );
133+ }
134+ } while (Process32NextW (snapshot, &entry));
135+ }
136+ }
137+ CloseHandle (snapshot);
138+ return pids;
139+ }
140+
141+ std::wstring Auth::GetProcessCommandLine (const DWORD& processId)
147142{
148143 typedef NTSTATUS (__stdcall* tNtQueryInformationProcess)
149144 (
@@ -232,7 +227,7 @@ std::wstring Auth::GetProcessCommandLine(DWORD processId)
232227 return result;
233228}
234229
235- std::wstring Auth::GetProcessPath (DWORD processId)
230+ std::wstring Auth::GetProcessPath (const DWORD& processId)
236231{
237232 HANDLE processHandle = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0 , processId);
238233 if (processHandle)
@@ -248,7 +243,7 @@ std::wstring Auth::GetProcessPath(DWORD processId)
248243 return L" " ;
249244}
250245
251- std::string Auth::GetFileVersion (std::wstring file)
246+ std::string Auth::GetFileVersion (const std::wstring& file)
252247{
253248 DWORD versionSize = GetFileVersionInfoSizeW (file.c_str (), 0 );
254249 if (versionSize)
0 commit comments