We rise from the ashes

This commit is contained in:
CallowBlack
2022-05-17 03:13:41 +03:00
parent 759118f830
commit 9999f2f9cb
832 changed files with 173179 additions and 8288 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release_WS|x64">
<Configuration>Release_WS</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
@ -24,14 +20,12 @@
<ClCompile Include="src\util.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\simple-ini.hpp" />
<ClInclude Include="src\injector.h" />
<ClInclude Include="src\util.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cheat-library\cheat-library.vcxproj">
<Project>{704c8746-1bd9-4bc8-9ebe-8187f1a1ad72}</Project>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
<ProjectReference Include="..\cheat-base\cheat-base.vcxproj">
<Project>{adb35022-823b-4dc0-b495-3efefbd3a82f}</Project>
</ProjectReference>
</ItemGroup>
<PropertyGroup Label="Globals">
@ -43,19 +37,6 @@
<ProjectName>injector</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
@ -69,88 +50,43 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_WS|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_WS|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\obj\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\obj\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\obj\</IntDir>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\$(Configuration)\obj\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)bin\$(PlatformShortName)\$(Configuration)\obj\</IntDir>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\$(Configuration)\obj\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_WS|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\$(Configuration)\obj\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)include/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)include/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@ -162,7 +98,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SupportJustMyCode>false</SupportJustMyCode>
<AdditionalIncludeDirectories>$(ProjectDir)include/</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)include/;$(SolutionDir)cheat-base/src;$(SolutionDir)cheat-base/vendor/simpleIni/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -170,6 +106,8 @@
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<ImageHasSafeExceptionHandlers>
</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>cheat-base.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
@ -189,7 +127,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)include/</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)include/;$(SolutionDir)cheat-base/src;$(SolutionDir)cheat-base/vendor/simpleIni/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -198,6 +136,34 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>cheat-base.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_WS|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)include/;$(SolutionDir)cheat-base/src;$(SolutionDir)cheat-base/vendor/simpleIni/</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>cheat-base.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>

View File

