Skip to content

Commit 172a6d6

Browse files
committed
reduce av false positives, update imgui, remove jsoncpp (now vcpkg)
1 parent 69676e3 commit 172a6d6

38 files changed

Lines changed: 2324 additions & 8795 deletions

KBotExt/Auth.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,17 @@ std::string Auth::MakeRiotHeader(const ClientInfo& info)
9696

9797
DWORD Auth::GetProcessId(const std::wstring& processName)
9898
{
99-
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
99+
static HMODULE kernel32 = GetModuleHandleA("kernel32");
100+
static auto pCreateToolhelp32Snapshot = (decltype(&CreateToolhelp32Snapshot))GetProcAddress(kernel32, "CreateToolhelp32Snapshot");
101+
static auto pProcess32FirstW = (decltype(&Process32FirstW))GetProcAddress(kernel32, "Process32FirstW");
102+
static auto pProcess32NextW = (decltype(&Process32NextW))GetProcAddress(kernel32, "Process32NextW");
103+
104+
const HANDLE snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
100105
if (snapshot != INVALID_HANDLE_VALUE)
101106
{
102107
PROCESSENTRY32W entry;
103108
entry.dwSize = sizeof(PROCESSENTRY32W);
104-
if (Process32FirstW(snapshot, &entry))
109+
if (pProcess32FirstW(snapshot, &entry))
105110
{
106111
do
107112
{
@@ -110,7 +115,7 @@ DWORD Auth::GetProcessId(const std::wstring& processName)
110115
CloseHandle(snapshot);
111116
return entry.th32ProcessID;
112117
}
113-
} while (Process32NextW(snapshot, &entry));
118+
} while (pProcess32NextW(snapshot, &entry));
114119
}
115120
}
116121
CloseHandle(snapshot);
@@ -119,21 +124,26 @@ DWORD Auth::GetProcessId(const std::wstring& processName)
119124

120125
std::vector<DWORD> Auth::GetAllProcessIds(const std::wstring& processName)
121126
{
127+
static HMODULE kernel32 = GetModuleHandleA("kernel32");
128+
static auto pCreateToolhelp32Snapshot = (decltype(&CreateToolhelp32Snapshot))GetProcAddress(kernel32, "CreateToolhelp32Snapshot");
129+
static auto pProcess32FirstW = (decltype(&Process32FirstW))GetProcAddress(kernel32, "Process32FirstW");
130+
static auto pProcess32NextW = (decltype(&Process32NextW))GetProcAddress(kernel32, "Process32NextW");
131+
122132
std::vector<DWORD> pids;
123-
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
133+
const HANDLE snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
124134
if (snapshot != INVALID_HANDLE_VALUE)
125135
{
126136
PROCESSENTRY32W entry;
127137
entry.dwSize = sizeof(PROCESSENTRY32W);
128-
if (Process32FirstW(snapshot, &entry))
138+
if (pProcess32FirstW(snapshot, &entry))
129139
{
130140
do
131141
{
132142
if (std::wstring(entry.szExeFile) == processName)
133143
{
134144
pids.emplace_back(entry.th32ProcessID);
135145
}
136-
} while (Process32NextW(snapshot, &entry));
146+
} while (pProcess32NextW(snapshot, &entry));
137147
}
138148
}
139149
CloseHandle(snapshot);
@@ -151,14 +161,20 @@ std::wstring Auth::GetProcessCommandLine(const DWORD& processId)
151161
PULONG ReturnLength
152162
);
153163

164+
static HMODULE kernel32 = GetModuleHandleA("kernel32");
165+
166+
static auto pOpenProcess = (decltype(&OpenProcess))GetProcAddress(kernel32, "OpenProcess");
154167
std::wstring result;
155-
const HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId);
168+
const HANDLE processHandle = pOpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId);
156169

170+
static auto pGetNativeSystemInfo = (decltype(&GetNativeSystemInfo))GetProcAddress(kernel32, "GetNativeSystemInfo");
157171
SYSTEM_INFO si;
158-
GetNativeSystemInfo(&si);
172+
pGetNativeSystemInfo(&si);
159173

174+
static auto pIsWow64Process = (decltype(&IsWow64Process))GetProcAddress(kernel32, "IsWow64Process");
175+
static auto pGetCurrentProcess = (decltype(&GetCurrentProcess))GetProcAddress(kernel32, "GetCurrentProcess");
160176
BOOL wow;
161-
IsWow64Process(GetCurrentProcess(), &wow);
177+
pIsWow64Process(pGetCurrentProcess(), &wow);
162178

