Skip to content

Commit

Permalink
reduce av false positives, update imgui, remove jsoncpp (now vcpkg)
Browse files Browse the repository at this point in the history
  • Loading branch information
KebsCS committed Nov 5, 2023
1 parent 69676e3 commit 172a6d6
Show file tree
Hide file tree
Showing 38 changed files with 2,324 additions and 8,795 deletions.
49 changes: 35 additions & 14 deletions KBotExt/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ std::string Auth::MakeRiotHeader(const ClientInfo& info)

DWORD Auth::GetProcessId(const std::wstring& processName)
{
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
static HMODULE kernel32 = GetModuleHandleA("kernel32");
static auto pCreateToolhelp32Snapshot = (decltype(&CreateToolhelp32Snapshot))GetProcAddress(kernel32, "CreateToolhelp32Snapshot");
static auto pProcess32FirstW = (decltype(&Process32FirstW))GetProcAddress(kernel32, "Process32FirstW");
static auto pProcess32NextW = (decltype(&Process32NextW))GetProcAddress(kernel32, "Process32NextW");

const HANDLE snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (snapshot != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32W entry;
entry.dwSize = sizeof(PROCESSENTRY32W);
if (Process32FirstW(snapshot, &entry))
if (pProcess32FirstW(snapshot, &entry))
{
do
{
Expand All @@ -110,7 +115,7 @@ DWORD Auth::GetProcessId(const std::wstring& processName)
CloseHandle(snapshot);
return entry.th32ProcessID;
}
} while (Process32NextW(snapshot, &entry));
} while (pProcess32NextW(snapshot, &entry));
}
}
CloseHandle(snapshot);
Expand All @@ -119,21 +124,26 @@ DWORD Auth::GetProcessId(const std::wstring& processName)

std::vector<DWORD> Auth::GetAllProcessIds(const std::wstring& processName)
{
static HMODULE kernel32 = GetModuleHandleA("kernel32");
static auto pCreateToolhelp32Snapshot = (decltype(&CreateToolhelp32Snapshot))GetProcAddress(kernel32, "CreateToolhelp32Snapshot");
static auto pProcess32FirstW = (decltype(&Process32FirstW))GetProcAddress(kernel32, "Process32FirstW");
static auto pProcess32NextW = (decltype(&Process32NextW))GetProcAddress(kernel32, "Process32NextW");

std::vector<DWORD> pids;
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
const HANDLE snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (snapshot != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32W entry;
entry.dwSize = sizeof(PROCESSENTRY32W);
if (Process32FirstW(snapshot, &entry))
if (pProcess32FirstW(snapshot, &entry))
{
do
{
if (std::wstring(entry.szExeFile) == processName)
{
pids.emplace_back(entry.th32ProcessID);
}
} while (Process32NextW(snapshot, &entry));
} while (pProcess32NextW(snapshot, &entry));
}
}
CloseHandle(snapshot);
Expand All @@ -151,14 +161,20 @@ std::wstring Auth::GetProcessCommandLine(const DWORD& processId)
PULONG ReturnLength
);

static HMODULE kernel32 = GetModuleHandleA("kernel32");

static auto pOpenProcess = (decltype(&OpenProcess))GetProcAddress(kernel32, "OpenProcess");
std::wstring result;
const HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId);
const HANDLE processHandle = pOpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId);

static auto pGetNativeSystemInfo = (decltype(&GetNativeSystemInfo))GetProcAddress(kernel32, "GetNativeSystemInfo");
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
pGetNativeSystemInfo(&si);

static auto pIsWow64Process = (decltype(&IsWow64Process))GetProcAddress(kernel32, "IsWow64Process");
static auto pGetCurrentProcess = (decltype(&GetCurrentProcess))GetProcAddress(kernel32, "GetCurrentProcess");
BOOL wow;
IsWow64Process(GetCurrentProcess(), &wow);
pIsWow64Process(pGetCurrentProcess(), &wow);

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

if (!ReadProcessMemory(processHandle, pbi.PebBaseAddress, peb, pebSize, nullptr))
static auto pReadProcessMemory = (decltype(&ReadProcessMemory))GetProcAddress(kernel32, "ReadProcessMemory");
if (!pReadProcessMemory(processHandle, pbi.PebBaseAddress, peb, pebSize, nullptr))
{
MessageBoxA(nullptr, "PEB ReadProcessMemory failed", nullptr, 0);
CloseHandle(processHandle);
return {};
}

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

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

std::wstring Auth::GetProcessPath(const DWORD& processId)
{
if (const HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId))
static HMODULE kernel32 = GetModuleHandleA("kernel32");
static auto pOpenProcess = (decltype(&OpenProcess))GetProcAddress(kernel32, "OpenProcess");