@ -13,6 +13,9 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Header Files\include">
<UniqueIdentifier>{877f240b-91bb-46cf-8770-6df8379fa27a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp">
@ -32,8 +35,5 @@
<ClInclude Include="src\util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\simple-ini.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -5,7 +5,7 @@
#define IPrintError(text, ...)
#else
#define ILog(text, ...) printf(text, __VA_ARGS__)
#define ILogError(text, ...) ILog(text, __VA_ARGS__); std::cout << "Error: " << GetLastErrorAsString() << std::endl
#define ILogError(text, ...) ILog(text, __VA_ARGS__); std::cout << "Error: " << util::GetLastErrorAsString() << std::endl
#endif
#ifdef _WIN64
@ -14,11 +14,12 @@
#define CURRENT_ARCH IMAGE_FILE_MACHINE_I386
#endif
bool InjectDLL(HANDLE hProc, const std::string& filepath) {
#ifndef _DEBUG // _DEBUG
bool InjectDLL(HANDLE hProc, const std::string& filepath)
{
#ifndef MANUAL_MAP
// Using LoadLibrary inject to be able to debug DLL in attached process.
// NOTE. For debug also needs disable mhyprot protection. (See protection-bypass.h in cheat-library)
// NOTE 2. Also need find way to disable antidebug.
bool result = LoadLibraryInject(hProc, filepath);
#else
std::ifstream file(filepath, std::ios::in | std::ios::binary | std::ios::ate);
@ -45,7 +46,7 @@ bool InjectDLL(HANDLE hProc, const std::string& filepath) {
return result;
}
#ifdef _DEBUG
#ifndef MANUAL_MAP
static bool LoadLibraryInject(HANDLE hProc, const std::string& dllpath)
{
HMODULE hKernel = GetModuleHandle("kernel32.dll");
@ -85,11 +86,11 @@ static bool LoadLibraryInject(HANDLE hProc, const std::string& dllpath)
// TODO: Add waiting for thread end and release unneccessary data.
// VirtualFreeEx(hProc, pDLLPath, 0, MEM_RELEASE);
ILogError("[DLL Injection] Successfully LoadLibraryA injection.\n");
ILog("[DLL Injection] Successfully LoadLibraryA injection.\n");
return true;
}
#endif // _DEBUG
#else
bool ManualMapDll(HANDLE hProc, BYTE* pSrcData, SIZE_T FileSize, bool ClearHeader, bool ClearNonNeededSections, bool AdjustProtections, bool SEHExceptionSupport, DWORD fdwReason) {
IMAGE_NT_HEADERS* pOldNtHeader = nullptr;
@ -409,4 +410,5 @@ void __stdcall Shellcode(MANUAL_MAPPING_DATA* pData) {
pData->hMod = reinterpret_cast<HINSTANCE>(0x505050);
else
pData->hMod = reinterpret_cast<HINSTANCE>(pBase);
}
}
#endif // MANUAL_MAP

View File

@ -39,10 +39,10 @@ struct MANUAL_MAPPING_DATA
bool InjectDLL(HANDLE hProc, const std::string& filepath);
#ifdef _DEBUG
static bool LoadLibraryInject(HANDLE hProc, const std::string& dllpath);
#endif
#ifdef MANUAL_MAP
// Note: Exception support only x64 with build params /EHa or /EHc
bool ManualMapDll(HANDLE hProc, BYTE* pSrcData, SIZE_T FileSize, bool ClearHeader = false, bool ClearNonNeededSections = false, bool AdjustProtections = false, bool SEHExceptionSupport = false, DWORD fdwReason = DLL_PROCESS_ATTACH);
void __stdcall Shellcode(MANUAL_MAPPING_DATA* pData);
bool ManualMapDll(HANDLE hProc, BYTE* pSrcData, SIZE_T FileSize, bool ClearHeader = false, bool ClearNonNeededSections = false, bool AdjustProtections = true, bool SEHExceptionSupport = false, DWORD fdwReason = DLL_PROCESS_ATTACH);
void __stdcall Shellcode(MANUAL_MAPPING_DATA* pData);
#else
static bool LoadLibraryInject(HANDLE hProc, const std::string& dllpath);
#endif

View File

@ -3,23 +3,25 @@
#include <sstream>
#include <filesystem>
#include <SimpleIni.h>
#include <cheat-base/Logger.h>
#include "injector.h"
#include "simple-ini.hpp"
#include "util.h"
const std::string GlobalGenshinProcName = "GenshinImpact.exe";
const std::string ChinaGenshinProcName = "YuanShen.exe";
const char* INIFileName = "config.ini";
static CSimpleIni ini;
HANDLE OpenGenshinProcess();
int main(int argc, char* argv[])
{
Logger::SetLevel(Logger::Level::Debug, Logger::LoggerType::ConsoleLogger);
auto path = std::filesystem::path(argv[0]).parent_path();
std::filesystem::current_path(path);
current_path(path);
WaitForCloseProcess(GlobalGenshinProcName);
WaitForCloseProcess(ChinaGenshinProcName);
@ -27,7 +29,7 @@ int main(int argc, char* argv[])
Sleep(1000); // Wait for unloading all dlls.
ini.SetUnicode();
ini.LoadFile(INIFileName);
ini.LoadFile("cfg.ini");
HANDLE hProcess = OpenGenshinProcess();
if (hProcess == NULL)
@ -36,54 +38,54 @@ int main(int argc, char* argv[])
return 1;
}
ini.SaveFile(INIFileName);
std::filesystem::current_path(path);
current_path(path);
ini.SaveFile("cfg.ini");
std::string filename = (argc == 2 ? argv[1] : "CLibrary.dll");
std::filesystem::path currentDllPath = std::filesystem::current_path() / filename;
#ifdef _DEBUG
std::filesystem::path tempDllPath = std::filesystem::temp_directory_path() / filename;
std::filesystem::copy(currentDllPath, tempDllPath, std::filesystem::copy_options::update_existing);
std::error_code ec;
std::filesystem::copy_file(currentDllPath, tempDllPath, std::filesystem::copy_options::update_existing, ec);
if (ec)
{
LOG_ERROR("Copy dll failed: %s", ec.message().c_str());
std::system("pause");
}
InjectDLL(hProcess, tempDllPath.string());
#else
InjectDLL(hProcess, currentDllPath.string());
#endif
CloseHandle(hProcess);
}
HANDLE OpenGenshinProcess() {
HANDLE OpenGenshinProcess()
{
STARTUPINFOA startInfo{};
PROCESS_INFORMATION processInformation{};
auto savedPath = ini.GetValue("Inject", "GenshinPath");
bool exePathNotExist = savedPath == nullptr;
auto filePath = util::GetOrSelectPath(ini, "Inject", "GenshinPath", "genshin path", "Executable\0GenshinImpact.exe;YuanShen.exe\0");
auto commandline = ini.GetValue("Inject", "GenshinCommandLine");
std::string* filePath = exePathNotExist ? nullptr : new std::string(savedPath);
if (exePathNotExist) {
std::cout << "Genshin path not found. Please point to it manually. ^)" << std::endl;
filePath = GetFilePathByUser();
if (filePath == nullptr) {
std::cout << "Failed to get genshin path from user. Exiting..." << std::endl;
return NULL;
}
}
LPSTR lpstr = commandline == nullptr ? nullptr : const_cast<LPSTR>(commandline);
if (!filePath)
return NULL;
BOOL result = CreateProcessA(filePath->c_str(),
nullptr, 0, 0, false, CREATE_SUSPENDED, nullptr, nullptr, &startInfo, &processInformation);
if (result == FALSE) {
std::cout << "Failed to create game process." << std::endl;
std::cout << "Error: " << GetLastErrorAsString() << std::endl;
std::cout << "If you have problem with GenshinImpact.exe path. You can change it manually in " << INIFileName << "." << std::endl;
lpstr, 0, 0, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &startInfo, &processInformation);
if (result == FALSE)
{
LOG_LAST_ERROR("Failed to create game process.");
LOG_ERROR("If you have problem with GenshinImpact.exe path. You can change it manually in cfg.ini.");
return NULL;
}
if (exePathNotExist) {
ini.SetValue("Inject", "genshinPath", (*filePath).c_str());
std::cout << "New GenshinImpact.exe path saved to " << INIFileName << "." << std::endl;
}
delete filePath;
std::cout << "Created game process." << std::endl;
ini.SaveFile("cfg.ini");
ResumeThread(processInformation.hThread);

View File

@ -4,59 +4,10 @@
#include <iostream>
#include <sstream>
#include <filesystem>
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
std::string GetLastErrorAsString()
int FindProcessId(const std::string& processName)
{
//Get the error message ID, if any.
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0) {
return std::string(); //No error message has been recorded
}
LPSTR messageBuffer = nullptr;
//Ask Win32 to give us the string version of that message ID.
//The parameters we pass in, tell Win32 to create the buffer that holds the message for us (because we don't yet know how long the message string will be).
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
//Copy the error message into a std::string.
std::string message(messageBuffer, size);
//Free the Win32's string's buffer.
LocalFree(messageBuffer);
return message;
}
std::string* GetFilePathByUser() {
// common dialog box structure, setting all fields to 0 is important
OPENFILENAME ofn = { 0 };
TCHAR szFile[260] = { 0 };
// Initialize remaining fields of OPENFILENAME structure
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "Executable\0*.exe\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == TRUE)
{
return new std::string(szFile);
}
return nullptr;
}
int FindProcessId(const std::string& processName) {
int pid = -1;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
@ -81,7 +32,8 @@ int FindProcessId(const std::string& processName) {
return pid;
}
void WaitForCloseProcess(const std::string& processName) {
void WaitForCloseProcess(const std::string& processName)
{
int pid = FindProcessId(processName);
if (pid == -1)
return;

View File

@ -1,9 +1,8 @@
#pragma once
#include <string>
#include <Windows.h>
#pragma once
std::string GetLastErrorAsString();
std::string* GetFilePathByUser();
#include <cheat-base/util.h>
int FindProcessId(const std::string& processName);
void WaitForCloseProcess(const std::string& processName);