163179
const DWORD ProcessParametersOffset = si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ? 0x20 : 0x10;
164180
const DWORD CommandLineOffset = si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ? 0x70 : 0x40;
@@ -270,14 +286,15 @@ std::wstring Auth::GetProcessCommandLine(const DWORD& processId)
270286
return {};
271287
}
272288

273-
if (!ReadProcessMemory(processHandle, pbi.PebBaseAddress, peb, pebSize, nullptr))
289+
static auto pReadProcessMemory = (decltype(&ReadProcessMemory))GetProcAddress(kernel32, "ReadProcessMemory");
290+
if (!pReadProcessMemory(processHandle, pbi.PebBaseAddress, peb, pebSize, nullptr))
274291
{
275292
MessageBoxA(nullptr, "PEB ReadProcessMemory failed", nullptr, 0);
276293
CloseHandle(processHandle);
277294
return {};
278295
}
279296

280-
if (const PBYTE* parameters = static_cast<PBYTE*>(*reinterpret_cast<LPVOID*>(peb + ProcessParametersOffset)); !ReadProcessMemory(
297+
if (const PBYTE* parameters = static_cast<PBYTE*>(*reinterpret_cast<LPVOID*>(peb + ProcessParametersOffset)); !pReadProcessMemory(
281298
processHandle, parameters, processParameters, processParametersSize, nullptr))
282299
{
283300
MessageBoxA(nullptr, "processParameters ReadProcessMemory failed", nullptr, 0);
@@ -287,7 +304,7 @@ std::wstring Auth::GetProcessCommandLine(const DWORD& processId)
287304

288305
const UNICODE_STRING* pCommandLine = reinterpret_cast<UNICODE_STRING*>(processParameters + CommandLineOffset);
289306
const auto commandLineCopy = static_cast<PWSTR>(malloc(pCommandLine->MaximumLength));
290-
if (!ReadProcessMemory(processHandle, pCommandLine->Buffer, commandLineCopy, pCommandLine->MaximumLength, nullptr))
307+
if (!pReadProcessMemory(processHandle, pCommandLine->Buffer, commandLineCopy, pCommandLine->MaximumLength, nullptr))
291308
{
292309
MessageBoxA(nullptr, "pCommandLine ReadProcessMemory failed", nullptr, 0);
293310
CloseHandle(processHandle);
@@ -303,9 +320,13 @@ std::wstring Auth::GetProcessCommandLine(const DWORD& processId)
303320

304321
std::wstring Auth::GetProcessPath(const DWORD& processId)
305322
{
306-
if (const HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId))
323+
static HMODULE kernel32 = GetModuleHandleA("kernel32");
324+
static auto pOpenProcess = (decltype(&OpenProcess))GetProcAddress(kernel32, "OpenProcess");
325+
326+
if (const HANDLE processHandle = pOpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId))
307327
{
308-
if (WCHAR result[MAX_PATH]; GetModuleFileNameExW(processHandle, nullptr, result, MAX_PATH))
328+
static auto pK32GetModuleFileNameExW = (decltype(&K32GetModuleFileNameExW))GetProcAddress(kernel32, "K32GetModuleFileNameExW");
329+
if (WCHAR result[MAX_PATH]; pK32GetModuleFileNameExW(processHandle, nullptr, result, MAX_PATH))
309330
{
310331
CloseHandle(processHandle);
311332
return { result };

KBotExt/GameTab.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,8 +1533,7 @@ class GameTab
15331533
{
15341534
url = L"https://porofessor.gg/pregame/" + region + L"/" + summNames;
15351535
}
1536-
1537-
ShellExecuteW(nullptr, nullptr, url.c_str(), nullptr, nullptr, SW_SHOW);
1536+
Utils::OpenUrl(url.c_str(), nullptr, SW_SHOW);
15381537
return Utils::WstringToString(url);
15391538
}
15401539
return "Failed to get region";

KBotExt/KBotExt.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ int WINAPI wWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR
4747
startupInfo.cb = sizeof(startupInfo);
4848
PROCESS_INFORMATION processInformation = {};
4949

50-
if (!CreateProcessA(applicationName.c_str(), const_cast<char*>(cmdLine.c_str()), nullptr, nullptr, false, 2U, nullptr, nullptr, &startupInfo,
50+
static HMODULE kernel32 = GetModuleHandleA("kernel32");
51+
static auto pCreateProcessA = (decltype(&CreateProcessA))GetProcAddress(kernel32, "CreateProcessA");
52+
if (!pCreateProcessA(applicationName.c_str(), const_cast<char*>(cmdLine.c_str()), nullptr, nullptr, false, 2U, nullptr, nullptr, &startupInfo,
5153
&processInformation))
5254
return 0;
5355

5456
std::cout << "App: " << applicationName << std::endl;
5557
std::cout << "PID: " << processInformation.dwProcessId << std::endl;
5658
std::cout << "Args: " << cmdLine << std::endl;
5759

58-
if (!DebugActiveProcessStop(processInformation.dwProcessId))
60+
static auto pDebugActiveProcessStop = (decltype(&DebugActiveProcessStop))GetProcAddress(kernel32, "DebugActiveProcessStop");
61+
if (!pDebugActiveProcessStop(processInformation.dwProcessId))
5962
{
6063
CloseHandle(processInformation.hProcess);
6164
CloseHandle(processInformation.hThread);
@@ -64,7 +67,8 @@ int WINAPI wWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR
6467
return 0;
6568
}
6669

67-
WaitForSingleObject(processInformation.hProcess, INFINITE);
70+
static auto pWaitForSingleObject = (decltype(&WaitForSingleObject))GetProcAddress(kernel32, "WaitForSingleObject");
71+
pWaitForSingleObject(processInformation.hProcess, INFINITE);
6872

6973
std::cout << "Exited" << std::endl;
7074

KBotExt/KBotExt.vcxproj

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
<SubSystem>Windows</SubSystem>
174174
<EnableCOMDATFolding>true</EnableCOMDATFolding>
175175
<OptimizeReferences>true</OptimizeReferences>
176-
<GenerateDebugInformation>false</GenerateDebugInformation>
176+
<GenerateDebugInformation>true</GenerateDebugInformation>
177177
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
178178
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
179179
</Link>
@@ -188,9 +188,6 @@
188188
<ClCompile Include="imgui\imgui_impl_win32.cpp" />
189189
<ClCompile Include="imgui\imgui_tables.cpp" />
190190
<ClCompile Include="imgui\imgui_widgets.cpp" />
191-
<ClCompile Include="json\json_reader.cpp" />
192-
<ClCompile Include="json\json_value.cpp" />
193-
<ClCompile Include="json\json_writer.cpp" />
194191
<ClCompile Include="KBotExt.cpp" />
195192
<ClCompile Include="LCU.cpp" />
196193
<ClCompile Include="Utils.cpp" />
@@ -213,17 +210,6 @@
213210
<ClInclude Include="imgui\imstb_textedit.h" />
214211
<ClInclude Include="Includes.h" />
215212
<ClInclude Include="InfoTab.h" />
216-
<ClInclude Include="json\allocator.h" />
217-
<ClInclude Include="json\assertions.h" />
218-
<ClInclude Include="json\config.h" />
219-
<ClInclude Include="json\forwards.h" />
220-
<ClInclude Include="json\json.h" />
221-
<ClInclude Include="json\json_features.h" />
222-
<ClInclude Include="json\json_tool.h" />
223-
<ClInclude Include="json\reader.h" />
224-
<ClInclude Include="json\value.h" />
225-
<ClInclude Include="json\version.h" />
226-
<ClInclude Include="json\writer.h" />
227213
<ClInclude Include="LCU.h" />
228214
<ClInclude Include="LoginTab.h" />
229215
<ClInclude Include="Misc.h" />
@@ -234,9 +220,6 @@
234220
<ClInclude Include="SkinsTab.h" />
235221
<ClInclude Include="Utils.h" />
236222
</ItemGroup>
237-
<ItemGroup>
238-
<None Include="json\json_valueiterator.inl" />
239-
</ItemGroup>
240223
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
241224
<ImportGroup Label="ExtensionTargets">
242225
</ImportGroup>

KBotExt/KBotExt.vcxproj.filters

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<Filter Include="json">
5-
<UniqueIdentifier>{54db2d2d-b22b-4c3c-b6bd-8802952723b6}</UniqueIdentifier>
6-
</Filter>
74
<Filter Include="Tabs">
85
<UniqueIdentifier>{7d0b8c55-703b-4c67-b79b-56f9c8dbbf02}</UniqueIdentifier>
96
</Filter>
@@ -54,15 +51,6 @@
5451
<ClCompile Include="imgui\imgui_widgets.cpp">
5552
<Filter>imgui</Filter>
5653
</ClCompile>
57-
<ClCompile Include="json\json_reader.cpp">
58-
<Filter>json</Filter>
59-
</ClCompile>
60-
<ClCompile Include="json\json_value.cpp">
61-
<Filter>json</Filter>
62-
</ClCompile>
63-
<ClCompile Include="json\json_writer.cpp">
64-
<Filter>json</Filter>
65-
</ClCompile>
6654
<ClCompile Include="LCU.cpp">
6755
<Filter>League</Filter>
6856
</ClCompile>
@@ -122,39 +110,6 @@
122110
<ClInclude Include="imgui\imstb_textedit.h">
123111
<Filter>imgui</Filter>
124112
</ClInclude>
125-
<ClInclude Include="json\allocator.h">
126-
<Filter>json</Filter>
127-
</ClInclude>
128-
<ClInclude Include="json\assertions.h">
129-
<Filter>json</Filter>
130-
</ClInclude>
131-
<ClInclude Include="json\config.h">
132-
<Filter>json</Filter>
133-
</ClInclude>
134-
<ClInclude Include="json\forwards.h">
135-
<Filter>json</Filter>
136-
</ClInclude>
137-
<ClInclude Include="json\json.h">
138-
<Filter>json</Filter>
139-
</ClInclude>
140-
<ClInclude Include="json\json_features.h">
141-
<Filter>json</Filter>
142-
</ClInclude>
143-
<ClInclude Include="json\json_tool.h">
144-
<Filter>json</Filter>
145-
</ClInclude>
146-
<ClInclude Include="json\reader.h">
147-
<Filter>json</Filter>
148-
</ClInclude>
149-
<ClInclude Include="json\value.h">
150-
<Filter>json</Filter>
151-
</ClInclude>
152-
<ClInclude Include="json\version.h">
153-
<Filter>json</Filter>
154-
</ClInclude>
155-
<ClInclude Include="json\writer.h">
156-
<Filter>json</Filter>
157-
</ClInclude>
158113
<ClInclude Include="Misc.h">
159114
<Filter>Header Files</Filter>
160115
</ClInclude>
@@ -186,9 +141,4 @@
186141
<Filter>imgui</Filter>
187142
</ClInclude>
188143
</ItemGroup>
189-
<ItemGroup>
190-
<None Include="json\json_valueiterator.inl">
191-
<Filter>json</Filter>
192-
</None>
193-
</ItemGroup>
194144
</Project>

KBotExt/LoginTab.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ class LoginTab
9898
// find saved lang from cfg file
9999
auto findLang = std::ranges::find_if(langs, [](std::pair<std::string, std::string> k) {
100100
return k.second == S.loginTab.language;
101-
});
101+
});
102102

103-
static std::pair selectedLang = {findLang[0].first, findLang[0].second};
103+
static std::pair selectedLang = { findLang[0].first, findLang[0].second };
104104

105105
if (ImGui::Button("Launch client"))
106106
{
@@ -122,7 +122,7 @@ class LoginTab
122122
{
123123
if (ImGui::Selectable(fst.c_str(), fst == selectedLang.first))
124124
{
125-
selectedLang = {fst, snd};
125+
selectedLang = { fst, snd };
126126
S.loginTab.language = snd;
127127
Config::Save();
128128

@@ -249,12 +249,12 @@ class LoginTab
249249
cpr::Session session;
250250
session.SetHeader(authHeader);
251251

252-
std::string valoApi = cpr::Get(cpr::Url{"https://valorant-api.com/v1/version"}).text;
252+
std::string valoApi = cpr::Get(cpr::Url{ "https://valorant-api.com/v1/version" }).text;
253253

254254
std::regex regexStr("\"riotClientBuild\":\"(.*?)\"");
255255
if (std::smatch m; std::regex_search(valoApi, m, regexStr))
256256
{
257-
session.UpdateHeader(cpr::Header{{"User-Agent", "RiotClient/" + m[1].str() + " rso-auth (Windows;10;;Home, x64)"}});
257+
session.UpdateHeader(cpr::Header{ {"User-Agent", "RiotClient/" + m[1].str() + " rso-auth (Windows;10;;Home, x64)"} });
258258
}
259259

260260
session.SetBody(authData.toStyledString());
@@ -284,7 +284,7 @@ class LoginTab
284284
size_t startIndex = uri.find("#access_token=") + strlen("#access_token=");
285285
size_t endIndex = uri.find("&scope");
286286
std::string bearer = uri.substr(startIndex, endIndex - startIndex);
287-
session.UpdateHeader(cpr::Header{{"Authorization", "Bearer " + bearer}});
287+
session.UpdateHeader(cpr::Header{ {"Authorization", "Bearer " + bearer} });
288288

289289
session.SetUrl("https://auth.riotgames.com/userinfo");
290290
r = session.Get().text;

0 commit comments

Comments
 (0)