if (const HANDLE processHandle = pOpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId))
{
if (WCHAR result[MAX_PATH]; GetModuleFileNameExW(processHandle, nullptr, result, MAX_PATH))
static auto pK32GetModuleFileNameExW = (decltype(&K32GetModuleFileNameExW))GetProcAddress(kernel32, "K32GetModuleFileNameExW");
if (WCHAR result[MAX_PATH]; pK32GetModuleFileNameExW(processHandle, nullptr, result, MAX_PATH))
{
CloseHandle(processHandle);
return { result };
Expand Down
3 changes: 1 addition & 2 deletions KBotExt/GameTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -1533,8 +1533,7 @@ class GameTab
{
url = L"https://porofessor.gg/pregame/" + region + L"/" + summNames;
}

ShellExecuteW(nullptr, nullptr, url.c_str(), nullptr, nullptr, SW_SHOW);
Utils::OpenUrl(url.c_str(), nullptr, SW_SHOW);
return Utils::WstringToString(url);
}
return "Failed to get region";
Expand Down
10 changes: 7 additions & 3 deletions KBotExt/KBotExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ int WINAPI wWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR
startupInfo.cb = sizeof(startupInfo);
PROCESS_INFORMATION processInformation = {};

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

std::cout << "App: " << applicationName << std::endl;
std::cout << "PID: " << processInformation.dwProcessId << std::endl;
std::cout << "Args: " << cmdLine << std::endl;

if (!DebugActiveProcessStop(processInformation.dwProcessId))
static auto pDebugActiveProcessStop = (decltype(&DebugActiveProcessStop))GetProcAddress(kernel32, "DebugActiveProcessStop");
if (!pDebugActiveProcessStop(processInformation.dwProcessId))
{
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
Expand All @@ -64,7 +67,8 @@ int WINAPI wWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR
return 0;
}

WaitForSingleObject(processInformation.hProcess, INFINITE);
static auto pWaitForSingleObject = (decltype(&WaitForSingleObject))GetProcAddress(kernel32, "WaitForSingleObject");
pWaitForSingleObject(processInformation.hProcess, INFINITE);

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

Expand Down
19 changes: 1 addition & 18 deletions KBotExt/KBotExt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
</Link>
Expand All @@ -188,9 +188,6 @@
<ClCompile Include="imgui\imgui_impl_win32.cpp" />
<ClCompile Include="imgui\imgui_tables.cpp" />
<ClCompile Include="imgui\imgui_widgets.cpp" />
<ClCompile Include="json\json_reader.cpp" />
<ClCompile Include="json\json_value.cpp" />
<ClCompile Include="json\json_writer.cpp" />
<ClCompile Include="KBotExt.cpp" />
<ClCompile Include="LCU.cpp" />
<ClCompile Include="Utils.cpp" />
Expand All @@ -213,17 +210,6 @@
<ClInclude Include="imgui\imstb_textedit.h" />
<ClInclude Include="Includes.h" />
<ClInclude Include="InfoTab.h" />
<ClInclude Include="json\allocator.h" />
<ClInclude Include="json\assertions.h" />
<ClInclude Include="json\config.h" />
<ClInclude Include="json\forwards.h" />
<ClInclude Include="json\json.h" />
<ClInclude Include="json\json_features.h" />
<ClInclude Include="json\json_tool.h" />
<ClInclude Include="json\reader.h" />
<ClInclude Include="json\value.h" />
<ClInclude Include="json\version.h" />
<ClInclude Include="json\writer.h" />
<ClInclude Include="LCU.h" />
<ClInclude Include="LoginTab.h" />
<ClInclude Include="Misc.h" />
Expand All @@ -234,9 +220,6 @@
<ClInclude Include="SkinsTab.h" />
<ClInclude Include="Utils.h" />
</ItemGroup>
<ItemGroup>
<None Include="json\json_valueiterator.inl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
50 changes: 0 additions & 50 deletions KBotExt/KBotExt.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="json">
<UniqueIdentifier>{54db2d2d-b22b-4c3c-b6bd-8802952723b6}</UniqueIdentifier>
</Filter>
<Filter Include="Tabs">
<UniqueIdentifier>{7d0b8c55-703b-4c67-b79b-56f9c8dbbf02}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -54,15 +51,6 @@
<ClCompile Include="imgui\imgui_widgets.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="json\json_reader.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="json\json_value.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="json\json_writer.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="LCU.cpp">
<Filter>League</Filter>
</ClCompile>
Expand Down Expand Up @@ -122,39 +110,6 @@
<ClInclude Include="imgui\imstb_textedit.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="json\allocator.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\assertions.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\config.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\forwards.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\json.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\json_features.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\json_tool.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\reader.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\value.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\version.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="json\writer.h">
<Filter>json</Filter>
</ClInclude>
<ClInclude Include="Misc.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -186,9 +141,4 @@
<Filter>imgui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="json\json_valueiterator.inl">
<Filter>json</Filter>
</None>
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions KBotExt/LoginTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class LoginTab
// find saved lang from cfg file
auto findLang = std::ranges::find_if(langs, [](std::pair<std::string, std::string> k) {
return k.second == S.loginTab.language;
});
});

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

if (ImGui::Button("Launch client"))
{
Expand All @@ -122,7 +122,7 @@ class LoginTab
{
if (ImGui::Selectable(fst.c_str(), fst == selectedLang.first))
{
selectedLang = {fst, snd};
selectedLang = { fst, snd };
S.loginTab.language = snd;
Config::Save();

Expand Down Expand Up @@ -249,12 +249,12 @@ class LoginTab
cpr::Session session;
session.SetHeader(authHeader);

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

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

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

session.SetUrl("https://auth.riotgames.com/userinfo");
r = session.Get().text;
Expand Down
Loading

0 comments on commit 172a6d6

Please sign in to comment.