Add missing files
This commit is contained in:
parent
f97f249c8a
commit
7a4c0a8938
31
hook_lib.sln
Normal file
31
hook_lib.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.33130.400
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hook_lib", "hook_lib\hook_lib.vcxproj", "{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x64.Build.0 = Debug|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x86.Build.0 = Debug|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x64.ActiveCfg = Release|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x64.Build.0 = Release|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x86.ActiveCfg = Release|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {58937352-3EDA-4AEE-A7FD-C21D6955F38B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
1142
hook_lib/Main.cpp
Normal file
1142
hook_lib/Main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
117
hook_lib/Main.hpp
Normal file
117
hook_lib/Main.hpp
Normal file
@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <winternl.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <dxgi1_5.h>
|
||||
#include <d3d12.h>
|
||||
#include <intrin.h>
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "user32.lib")
|
||||
|
||||
#include "common/utils/hook.hpp"
|
||||
#include "common/utils/hardware_breakpoint.hpp"
|
||||
#include "functions.hpp"
|
||||
#include "structs.h"
|
||||
#include "assets.h"
|
||||
|
||||
#include "ini.h"
|
||||
#include "json.hpp"
|
||||
#include "splashscreen.hpp"
|
||||
|
||||
extern void* exception_handler;
|
||||
|
||||
#define base g_Addrs.ModuleBase
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
|
||||
|
||||
|
||||
|
||||
#define INRANGE(x, a, b) (x >= a && x <= b)
|
||||
#define GET_BITS( x ) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0))
|
||||
#define GET_BYTE( x ) (GET_BITS(x[0]) << 4 | GET_BITS(x[1]))
|
||||
|
||||
struct menu_variables {
|
||||
bool bInitiateMenu;
|
||||
bool bMenuOpen;
|
||||
|
||||
};
|
||||
extern menu_variables vars;
|
||||
|
||||
void nlog(const char* str, ...);
|
||||
uintptr_t find_pattern(const char* module_name, const char* pattern);
|
||||
uintptr_t find_pattern(uintptr_t start, const char* module_name, const char* pattern);
|
||||
|
||||
size_t operator"" _b(size_t val);
|
||||
size_t reverse_b(size_t val);
|
||||
size_t reverse_b(const void* val);
|
||||
|
||||
size_t operator"" _g(size_t val);
|
||||
size_t reverse_g(size_t val);
|
||||
size_t reverse_g(const void* val);
|
||||
|
||||
void log(const char* str);
|
||||
void log(const char* file, const char* str);
|
||||
|
||||
struct DvarPair
|
||||
{
|
||||
const char* m_key;
|
||||
const char* m_value;
|
||||
};
|
||||
inline bool IsBadPointer(uintptr_t* ptr)
|
||||
{
|
||||
__try
|
||||
{
|
||||
volatile auto result = *ptr;
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct DvarMap
|
||||
{
|
||||
DvarPair m_pairs[10000];
|
||||
};
|
||||
extern int g_dvarmapcount;
|
||||
extern DvarPair g_dvarmap[6821];
|
||||
|
||||
struct shaderOverride_t
|
||||
{
|
||||
float scrollRateX;
|
||||
float scrollRateY;
|
||||
float scrollRateR;
|
||||
float tilingX;
|
||||
float tilingY;
|
||||
float rotation;
|
||||
float alpha;
|
||||
float emissive;
|
||||
float atlasTime;
|
||||
};
|
||||
|
||||
struct GfxSceneHudOutlineInfo
|
||||
{
|
||||
unsigned int color;
|
||||
float scopeStencil;
|
||||
bool drawOccludedPixels;
|
||||
bool drawNonOccludedPixels;
|
||||
bool fill;
|
||||
bool useAlternateColor;
|
||||
bool forSpectator;
|
||||
bool specialActive;
|
||||
unsigned __int8 renderMode;
|
||||
unsigned __int8 lineWidth;
|
||||
unsigned __int8 temperatureSet;
|
||||
unsigned int mapEntLookup;
|
||||
float temperatureBase;
|
||||
float temperatureScale;
|
||||
float characterEVOffset;
|
||||
};
|
||||
|
BIN
hook_lib/__game_dx12_ship_replay
Normal file
BIN
hook_lib/__game_dx12_ship_replay
Normal file
Binary file not shown.
6
hook_lib/assets.cpp
Normal file
6
hook_lib/assets.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "assets.h"
|
||||
|
||||
|
||||
void test() {
|
||||
sizeof(VehicleDef);
|
||||
}
|
4383
hook_lib/assets.h
Normal file
4383
hook_lib/assets.h
Normal file
File diff suppressed because it is too large
Load Diff
85
hook_lib/common/exception/minidump.cpp
Normal file
85
hook_lib/common/exception/minidump.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "minidump.hpp"
|
||||
|
||||
#include <DbgHelp.h>
|
||||
#pragma comment(lib, "dbghelp.lib")
|
||||
|
||||
namespace exception
|
||||
{
|
||||
namespace
|
||||
{
|
||||
constexpr MINIDUMP_TYPE get_minidump_type()
|
||||
{
|
||||
constexpr auto type = MiniDumpIgnoreInaccessibleMemory //
|
||||
| MiniDumpWithHandleData //
|
||||
| MiniDumpScanMemory //
|
||||
| MiniDumpWithProcessThreadData //
|
||||
| MiniDumpWithFullMemoryInfo //
|
||||
| MiniDumpWithThreadInfo //
|
||||
| MiniDumpWithUnloadedModules;
|
||||
|
||||
return static_cast<MINIDUMP_TYPE>(type);
|
||||
}
|
||||
|
||||
std::string get_temp_filename()
|
||||
{
|
||||
char filename[MAX_PATH] = {0};
|
||||
char pathname[MAX_PATH] = {0};
|
||||
|
||||
GetTempPathA(sizeof(pathname), pathname);
|
||||
GetTempFileNameA(pathname, "boiii-", 0, filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
HANDLE write_dump_to_temp_file(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
MINIDUMP_EXCEPTION_INFORMATION minidump_exception_info = {GetCurrentThreadId(), exceptioninfo, FALSE};
|
||||
|
||||
auto* const file_handle = CreateFileA(get_temp_filename().data(), GENERIC_WRITE | GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
|
||||
nullptr);
|
||||
|
||||
if (!MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file_handle, get_minidump_type(),
|
||||
&minidump_exception_info,
|
||||
nullptr,
|
||||
nullptr))
|
||||
{
|
||||
MessageBoxA(nullptr, "There was an error creating the minidump! Hit OK to close the program.",
|
||||
"Minidump Error", MB_OK | MB_ICONERROR);
|
||||
TerminateProcess(GetCurrentProcess(), 123);
|
||||
}
|
||||
|
||||
return file_handle;
|
||||
}
|
||||
|
||||
std::string read_file(const HANDLE file_handle)
|
||||
{
|
||||
FlushFileBuffers(file_handle);
|
||||
SetFilePointer(file_handle, 0, nullptr, FILE_BEGIN);
|
||||
|
||||
std::string buffer{};
|
||||
|
||||
DWORD bytes_read = 0;
|
||||
char temp_bytes[0x2000];
|
||||
|
||||
do
|
||||
{
|
||||
if (!ReadFile(file_handle, temp_bytes, sizeof(temp_bytes), &bytes_read, nullptr))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
buffer.append(temp_bytes, bytes_read);
|
||||
}
|
||||
while (bytes_read == sizeof(temp_bytes));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
std::string create_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const utils::nt::handle file_handle = write_dump_to_temp_file(exceptioninfo);
|
||||
return read_file(file_handle);
|
||||
}
|
||||
}
|
8
hook_lib/common/exception/minidump.hpp
Normal file
8
hook_lib/common/exception/minidump.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../utils/nt.hpp"
|
||||
|
||||
namespace exception
|
||||
{
|
||||
std::string create_minidump(LPEXCEPTION_POINTERS exceptioninfo);
|
||||
}
|
185
hook_lib/common/utils/MinHook.hpp
Normal file
185
hook_lib/common/utils/MinHook.hpp
Normal file
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* MinHook - The Minimalistic API Hooking Library for x64/x86
|
||||
* Copyright (C) 2009-2017 Tsuda Kageyu.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__)
|
||||
#error MinHook supports only x86 and x64 systems.
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// MinHook Error Codes.
|
||||
typedef enum MH_STATUS
|
||||
{
|
||||
// Unknown error. Should not be returned.
|
||||
MH_UNKNOWN = -1,
|
||||
|
||||
// Successful.
|
||||
MH_OK = 0,
|
||||
|
||||
// MinHook is already initialized.
|
||||
MH_ERROR_ALREADY_INITIALIZED,
|
||||
|
||||
// MinHook is not initialized yet, or already uninitialized.
|
||||
MH_ERROR_NOT_INITIALIZED,
|
||||
|
||||
// The hook for the specified target function is already created.
|
||||
MH_ERROR_ALREADY_CREATED,
|
||||
|
||||
// The hook for the specified target function is not created yet.
|
||||
MH_ERROR_NOT_CREATED,
|
||||
|
||||
// The hook for the specified target function is already enabled.
|
||||
MH_ERROR_ENABLED,
|
||||
|
||||
// The hook for the specified target function is not enabled yet, or already
|
||||
// disabled.
|
||||
MH_ERROR_DISABLED,
|
||||
|
||||
// The specified pointer is invalid. It points the address of non-allocated
|
||||
// and/or non-executable region.
|
||||
MH_ERROR_NOT_EXECUTABLE,
|
||||
|
||||
// The specified target function cannot be hooked.
|
||||
MH_ERROR_UNSUPPORTED_FUNCTION,
|
||||
|
||||
// Failed to allocate memory.
|
||||
MH_ERROR_MEMORY_ALLOC,
|
||||
|
||||
// Failed to change the memory protection.
|
||||
MH_ERROR_MEMORY_PROTECT,
|
||||
|
||||
// The specified module is not loaded.
|
||||
MH_ERROR_MODULE_NOT_FOUND,
|
||||
|
||||
// The specified function is not found.
|
||||
MH_ERROR_FUNCTION_NOT_FOUND
|
||||
}
|
||||
MH_STATUS;
|
||||
|
||||
// Can be passed as a parameter to MH_EnableHook, MH_DisableHook,
|
||||
// MH_QueueEnableHook or MH_QueueDisableHook.
|
||||
#define MH_ALL_HOOKS NULL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Initialize the MinHook library. You must call this function EXACTLY ONCE
|
||||
// at the beginning of your program.
|
||||
MH_STATUS WINAPI MH_Initialize(VOID);
|
||||
|
||||
// Uninitialize the MinHook library. You must call this function EXACTLY
|
||||
// ONCE at the end of your program.
|
||||
MH_STATUS WINAPI MH_Uninitialize(VOID);
|
||||
|
||||
// Creates a hook for the specified target function, in disabled state.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal);
|
||||
|
||||
// Creates a hook for the specified API function, in disabled state.
|
||||
// Parameters:
|
||||
// pszModule [in] A pointer to the loaded module name which contains the
|
||||
// target function.
|
||||
// pszProcName [in] A pointer to the target function name, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHookApi(
|
||||
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal);
|
||||
|
||||
// Creates a hook for the specified API function, in disabled state.
|
||||
// Parameters:
|
||||
// pszModule [in] A pointer to the loaded module name which contains the
|
||||
// target function.
|
||||
// pszProcName [in] A pointer to the target function name, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
// ppTarget [out] A pointer to the target function, which will be used
|
||||
// with other functions.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHookApiEx(
|
||||
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget);
|
||||
|
||||
// Removes an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget);
|
||||
|
||||
// Enables an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// enabled in one go.
|
||||
MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
|
||||
|
||||
// Disables an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// disabled in one go.
|
||||
MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget);
|
||||
|
||||
// Queues to enable an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// queued to be enabled.
|
||||
MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget);
|
||||
|
||||
// Queues to disable an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// queued to be disabled.
|
||||
MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget);
|
||||
|
||||
// Applies all queued changes in one go.
|
||||
MH_STATUS WINAPI MH_ApplyQueued(VOID);
|
||||
|
||||
// Translates the MH_STATUS to its name as a string.
|
||||
const char * WINAPI MH_StatusToString(MH_STATUS status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
75
hook_lib/common/utils/binary_resource.cpp
Normal file
75
hook_lib/common/utils/binary_resource.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include "binary_resource.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "nt.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::string get_temp_folder()
|
||||
{
|
||||
char path[MAX_PATH] = {0};
|
||||
if (!GetTempPathA(sizeof(path), path))
|
||||
{
|
||||
throw std::runtime_error("Unable to get temp path");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string write_existing_temp_file(const std::string& file, const std::string& data,
|
||||
const bool fatal_if_overwrite_fails)
|
||||
{
|
||||
const auto temp = get_temp_folder();
|
||||
auto file_path = temp + file;
|
||||
|
||||
std::string current_data;
|
||||
if (!io::read_file(file_path, ¤t_data))
|
||||
{
|
||||
if (!io::write_file(file_path, data))
|
||||
{
|
||||
throw std::runtime_error("Failed to write file: " + file_path);
|
||||
}
|
||||
|
||||
return file_path;
|
||||
}
|
||||
|
||||
if (current_data == data || io::write_file(file_path, data) || !fatal_if_overwrite_fails)
|
||||
{
|
||||
return file_path;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"Temporary file was already written, but differs. It can't be overwritten as it's still in use: " +
|
||||
file_path);
|
||||
}
|
||||
}
|
||||
|
||||
binary_resource::binary_resource(const int id, std::string file)
|
||||
: filename_(std::move(file))
|
||||
{
|
||||
this->resource_ = nt::load_resource(id);
|
||||
|
||||
if (this->resource_.empty())
|
||||
{
|
||||
throw std::runtime_error("Unable to load resource: " + std::to_string(id));
|
||||
}
|
||||
}
|
||||
|
||||
std::string binary_resource::get_extracted_file(const bool fatal_if_overwrite_fails)
|
||||
{
|
||||
if (this->path_.empty())
|
||||
{
|
||||
this->path_ = write_existing_temp_file(this->filename_, this->resource_, fatal_if_overwrite_fails);
|
||||
}
|
||||
|
||||
return this->path_;
|
||||
}
|
||||
|
||||
const std::string& binary_resource::get_data() const
|
||||
{
|
||||
return this->resource_;
|
||||
}
|
||||
}
|
20
hook_lib/common/utils/binary_resource.hpp
Normal file
20
hook_lib/common/utils/binary_resource.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class binary_resource
|
||||
{
|
||||
public:
|
||||
binary_resource(int id, std::string file);
|
||||
|
||||
std::string get_extracted_file(bool fatal_if_overwrite_fails = false);
|
||||
const std::string& get_data() const;
|
||||
|
||||
private:
|
||||
std::string resource_;
|
||||
std::string filename_;
|
||||
std::string path_;
|
||||
};
|
||||
}
|
46
hook_lib/common/utils/concurrency.hpp
Normal file
46
hook_lib/common/utils/concurrency.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace utils::concurrency
|
||||
{
|
||||
template <typename T, typename MutexType = std::mutex>
|
||||
class container
|
||||
{
|
||||
public:
|
||||
template <typename R = void, typename F>
|
||||
R access(F&& accessor) const
|
||||
{
|
||||
std::lock_guard<MutexType> _{mutex_};
|
||||
return accessor(object_);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access(F&& accessor)
|
||||
{
|
||||
std::lock_guard<MutexType> _{mutex_};
|
||||
return accessor(object_);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access_with_lock(F&& accessor) const
|
||||
{
|
||||
std::unique_lock<MutexType> lock{mutex_};
|
||||
return accessor(object_, lock);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access_with_lock(F&& accessor)
|
||||
{
|
||||
std::unique_lock<MutexType> lock{mutex_};
|
||||
return accessor(object_, lock);
|
||||
}
|
||||
|
||||
T& get_raw() { return object_; }
|
||||
const T& get_raw() const { return object_; }
|
||||
|
||||
private:
|
||||
mutable MutexType mutex_{};
|
||||
T object_{};
|
||||
};
|
||||
}
|
54
hook_lib/common/utils/finally.hpp
Normal file
54
hook_lib/common/utils/finally.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
/*
|
||||
* Copied from here: https://github.com/microsoft/GSL/blob/e0880931ae5885eb988d1a8a57acf8bc2b8dacda/include/gsl/util#L57
|
||||
*/
|
||||
|
||||
template <class F>
|
||||
class final_action
|
||||
{
|
||||
public:
|
||||
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
|
||||
!std::is_volatile<F>::value,
|
||||
"Final_action should store its callable by value");
|
||||
|
||||
explicit final_action(F f) noexcept : f_(std::move(f))
|
||||
{
|
||||
}
|
||||
|
||||
final_action(final_action&& other) noexcept
|
||||
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
|
||||
{
|
||||
}
|
||||
|
||||
final_action(const final_action&) = delete;
|
||||
final_action& operator=(const final_action&) = delete;
|
||||
final_action& operator=(final_action&&) = delete;
|
||||
|
||||
~final_action() noexcept
|
||||
{
|
||||
if (invoke_) f_();
|
||||
}
|
||||
|
||||
// Added by momo5502
|
||||
void cancel()
|
||||
{
|
||||
invoke_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
bool invoke_{true};
|
||||
};
|
||||
|
||||
template <class F>
|
||||
final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
|
||||
finally(F&& f) noexcept
|
||||
{
|
||||
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
|
||||
std::forward<F>(f));
|
||||
}
|
||||
}
|
173
hook_lib/common/utils/hardware_breakpoint.cpp
Normal file
173
hook_lib/common/utils/hardware_breakpoint.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
#include "hardware_breakpoint.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
|
||||
namespace utils::hardware_breakpoint
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void set_bits(uintptr_t& value, const uint32_t bit_index, const uint32_t bits, const uintptr_t new_value)
|
||||
{
|
||||
const uintptr_t range_mask = (1ull << bits) - 1ull;
|
||||
const uintptr_t full_mask = ~(range_mask << bit_index);
|
||||
value = (value & full_mask) | (new_value << bit_index);
|
||||
}
|
||||
|
||||
void validate_index(const uint32_t index)
|
||||
{
|
||||
if (index >= 4)
|
||||
{
|
||||
throw std::runtime_error("Invalid index");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t translate_length(const uint32_t length)
|
||||
{
|
||||
if (length != 1 && length != 2 && length != 4)
|
||||
{
|
||||
throw std::runtime_error("Invalid length");
|
||||
}
|
||||
|
||||
return length - 1;
|
||||
}
|
||||
|
||||
class debug_context
|
||||
{
|
||||
public:
|
||||
debug_context(uint32_t thread_id)
|
||||
: handle_(thread_id, THREAD_SET_CONTEXT | THREAD_GET_CONTEXT)
|
||||
{
|
||||
if (!this->handle_)
|
||||
{
|
||||
throw std::runtime_error("Unable to access thread");
|
||||
}
|
||||
|
||||
this->context_.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
||||
|
||||
if (!GetThreadContext(this->handle_, &this->context_))
|
||||
{
|
||||
throw std::runtime_error("Unable to get thread context");
|
||||
}
|
||||
}
|
||||
|
||||
~debug_context()
|
||||
{
|
||||
SetThreadContext(this->handle_, &this->context_);
|
||||
}
|
||||
|
||||
debug_context(const debug_context&) = delete;
|
||||
debug_context& operator=(const debug_context&) = delete;
|
||||
|
||||
debug_context(debug_context&& obj) noexcept = delete;
|
||||
debug_context& operator=(debug_context&& obj) noexcept = delete;
|
||||
|
||||
CONTEXT* operator->()
|
||||
{
|
||||
return &this->context_;
|
||||
}
|
||||
|
||||
operator CONTEXT&()
|
||||
{
|
||||
return this->context_;
|
||||
}
|
||||
|
||||
private:
|
||||
thread::handle handle_;
|
||||
CONTEXT context_{};
|
||||
};
|
||||
|
||||
uint32_t find_free_index(const CONTEXT& context)
|
||||
{
|
||||
for (uint32_t i = 0; i < 4; ++i)
|
||||
{
|
||||
if ((context.Dr7 & (1ull << (i << 1ull))) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("No free index");
|
||||
}
|
||||
}
|
||||
|
||||
void set_branch_tracing(const bool enabled, CONTEXT& context)
|
||||
{
|
||||
set_bits(context.Dr7, 8, 1, enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
void set_branch_tracing(const bool enabled, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
set_branch_tracing(enabled, context);
|
||||
}
|
||||
|
||||
uint32_t activate(const uintptr_t address, uint32_t length, const condition cond, CONTEXT& context)
|
||||
{
|
||||
const auto index = find_free_index(context);
|
||||
length = translate_length(length);
|
||||
|
||||
(&context.Dr0)[index] = address;
|
||||
set_bits(context.Dr7, 16 + (index << 2ull), 2, cond);
|
||||
set_bits(context.Dr7, 18 + (index << 2ull), 2, length);
|
||||
set_bits(context.Dr7, index << 1ull, 1, 1);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
uint32_t activate(void* address, const uint32_t length, const condition cond, const uint32_t thread_id)
|
||||
{
|
||||
return activate(reinterpret_cast<uint64_t>(address), length, cond, thread_id);
|
||||
}
|
||||
|
||||
uint32_t activate(const uint64_t address, const uint32_t length, const condition cond, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
return activate(address, length, cond, context);
|
||||
}
|
||||
|
||||
void deactivate_address(const uint64_t address, CONTEXT& context)
|
||||
{
|
||||
for (auto i = 0; i < 4; ++i)
|
||||
{
|
||||
if ((&context.Dr0)[i] == address)
|
||||
{
|
||||
deactivate(i, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deactivate_address(void* address, const uint32_t thread_id)
|
||||
{
|
||||
return deactivate_address(reinterpret_cast<uint64_t>(address), thread_id);
|
||||
}
|
||||
|
||||
void deactivate_address(const uint64_t address, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate_address(address, context);
|
||||
}
|
||||
|
||||
void deactivate(const uint32_t index, CONTEXT& context)
|
||||
{
|
||||
validate_index(index);
|
||||
set_bits(context.Dr7, index << 1ull, 1, 0);
|
||||
}
|
||||
|
||||
void deactivate(const uint32_t index, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate(index, context);
|
||||
}
|
||||
|
||||
void deactivate_all(CONTEXT& context)
|
||||
{
|
||||
context.Dr7 = 0;
|
||||
}
|
||||
|
||||
void deactivate_all(const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate_all(context);
|
||||
}
|
||||
}
|
||||
|
32
hook_lib/common/utils/hardware_breakpoint.hpp
Normal file
32
hook_lib/common/utils/hardware_breakpoint.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include "nt.hpp"
|
||||
|
||||
|
||||
namespace utils::hardware_breakpoint
|
||||
{
|
||||
enum condition
|
||||
{
|
||||
execute = 0,
|
||||
write = 1,
|
||||
read_write = 3
|
||||
};
|
||||
|
||||
|
||||
void set_branch_tracing(bool enabled, CONTEXT& context);
|
||||
void set_branch_tracing(bool enabled, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
uint32_t activate(uint64_t address, uint32_t length, condition cond, CONTEXT& context);
|
||||
uint32_t activate(void* address, uint32_t length, condition cond, uint32_t thread_id = GetCurrentThreadId());
|
||||
uint32_t activate(uint64_t address, uint32_t length, condition cond, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate_address(uint64_t address, CONTEXT& context);
|
||||
void deactivate_address(void* address, uint32_t thread_id = GetCurrentThreadId());
|
||||
void deactivate_address(uint64_t address, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate(uint32_t index, CONTEXT& context);
|
||||
void deactivate(uint32_t index, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate_all(CONTEXT& context);
|
||||
void deactivate_all(uint32_t thread_id = GetCurrentThreadId());
|
||||
}
|
484
hook_lib/common/utils/hook.cpp
Normal file
484
hook_lib/common/utils/hook.cpp
Normal file
@ -0,0 +1,484 @@
|
||||
#include "hook.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "MinHook.hpp"
|
||||
|
||||
#include "concurrency.hpp"
|
||||
#include "string.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
namespace
|
||||
{
|
||||
uint8_t* allocate_somewhere_near(const void* base_address, const size_t size)
|
||||
{
|
||||
size_t offset = 0;
|
||||
while (true)
|
||||
{
|
||||
offset += size;
|
||||
auto* target_address = static_cast<const uint8_t*>(base_address) - offset;
|
||||
if (is_relatively_far(base_address, target_address))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto res = VirtualAlloc(const_cast<uint8_t*>(target_address), size, MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
if (res)
|
||||
{
|
||||
if (is_relatively_far(base_address, target_address))
|
||||
{
|
||||
VirtualFree(res, 0, MEM_RELEASE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<uint8_t*>(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class memory
|
||||
{
|
||||
public:
|
||||
memory() = default;
|
||||
|
||||
memory(const void* ptr)
|
||||
: memory()
|
||||
{
|
||||
this->length_ = 0x1000;
|
||||
this->buffer_ = allocate_somewhere_near(ptr, this->length_);
|
||||
if (!this->buffer_)
|
||||
{
|
||||
throw std::runtime_error("Failed to allocate");
|
||||
}
|
||||
}
|
||||
|
||||
~memory()
|
||||
{
|
||||
if (this->buffer_)
|
||||
{
|
||||
VirtualFree(this->buffer_, 0, MEM_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
memory(memory&& obj) noexcept
|
||||
: memory()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
memory& operator=(memory&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~memory();
|
||||
this->buffer_ = obj.buffer_;
|
||||
this->length_ = obj.length_;
|
||||
this->offset_ = obj.offset_;
|
||||
|
||||
obj.buffer_ = nullptr;
|
||||
obj.length_ = 0;
|
||||
obj.offset_ = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void* allocate(const size_t length)
|
||||
{
|
||||
if (!this->buffer_)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->offset_ + length > this->length_)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto ptr = this->get_ptr();
|
||||
this->offset_ += length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* get_ptr() const
|
||||
{
|
||||
return this->buffer_ + this->offset_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t* buffer_{};
|
||||
size_t length_{};
|
||||
size_t offset_{};
|
||||
};
|
||||
|
||||
void* get_memory_near(const void* address, const size_t size)
|
||||
{
|
||||
static concurrency::container<std::vector<memory>> memory_container{};
|
||||
|
||||
return memory_container.access<void*>([&](std::vector<memory>& memories)
|
||||
{
|
||||
for (auto& memory : memories)
|
||||
{
|
||||
if (!is_relatively_far(address, memory.get_ptr()))
|
||||
{
|
||||
const auto buffer = memory.allocate(size);
|
||||
if (buffer)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memories.emplace_back(address);
|
||||
return memories.back().allocate(size);
|
||||
});
|
||||
}
|
||||
|
||||
void* initialize_min_hook()
|
||||
{
|
||||
static class min_hook_init
|
||||
{
|
||||
public:
|
||||
min_hook_init()
|
||||
{
|
||||
if (MH_Initialize() != MH_OK)
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize MinHook");
|
||||
}
|
||||
}
|
||||
|
||||
~min_hook_init()
|
||||
{
|
||||
MH_Uninitialize();
|
||||
}
|
||||
} min_hook_init;
|
||||
return &min_hook_init;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
detour::detour()
|
||||
{
|
||||
(void)initialize_min_hook();
|
||||
}
|
||||
|
||||
detour::detour(const size_t place, void* target)
|
||||
: detour(reinterpret_cast<void*>(place), target)
|
||||
{
|
||||
}
|
||||
|
||||
detour::detour(void* place, void* target)
|
||||
: detour()
|
||||
{
|
||||
this->create(place, target);
|
||||
}
|
||||
|
||||
detour::~detour()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void detour::enable()
|
||||
{
|
||||
MH_EnableHook(this->place_);
|
||||
if (!this->moved_data_.empty())
|
||||
{
|
||||
this->move();
|
||||
}
|
||||
}
|
||||
|
||||
void detour::disable()
|
||||
{
|
||||
this->un_move();
|
||||
MH_DisableHook(this->place_);
|
||||
}
|
||||
|
||||
void detour::create(void* place, void* target)
|
||||
{
|
||||
this->clear();
|
||||
this->place_ = place;
|
||||
|
||||
if (MH_CreateHook(this->place_, target, &this->original_) != MH_OK)
|
||||
{
|
||||
//throw std::runtime_error(string::va("Unable to create hook at location: %p", this->place_));
|
||||
}
|
||||
|
||||
this->enable();
|
||||
}
|
||||
|
||||
void detour::create(const size_t place, void* target)
|
||||
{
|
||||
MH_Initialize();
|
||||
this->create(reinterpret_cast<void*>(place), target);
|
||||
}
|
||||
|
||||
void detour::clear()
|
||||
{
|
||||
if (this->place_)
|
||||
{
|
||||
this->un_move();
|
||||
MH_RemoveHook(this->place_);
|
||||
}
|
||||
|
||||
this->place_ = nullptr;
|
||||
this->original_ = nullptr;
|
||||
this->moved_data_ = {};
|
||||
}
|
||||
|
||||
void detour::move()
|
||||
{
|
||||
this->moved_data_ = move_hook(this->place_);
|
||||
}
|
||||
|
||||
void* detour::get_place() const
|
||||
{
|
||||
return this->place_;
|
||||
}
|
||||
|
||||
void* detour::get_original() const
|
||||
{
|
||||
return this->original_;
|
||||
}
|
||||
|
||||
void detour::un_move()
|
||||
{
|
||||
if (!this->moved_data_.empty())
|
||||
{
|
||||
copy(this->place_, this->moved_data_.data(), this->moved_data_.size());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::pair<void*, void*>> iat(const nt::library& library, const std::string& target_library, const std::string& process, void* stub)
|
||||
{
|
||||
if (!library.is_valid()) return {};
|
||||
|
||||
auto* const ptr = library.get_iat_entry(target_library, process);
|
||||
if (!ptr) return {};
|
||||
|
||||
DWORD protect;
|
||||
VirtualProtect(ptr, sizeof(*ptr), PAGE_EXECUTE_READWRITE, &protect);
|
||||
|
||||
std::swap(*ptr, stub);
|
||||
|
||||
VirtualProtect(ptr, sizeof(*ptr), protect, &protect);
|
||||
return {{ptr, stub}};
|
||||
}
|
||||
|
||||
void nop(void* place, const size_t length)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
|
||||
std::memset(place, 0x90, length);
|
||||
|
||||
VirtualProtect(place, length, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, length);
|
||||
}
|
||||
|
||||
void nop(const size_t place, const size_t length)
|
||||
{
|
||||
nop(reinterpret_cast<void*>(place), length);
|
||||
}
|
||||
|
||||
void copy(void* place, const void* data, const size_t length)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
|
||||
std::memmove(place, data, length);
|
||||
|
||||
VirtualProtect(place, length, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, length);
|
||||
}
|
||||
|
||||
void copy(const size_t place, const void* data, const size_t length)
|
||||
{
|
||||
copy(reinterpret_cast<void*>(place), data, length);
|
||||
}
|
||||
|
||||
void copy_string(void* place, const char* str)
|
||||
{
|
||||
copy(reinterpret_cast<void*>(place), str, strlen(str) + 1);
|
||||
}
|
||||
|
||||
void copy_string(const size_t place, const char* str)
|
||||
{
|
||||
copy_string(reinterpret_cast<void*>(place), str);
|
||||
}
|
||||
|
||||
bool is_relatively_far(const void* pointer, const void* data, const int offset)
|
||||
{
|
||||
const int64_t diff = size_t(data) - (size_t(pointer) + offset);
|
||||
const auto small_diff = int32_t(diff);
|
||||
return diff != int64_t(small_diff);
|
||||
}
|
||||
|
||||
void call(void* pointer, void* data)
|
||||
{
|
||||
if (is_relatively_far(pointer, data))
|
||||
{
|
||||
auto* trampoline = get_memory_near(pointer, 14);
|
||||
if (!trampoline)
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
|
||||
call(pointer, trampoline);
|
||||
jump(trampoline, data, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t copy_data[5];
|
||||
copy_data[0] = 0xE8;
|
||||
*reinterpret_cast<int32_t*>(©_data[1]) = int32_t(size_t(data) - (size_t(pointer) + 5));
|
||||
|
||||
auto* patch_pointer = PBYTE(pointer);
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
|
||||
void call(const size_t pointer, void* data)
|
||||
{
|
||||
return call(reinterpret_cast<void*>(pointer), data);
|
||||
}
|
||||
|
||||
void call(const size_t pointer, const size_t data)
|
||||
{
|
||||
return call(pointer, reinterpret_cast<void*>(data));
|
||||
}
|
||||
|
||||
void jump(void* pointer, void* data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
static const unsigned char jump_data[] = {
|
||||
0x48, 0xb8, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xff, 0xe0
|
||||
};
|
||||
|
||||
static const unsigned char jump_data_safe[] = {
|
||||
0xFF, 0x25, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
if (!use_far && is_relatively_far(pointer, data))
|
||||
{
|
||||
auto* trampoline = get_memory_near(pointer, 14);
|
||||
if (!trampoline)
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
jump(pointer, trampoline, false, false);
|
||||
jump(trampoline, data, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
auto* patch_pointer = PBYTE(pointer);
|
||||
|
||||
if (use_far)
|
||||
{
|
||||
if (use_safe)
|
||||
{
|
||||
uint8_t copy_data[sizeof(jump_data_safe) + sizeof(data)];
|
||||
memcpy(copy_data, jump_data_safe, sizeof(jump_data_safe));
|
||||
memcpy(copy_data + sizeof(jump_data_safe), &data, sizeof(data));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t copy_data[sizeof(jump_data)];
|
||||
memcpy(copy_data, jump_data, sizeof(jump_data));
|
||||
memcpy(copy_data + 2, &data, sizeof(data));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t copy_data[5];
|
||||
copy_data[0] = 0xE9;
|
||||
*reinterpret_cast<int32_t*>(©_data[1]) = int32_t(size_t(data) - (size_t(pointer) + 5));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
}
|
||||
|
||||
void jump(const size_t pointer, void* data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
return jump(reinterpret_cast<void*>(pointer), data, use_far, use_safe);
|
||||
}
|
||||
|
||||
void jump(const size_t pointer, const size_t data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
return jump(pointer, reinterpret_cast<void*>(data), use_far, use_safe);
|
||||
}
|
||||
|
||||
|
||||
void inject(void* pointer, const void* data)
|
||||
{
|
||||
if (is_relatively_far(pointer, data, 4))
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
|
||||
set<int32_t>(pointer, int32_t(size_t(data) - (size_t(pointer) + 4)));
|
||||
}
|
||||
|
||||
void inject(const size_t pointer, const void* data)
|
||||
{
|
||||
return inject(reinterpret_cast<void*>(pointer), data);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> move_hook(void* pointer)
|
||||
{
|
||||
std::vector<uint8_t> original_data{};
|
||||
|
||||
auto* data_ptr = static_cast<uint8_t*>(pointer);
|
||||
if (data_ptr[0] == 0xE9)
|
||||
{
|
||||
original_data.resize(6);
|
||||
memmove(original_data.data(), pointer, original_data.size());
|
||||
|
||||
auto* target = follow_branch(data_ptr);
|
||||
nop(data_ptr, 1);
|
||||
jump(data_ptr + 1, target);
|
||||
}
|
||||
else if (data_ptr[0] == 0xFF && data_ptr[1] == 0x25)
|
||||
{
|
||||
original_data.resize(15);
|
||||
memmove(original_data.data(), pointer, original_data.size());
|
||||
|
||||
copy(data_ptr + 1, data_ptr, 14);
|
||||
nop(data_ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("No branch instruction found");
|
||||
}
|
||||
|
||||
return original_data;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> move_hook(const size_t pointer)
|
||||
{
|
||||
return move_hook(reinterpret_cast<void*>(pointer));
|
||||
}
|
||||
|
||||
void* follow_branch(void* address)
|
||||
{
|
||||
auto* const data = static_cast<uint8_t*>(address);
|
||||
if (*data != 0xE8 && *data != 0xE9)
|
||||
{
|
||||
throw std::runtime_error("No branch instruction found");
|
||||
}
|
||||
|
||||
return extract<void*>(data + 1);
|
||||
}
|
||||
}
|
186
hook_lib/common/utils/hook.hpp
Normal file
186
hook_lib/common/utils/hook.hpp
Normal file
@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
#include "signature.hpp"
|
||||
|
||||
#pragma comment(lib, "minhook.lib")
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <size_t Entries>
|
||||
std::vector<size_t(*)()> get_iota_functions()
|
||||
{
|
||||
if constexpr (Entries == 0)
|
||||
{
|
||||
std::vector<size_t(*)()> functions;
|
||||
return functions;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto functions = get_iota_functions<Entries - 1>();
|
||||
functions.emplace_back([]()
|
||||
{
|
||||
return Entries - 1;
|
||||
});
|
||||
return functions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the pointer to the entry in the v-table.
|
||||
// It seems otherwise impossible to get this.
|
||||
// This is ugly as fuck and only safely works on x64
|
||||
// Example:
|
||||
// ID3D11Device* device = ...
|
||||
// auto entry = get_vtable_entry(device, &ID3D11Device::CreateTexture2D);
|
||||
template <size_t Entries = 100, typename Class, typename T, typename... Args>
|
||||
void** get_vtable_entry(Class* obj, T (Class::* entry)(Args ...))
|
||||
{
|
||||
union
|
||||
{
|
||||
decltype(entry) func;
|
||||
void* pointer;
|
||||
};
|
||||
|
||||
func = entry;
|
||||
|
||||
auto iota_functions = detail::get_iota_functions<Entries>();
|
||||
auto* object = iota_functions.data();
|
||||
|
||||
using fake_func = size_t(__thiscall*)(void* self);
|
||||
auto index = static_cast<fake_func>(pointer)(&object);
|
||||
|
||||
void** obj_v_table = *reinterpret_cast<void***>(obj);
|
||||
return &obj_v_table[index];
|
||||
}
|
||||
|
||||
|
||||
class detour
|
||||
{
|
||||
public:
|
||||
detour();
|
||||
detour(void* place, void* target);
|
||||
detour(size_t place, void* target);
|
||||
~detour();
|
||||
|
||||
detour(detour&& other) noexcept
|
||||
{
|
||||
this->operator=(std::move(other));
|
||||
}
|
||||
|
||||
detour& operator=(detour&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
this->clear();
|
||||
|
||||
this->place_ = other.place_;
|
||||
this->original_ = other.original_;
|
||||
this->moved_data_ = other.moved_data_;
|
||||
|
||||
other.place_ = nullptr;
|
||||
other.original_ = nullptr;
|
||||
other.moved_data_ = {};
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
detour(const detour&) = delete;
|
||||
detour& operator=(const detour&) = delete;
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
void create(void* place, void* target);
|
||||
void create(size_t place, void* target);
|
||||
void clear();
|
||||
|
||||
void move();
|
||||
|
||||
void* get_place() const;
|
||||
|
||||
template <typename T>
|
||||
T* get() const
|
||||
{
|
||||
return static_cast<T*>(this->get_original());
|
||||
}
|
||||
|
||||
template <typename T = void, typename... Args>
|
||||
T stub(Args ... args)
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(this->get_original())(args...);
|
||||
}
|
||||
|
||||
[[nodiscard]] void* get_original() const;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> moved_data_{};
|
||||
void* place_{};
|
||||
void* original_{};
|
||||
|
||||
void un_move();
|
||||
};
|
||||
|
||||
std::optional<std::pair<void*, void*>> iat(const nt::library& library, const std::string& target_library,
|
||||
const std::string& process, void* stub);
|
||||
|
||||
void nop(void* place, size_t length);
|
||||
void nop(size_t place, size_t length);
|
||||
|
||||
void copy(void* place, const void* data, size_t length);
|
||||
void copy(size_t place, const void* data, size_t length);
|
||||
|
||||
void copy_string(void* place, const char* str);
|
||||
void copy_string(size_t place, const char* str);
|
||||
|
||||
bool is_relatively_far(const void* pointer, const void* data, int offset = 5);
|
||||
|
||||
void call(void* pointer, void* data);
|
||||
void call(size_t pointer, void* data);
|
||||
void call(size_t pointer, size_t data);
|
||||
|
||||
void jump(void* pointer, void* data, bool use_far = false, bool use_safe = false);
|
||||
void jump(size_t pointer, void* data, bool use_far = false, bool use_safe = false);
|
||||
void jump(size_t pointer, size_t data, bool use_far = false, bool use_safe = false);
|
||||
|
||||
void inject(void* pointer, const void* data);
|
||||
void inject(size_t pointer, const void* data);
|
||||
|
||||
std::vector<uint8_t> move_hook(void* pointer);
|
||||
std::vector<uint8_t> move_hook(size_t pointer);
|
||||
|
||||
template <typename T>
|
||||
T extract(void* address)
|
||||
{
|
||||
auto* const data = static_cast<uint8_t*>(address);
|
||||
const auto offset = *reinterpret_cast<int32_t*>(data);
|
||||
return reinterpret_cast<T>(data + offset + 4);
|
||||
}
|
||||
|
||||
void* follow_branch(void* address);
|
||||
|
||||
template <typename T>
|
||||
static void set(void* place, T value = false)
|
||||
{
|
||||
copy(place, &value, sizeof(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void set(const size_t place, T value = false)
|
||||
{
|
||||
return set<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T invoke(size_t func, Args ... args)
|
||||
{
|
||||
return reinterpret_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T invoke(void* func, Args ... args)
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
}
|
48
hook_lib/common/utils/http.cpp
Normal file
48
hook_lib/common/utils/http.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "http.hpp"
|
||||
#include "nt.hpp"
|
||||
#include <atlcomcli.h>
|
||||
|
||||
namespace utils::http
|
||||
{
|
||||
std::optional<std::string> get_data(const std::string& url)
|
||||
{
|
||||
CComPtr<IStream> stream;
|
||||
|
||||
if (FAILED(URLOpenBlockingStreamA(nullptr, url.data(), &stream, 0, nullptr)))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
char buffer[0x1000];
|
||||
std::string result;
|
||||
|
||||
HRESULT status{};
|
||||
|
||||
do
|
||||
{
|
||||
DWORD bytes_read = 0;
|
||||
status = stream->Read(buffer, sizeof(buffer), &bytes_read);
|
||||
|
||||
if (bytes_read > 0)
|
||||
{
|
||||
result.append(buffer, bytes_read);
|
||||
}
|
||||
}
|
||||
while (SUCCEEDED(status) && status != S_FALSE);
|
||||
|
||||
if (FAILED(status))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return {result};
|
||||
}
|
||||
|
||||
std::future<std::optional<std::string>> get_data_async(const std::string& url)
|
||||
{
|
||||
return std::async(std::launch::async, [url]()
|
||||
{
|
||||
return get_data(url);
|
||||
});
|
||||
}
|
||||
}
|
13
hook_lib/common/utils/http.hpp
Normal file
13
hook_lib/common/utils/http.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <future>
|
||||
|
||||
#pragma comment(lib, "Urlmon.lib")
|
||||
|
||||
namespace utils::http
|
||||
{
|
||||
std::optional<std::string> get_data(const std::string& url);
|
||||
std::future<std::optional<std::string>> get_data_async(const std::string& url);
|
||||
}
|
130
hook_lib/common/utils/io.cpp
Normal file
130
hook_lib/common/utils/io.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
#include "io.hpp"
|
||||
#include "nt.hpp"
|
||||
#include <fstream>
|
||||
|
||||
namespace utils::io
|
||||
{
|
||||
bool remove_file(const std::filesystem::path& file)
|
||||
{
|
||||
if(DeleteFileW(file.wstring().data()) != FALSE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetLastError() == ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
bool move_file(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
return MoveFileW(src.wstring().data(), target.wstring().data()) == TRUE;
|
||||
}
|
||||
|
||||
bool file_exists(const std::string& file)
|
||||
{
|
||||
return std::ifstream(file).good();
|
||||
}
|
||||
|
||||
bool write_file(const std::string& file, const std::string& data, const bool append)
|
||||
{
|
||||
const auto pos = file.find_last_of("/\\");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
create_directory(file.substr(0, pos));
|
||||
}
|
||||
|
||||
std::ofstream stream(
|
||||
file, std::ios::binary | std::ofstream::out | (append ? std::ofstream::app : 0));
|
||||
|
||||
if (stream.is_open())
|
||||
{
|
||||
stream.write(data.data(), static_cast<std::streamsize>(data.size()));
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string read_file(const std::string& file)
|
||||
{
|
||||
std::string data;
|
||||
read_file(file, &data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool read_file(const std::string& file, std::string* data)
|
||||
{
|
||||
if (!data) return false;
|
||||
data->clear();
|
||||
|
||||
if (file_exists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
if (!stream.is_open()) return false;
|
||||
|
||||
stream.seekg(0, std::ios::end);
|
||||
const std::streamsize size = stream.tellg();
|
||||
stream.seekg(0, std::ios::beg);
|
||||
|
||||
if (size > -1)
|
||||
{
|
||||
data->resize(static_cast<std::uint32_t>(size));
|
||||
stream.read(data->data(), size);
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t file_size(const std::string& file)
|
||||
{
|
||||
if (file_exists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
|
||||
if (stream.good())
|
||||
{
|
||||
stream.seekg(0, std::ios::end);
|
||||
return static_cast<std::size_t>(stream.tellg());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool create_directory(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::create_directories(directory);
|
||||
}
|
||||
|
||||
bool directory_exists(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::is_directory(directory);
|
||||
}
|
||||
|
||||
bool directory_is_empty(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::is_empty(directory);
|
||||
}
|
||||
|
||||
std::vector<std::string> list_files(const std::filesystem::path& directory)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
for (auto& file : std::filesystem::directory_iterator(directory))
|
||||
{
|
||||
files.push_back(file.path().generic_string());
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
std::filesystem::copy(src, target,
|
||||
std::filesystem::copy_options::overwrite_existing |
|
||||
std::filesystem::copy_options::recursive);
|
||||
}
|
||||
}
|
21
hook_lib/common/utils/io.hpp
Normal file
21
hook_lib/common/utils/io.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils::io
|
||||
{
|
||||
bool remove_file(const std::filesystem::path& file);
|
||||
bool move_file(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
bool file_exists(const std::string& file);
|
||||
bool write_file(const std::string& file, const std::string& data, bool append = false);
|
||||
bool read_file(const std::string& file, std::string* data);
|
||||
std::string read_file(const std::string& file);
|
||||
size_t file_size(const std::string& file);
|
||||
bool create_directory(const std::filesystem::path& directory);
|
||||
bool directory_exists(const std::filesystem::path& directory);
|
||||
bool directory_is_empty(const std::filesystem::path& directory);
|
||||
std::vector<std::string> list_files(const std::filesystem::path& directory);
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
}
|
170
hook_lib/common/utils/memory.cpp
Normal file
170
hook_lib/common/utils/memory.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
#include "memory.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
memory::allocator memory::mem_allocator_;
|
||||
|
||||
memory::allocator::~allocator()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void memory::allocator::clear()
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
for (auto& data : this->pool_)
|
||||
{
|
||||
memory::free(data);
|
||||
}
|
||||
|
||||
this->pool_.clear();
|
||||
}
|
||||
|
||||
void memory::allocator::free(void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
if (j != this->pool_.end())
|
||||
{
|
||||
memory::free(data);
|
||||
this->pool_.erase(j);
|
||||
}
|
||||
}
|
||||
|
||||
void memory::allocator::free(const void* data)
|
||||
{
|
||||
this->free(const_cast<void*>(data));
|
||||
}
|
||||
|
||||
void* memory::allocator::allocate(const size_t length)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto data = memory::allocate(length);
|
||||
this->pool_.push_back(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool memory::allocator::empty() const
|
||||
{
|
||||
return this->pool_.empty();
|
||||
}
|
||||
|
||||
char* memory::allocator::duplicate_string(const std::string& string)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto data = memory::duplicate_string(string);
|
||||
this->pool_.push_back(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool memory::allocator::find(const void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
return j != this->pool_.end();
|
||||
}
|
||||
|
||||
void* memory::allocate(const size_t length)
|
||||
{
|
||||
return std::calloc(length, 1);
|
||||
}
|
||||
|
||||
char* memory::duplicate_string(const std::string& string)
|
||||
{
|
||||
const auto new_string = allocate_array<char>(string.size() + 1);
|
||||
std::memcpy(new_string, string.data(), string.size());
|
||||
return new_string;
|
||||
}
|
||||
|
||||
void memory::free(void* data)
|
||||
{
|
||||
std::free(data);
|
||||
}
|
||||
|
||||
void memory::free(const void* data)
|
||||
{
|
||||
free(const_cast<void*>(data));
|
||||
}
|
||||
|
||||
bool memory::is_set(const void* mem, const char chr, const size_t length)
|
||||
{
|
||||
const auto mem_arr = static_cast<const char*>(mem);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
if (mem_arr[i] != chr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_bad_read_ptr(const void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi = {};
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(mbi)))
|
||||
{
|
||||
const DWORD mask = (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ |
|
||||
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
|
||||
auto b = !(mbi.Protect & mask);
|
||||
// check the page is not a guard page
|
||||
if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = true;
|
||||
|
||||
return b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_bad_code_ptr(const void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi = {};
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(mbi)))
|
||||
{
|
||||
const DWORD mask = (PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
|
||||
auto b = !(mbi.Protect & mask);
|
||||
// check the page is not a guard page
|
||||
if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = true;
|
||||
|
||||
return b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_rdata_ptr(void* pointer)
|
||||
{
|
||||
const std::string rdata = ".rdata";
|
||||
const auto pointer_lib = utils::nt::library::get_by_address(pointer);
|
||||
|
||||
for (const auto& section : pointer_lib.get_section_headers())
|
||||
{
|
||||
const auto size = sizeof(section->Name);
|
||||
char name[size + 1];
|
||||
name[size] = 0;
|
||||
std::memcpy(name, section->Name, size);
|
||||
|
||||
if (name == rdata)
|
||||
{
|
||||
const auto target = size_t(pointer);
|
||||
const size_t source_start = size_t(pointer_lib.get_ptr()) + section->PointerToRawData;
|
||||
const size_t source_end = source_start + section->SizeOfRawData;
|
||||
|
||||
return target >= source_start && target <= source_end;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
memory::allocator* memory::get_allocator()
|
||||
{
|
||||
return &memory::mem_allocator_;
|
||||
}
|
||||
}
|
77
hook_lib/common/utils/memory.hpp
Normal file
77
hook_lib/common/utils/memory.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class memory final
|
||||
{
|
||||
public:
|
||||
class allocator final
|
||||
{
|
||||
public:
|
||||
~allocator();
|
||||
|
||||
void clear();
|
||||
|
||||
void free(void* data);
|
||||
|
||||
void free(const void* data);
|
||||
|
||||
void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
T* allocate()
|
||||
{
|
||||
return this->allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
bool empty() const;
|
||||
|
||||
char* duplicate_string(const std::string& string);
|
||||
|
||||
bool find(const void* data);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::vector<void*> pool_;
|
||||
};
|
||||
|
||||
static void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
static T* allocate()
|
||||
{
|
||||
return allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
static char* duplicate_string(const std::string& string);
|
||||
|
||||
static void free(void* data);
|
||||
static void free(const void* data);
|
||||
|
||||
static bool is_set(const void* mem, char chr, size_t length);
|
||||
|
||||
static bool is_bad_read_ptr(const void* ptr);
|
||||
static bool is_bad_code_ptr(const void* ptr);
|
||||
static bool is_rdata_ptr(void* ptr);
|
||||
|
||||
static allocator* get_allocator();
|
||||
|
||||
private:
|
||||
static allocator mem_allocator_;
|
||||
};
|
||||
}
|
291
hook_lib/common/utils/nt.cpp
Normal file
291
hook_lib/common/utils/nt.cpp
Normal file
@ -0,0 +1,291 @@
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::nt
|
||||
{
|
||||
library library::load(const char* name)
|
||||
{
|
||||
return library(LoadLibraryA(name));
|
||||
}
|
||||
|
||||
library library::load(const std::string& name)
|
||||
{
|
||||
return library::load(name.data());
|
||||
}
|
||||
|
||||
library library::load(const std::filesystem::path& path)
|
||||
{
|
||||
return library::load(path.generic_string());
|
||||
}
|
||||
|
||||
library library::get_by_address(const void* address)
|
||||
{
|
||||
HMODULE handle = nullptr;
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
static_cast<LPCSTR>(address), &handle);
|
||||
return library(handle);
|
||||
}
|
||||
|
||||
library::library()
|
||||
: module_(GetModuleHandleA(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
library::library(const std::string& name)
|
||||
: module_(GetModuleHandleA(name.data()))
|
||||
{
|
||||
}
|
||||
|
||||
library::library(const HMODULE handle)
|
||||
: module_(handle)
|
||||
{
|
||||
}
|
||||
|
||||
bool library::operator==(const library& obj) const
|
||||
{
|
||||
return this->module_ == obj.module_;
|
||||
}
|
||||
|
||||
library::operator bool() const
|
||||
{
|
||||
return this->is_valid();
|
||||
}
|
||||
|
||||
library::operator HMODULE() const
|
||||
{
|
||||
return this->get_handle();
|
||||
}
|
||||
|
||||
PIMAGE_NT_HEADERS library::get_nt_headers() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return reinterpret_cast<PIMAGE_NT_HEADERS>(this->get_ptr() + this->get_dos_header()->e_lfanew);
|
||||
}
|
||||
|
||||
PIMAGE_DOS_HEADER library::get_dos_header() const
|
||||
{
|
||||
return reinterpret_cast<PIMAGE_DOS_HEADER>(this->get_ptr());
|
||||
}
|
||||
|
||||
PIMAGE_OPTIONAL_HEADER library::get_optional_header() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return &this->get_nt_headers()->OptionalHeader;
|
||||
}
|
||||
|
||||
std::vector<PIMAGE_SECTION_HEADER> library::get_section_headers() const
|
||||
{
|
||||
std::vector<PIMAGE_SECTION_HEADER> headers;
|
||||
|
||||
auto nt_headers = this->get_nt_headers();
|
||||
auto section = IMAGE_FIRST_SECTION(nt_headers);
|
||||
|
||||
for (uint16_t i = 0; i < nt_headers->FileHeader.NumberOfSections; ++i, ++section)
|
||||
{
|
||||
if (section) headers.push_back(section);
|
||||
else OutputDebugStringA("There was an invalid section :O");
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
std::uint8_t* library::get_ptr() const
|
||||
{
|
||||
return reinterpret_cast<std::uint8_t*>(this->module_);
|
||||
}
|
||||
|
||||
void library::unprotect() const
|
||||
{
|
||||
if (!this->is_valid()) return;
|
||||
|
||||
DWORD protection;
|
||||
VirtualProtect(this->get_ptr(), this->get_optional_header()->SizeOfImage, PAGE_EXECUTE_READWRITE,
|
||||
&protection);
|
||||
}
|
||||
|
||||
size_t library::get_relative_entry_point() const
|
||||
{
|
||||
if (!this->is_valid()) return 0;
|
||||
return this->get_nt_headers()->OptionalHeader.AddressOfEntryPoint;
|
||||
}
|
||||
|
||||
void* library::get_entry_point() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return this->get_ptr() + this->get_relative_entry_point();
|
||||
}
|
||||
|
||||
bool library::is_valid() const
|
||||
{
|
||||
return this->module_ != nullptr && this->get_dos_header()->e_magic == IMAGE_DOS_SIGNATURE;
|
||||
}
|
||||
|
||||
std::string library::get_name() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
const auto path = this->get_path();
|
||||
const auto pos = path.generic_string().find_last_of("/\\");
|
||||
if (pos == std::string::npos) return path.generic_string();
|
||||
|
||||
return path.generic_string().substr(pos + 1);
|
||||
}
|
||||
|
||||
std::filesystem::path library::get_path() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
wchar_t name[MAX_PATH] = {0};
|
||||
GetModuleFileNameW(this->module_, name, MAX_PATH);
|
||||
|
||||
return {name};
|
||||
}
|
||||
|
||||
std::filesystem::path library::get_folder() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
const auto path = std::filesystem::path(this->get_path());
|
||||
return path.parent_path().generic_string();
|
||||
}
|
||||
|
||||
void library::free()
|
||||
{
|
||||
if (this->is_valid())
|
||||
{
|
||||
FreeLibrary(this->module_);
|
||||
this->module_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HMODULE library::get_handle() const
|
||||
{
|
||||
return this->module_;
|
||||
}
|
||||
|
||||
void** library::get_iat_entry(const std::string& module_name, const std::string& proc_name) const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
|
||||
const library other_module(module_name);
|
||||
if (!other_module.is_valid()) return nullptr;
|
||||
|
||||
auto* const target_function = other_module.get_proc<void*>(proc_name);
|
||||
if (!target_function) return nullptr;
|
||||
|
||||
auto* header = this->get_optional_header();
|
||||
if (!header) return nullptr;
|
||||
|
||||
auto* import_descriptor = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(this->get_ptr() + header->DataDirectory
|
||||
[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||
|
||||
while (import_descriptor->Name)
|
||||
{
|
||||
if (!_stricmp(reinterpret_cast<char*>(this->get_ptr() + import_descriptor->Name), module_name.data()))
|
||||
{
|
||||
auto* original_thunk_data = reinterpret_cast<PIMAGE_THUNK_DATA>(import_descriptor->
|
||||
OriginalFirstThunk + this->get_ptr());
|
||||
auto* thunk_data = reinterpret_cast<PIMAGE_THUNK_DATA>(import_descriptor->FirstThunk + this->
|
||||
get_ptr());
|
||||
|
||||
while (original_thunk_data->u1.AddressOfData)
|
||||
{
|
||||
if (thunk_data->u1.Function == reinterpret_cast<uint64_t>(target_function))
|
||||
{
|
||||
return reinterpret_cast<void**>(&thunk_data->u1.Function);
|
||||
}
|
||||
|
||||
const size_t ordinal_number = original_thunk_data->u1.AddressOfData & 0xFFFFFFF;
|
||||
|
||||
if (ordinal_number <= 0xFFFF)
|
||||
{
|
||||
auto* proc = GetProcAddress(other_module.module_, reinterpret_cast<char*>(ordinal_number));
|
||||
if (reinterpret_cast<void*>(proc) == target_function)
|
||||
{
|
||||
return reinterpret_cast<void**>(&thunk_data->u1.Function);
|
||||
}
|
||||
}
|
||||
|
||||
++original_thunk_data;
|
||||
++thunk_data;
|
||||
}
|
||||
|
||||
//break;
|
||||
}
|
||||
|
||||
++import_descriptor;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool is_wine()
|
||||
{
|
||||
static const auto has_wine_export = []() -> bool
|
||||
{
|
||||
const library ntdll("ntdll.dll");
|
||||
return ntdll.get_proc<void*>("wine_get_version");
|
||||
}();
|
||||
|
||||
return has_wine_export;
|
||||
}
|
||||
|
||||
bool is_shutdown_in_progress()
|
||||
{
|
||||
static auto* shutdown_in_progress = []
|
||||
{
|
||||
const library ntdll("ntdll.dll");
|
||||
return ntdll.get_proc<BOOLEAN(*)()>("RtlDllShutdownInProgress");
|
||||
}();
|
||||
|
||||
return shutdown_in_progress();
|
||||
}
|
||||
|
||||
void raise_hard_exception()
|
||||
{
|
||||
int data = false;
|
||||
const library ntdll("ntdll.dll");
|
||||
ntdll.invoke_pascal<void>("RtlAdjustPrivilege", 19, true, false, &data);
|
||||
ntdll.invoke_pascal<void>("NtRaiseHardError", 0xC000007B, 0, nullptr, nullptr, 6, &data);
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
std::string load_resource(const int id)
|
||||
{
|
||||
const auto lib = library::get_by_address(load_resource);
|
||||
auto* const res = FindResource(lib, MAKEINTRESOURCE(id), RT_RCDATA);
|
||||
if (!res) return {};
|
||||
|
||||
auto* const handle = LoadResource(lib, res);
|
||||
if (!handle) return {};
|
||||
|
||||
return std::string(LPSTR(LockResource(handle)), SizeofResource(lib, res));
|
||||
}
|
||||
|
||||
void relaunch_self()
|
||||
{
|
||||
const auto self = utils::nt::library::get_by_address(relaunch_self);
|
||||
|
||||
STARTUPINFOA startup_info;
|
||||
PROCESS_INFORMATION process_info;
|
||||
|
||||
ZeroMemory(&startup_info, sizeof(startup_info));
|
||||
ZeroMemory(&process_info, sizeof(process_info));
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
|
||||
char current_dir[MAX_PATH];
|
||||
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
|
||||
auto* const command_line = GetCommandLineA();
|
||||
|
||||
CreateProcessA(self.get_path().generic_string().data(), command_line, nullptr, nullptr, false, NULL, nullptr, current_dir,
|
||||
&startup_info, &process_info);
|
||||
|
||||
if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread);
|
||||
if (process_info.hProcess && process_info.hProcess != INVALID_HANDLE_VALUE) CloseHandle(process_info.hProcess);
|
||||
}
|
||||
|
||||
void terminate(const uint32_t code)
|
||||
{
|
||||
TerminateProcess(GetCurrentProcess(), code);
|
||||
_Exit(code);
|
||||
}
|
||||
}
|
177
hook_lib/common/utils/nt.hpp
Normal file
177
hook_lib/common/utils/nt.hpp
Normal file
@ -0,0 +1,177 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
// min and max is required by gdi, therefore NOMINMAX won't work
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils::nt
|
||||
{
|
||||
class library final
|
||||
{
|
||||
public:
|
||||
static library load(const char* name);
|
||||
static library load(const std::string& name);
|
||||
static library load(const std::filesystem::path& path);
|
||||
static library get_by_address(const void* address);
|
||||
|
||||
library();
|
||||
explicit library(const std::string& name);
|
||||
explicit library(HMODULE handle);
|
||||
|
||||
library(const library& a) : module_(a.module_)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator!=(const library& obj) const { return !(*this == obj); };
|
||||
bool operator==(const library& obj) const;
|
||||
|
||||
operator bool() const;
|
||||
operator HMODULE() const;
|
||||
|
||||
void unprotect() const;
|
||||
[[nodiscard]] void* get_entry_point() const;
|
||||
[[nodiscard]] size_t get_relative_entry_point() const;
|
||||
|
||||
[[nodiscard]] bool is_valid() const;
|
||||
[[nodiscard]] std::string get_name() const;
|
||||
[[nodiscard]] std::filesystem::path get_path() const;
|
||||
[[nodiscard]] std::filesystem::path get_folder() const;
|
||||
[[nodiscard]] std::uint8_t* get_ptr() const;
|
||||
void free();
|
||||
|
||||
[[nodiscard]] HMODULE get_handle() const;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T get_proc(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) T{};
|
||||
return reinterpret_cast<T>(GetProcAddress(this->module_, process.data()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] std::function<T> get(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) return std::function<T>();
|
||||
return static_cast<T*>(this->get_proc<void*>(process));
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__cdecl)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_pascal(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__stdcall)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_this(const std::string& process, void* this_ptr, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__thiscall)(void*, Args ...)>(this_ptr, process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<PIMAGE_SECTION_HEADER> get_section_headers() const;
|
||||
|
||||
[[nodiscard]] PIMAGE_NT_HEADERS get_nt_headers() const;
|
||||
[[nodiscard]] PIMAGE_DOS_HEADER get_dos_header() const;
|
||||
[[nodiscard]] PIMAGE_OPTIONAL_HEADER get_optional_header() const;
|
||||
|
||||
[[nodiscard]] void** get_iat_entry(const std::string& module_name, const std::string& proc_name) const;
|
||||
|
||||
private:
|
||||
HMODULE module_;
|
||||
};
|
||||
|
||||
template <HANDLE InvalidHandle = nullptr>
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle() = default;
|
||||
|
||||
handle(const HANDLE h)
|
||||
: handle_(h)
|
||||
{
|
||||
}
|
||||
|
||||
~handle()
|
||||
{
|
||||
if (*this)
|
||||
{
|
||||
CloseHandle(this->handle_);
|
||||
this->handle_ = InvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
handle(const handle&) = delete;
|
||||
handle& operator=(const handle&) = delete;
|
||||
|
||||
handle(handle&& obj) noexcept
|
||||
: handle()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
handle& operator=(handle&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~handle();
|
||||
this->handle_ = obj.handle_;
|
||||
obj.handle_ = InvalidHandle;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
handle& operator=(HANDLE h) noexcept
|
||||
{
|
||||
this->~handle();
|
||||
this->handle_ = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->handle_ != InvalidHandle;
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE handle_{InvalidHandle};
|
||||
};
|
||||
|
||||
bool is_wine();
|
||||
bool is_shutdown_in_progress();
|
||||
|
||||
__declspec(noreturn) void raise_hard_exception();
|
||||
std::string load_resource(int id);
|
||||
|
||||
void relaunch_self();
|
||||
__declspec(noreturn) void terminate(uint32_t code = 0);
|
||||
}
|
220
hook_lib/common/utils/signature.cpp
Normal file
220
hook_lib/common/utils/signature.cpp
Normal file
@ -0,0 +1,220 @@
|
||||
#include "signature.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
void signature::load_pattern(const std::string& pattern)
|
||||
{
|
||||
this->mask_.clear();
|
||||
this->pattern_.clear();
|
||||
|
||||
uint8_t nibble = 0;
|
||||
auto has_nibble = false;
|
||||
|
||||
for (auto val : pattern)
|
||||
{
|
||||
if (val == ' ') continue;
|
||||
if (val == '?')
|
||||
{
|
||||
this->mask_.push_back(val);
|
||||
this->pattern_.push_back(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((val < '0' || val > '9') && (val < 'A' || val > 'F') && (val < 'a' || val > 'f'))
|
||||
{
|
||||
throw std::runtime_error("Invalid pattern");
|
||||
}
|
||||
|
||||
char str[] = {val, 0};
|
||||
const auto current_nibble = static_cast<uint8_t>(strtol(str, nullptr, 16));
|
||||
|
||||
if (!has_nibble)
|
||||
{
|
||||
has_nibble = true;
|
||||
nibble = current_nibble;
|
||||
}
|
||||
else
|
||||
{
|
||||
has_nibble = false;
|
||||
const uint8_t byte = current_nibble | (nibble << 4);
|
||||
|
||||
this->mask_.push_back('x');
|
||||
this->pattern_.push_back(byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!this->mask_.empty() && this->mask_.back() == '?')
|
||||
{
|
||||
this->mask_.pop_back();
|
||||
this->pattern_.pop_back();
|
||||
}
|
||||
|
||||
if (this->has_sse_support())
|
||||
{
|
||||
while (this->pattern_.size() < 16)
|
||||
{
|
||||
this->pattern_.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_nibble)
|
||||
{
|
||||
throw std::runtime_error("Invalid pattern");
|
||||
}
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range(uint8_t* start, const size_t length) const
|
||||
{
|
||||
if (this->has_sse_support()) return this->process_range_vectorized(start, length);
|
||||
return this->process_range_linear(start, length);
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range_linear(uint8_t* start, const size_t length) const
|
||||
{
|
||||
std::vector<uint8_t*> result;
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
|
||||
size_t j = 0;
|
||||
for (; j < this->mask_.size(); ++j)
|
||||
{
|
||||
if (this->mask_[j] != '?' && this->pattern_[j] != address[j])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == this->mask_.size())
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range_vectorized(uint8_t* start, const size_t length) const
|
||||
{
|
||||
std::vector<uint8_t*> result;
|
||||
__declspec(align(16)) char desired_mask[16] = {0};
|
||||
|
||||
for (size_t i = 0; i < this->mask_.size(); i++)
|
||||
{
|
||||
desired_mask[i / 8] |= (this->mask_[i] == '?' ? 0 : 1) << i % 8;
|
||||
}
|
||||
|
||||
const auto mask = _mm_load_si128(reinterpret_cast<const __m128i*>(desired_mask));
|
||||
const auto comparand = _mm_loadu_si128(reinterpret_cast<const __m128i*>(this->pattern_.data()));
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
const auto value = _mm_loadu_si128(reinterpret_cast<const __m128i*>(address));
|
||||
const auto comparison = _mm_cmpestrm(value, 16, comparand, static_cast<int>(this->mask_.size()),
|
||||
_SIDD_CMP_EQUAL_EACH);
|
||||
|
||||
const auto matches = _mm_and_si128(mask, comparison);
|
||||
const auto equivalence = _mm_xor_si128(mask, matches);
|
||||
|
||||
if (_mm_test_all_zeros(equivalence, equivalence))
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
signature::signature_result signature::process() const
|
||||
{
|
||||
const auto range = this->length_ - this->mask_.size();
|
||||
const auto cores = std::max(1u, std::thread::hardware_concurrency());
|
||||
|
||||
if (range <= cores * 10ull) return this->process_serial();
|
||||
return this->process_parallel();
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_serial() const
|
||||
{
|
||||
const auto sub = this->has_sse_support() ? 16 : this->mask_.size();
|
||||
return {this->process_range(this->start_, this->length_ - sub)};
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_parallel() const
|
||||
{
|
||||
const auto sub = this->has_sse_support() ? 16 : this->mask_.size();
|
||||
const auto range = this->length_ - sub;
|
||||
const auto cores = std::max(1u, std::thread::hardware_concurrency() / 2);
|
||||
// Only use half of the available cores
|
||||
const auto grid = range / cores;
|
||||
|
||||
std::mutex mutex;
|
||||
std::vector<uint8_t*> result;
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
for (auto i = 0u; i < cores; ++i)
|
||||
{
|
||||
const auto start = this->start_ + (grid * i);
|
||||
const auto length = (i + 1 == cores) ? (this->start_ + this->length_ - sub) - start : grid;
|
||||
threads.emplace_back([&, start, length]()
|
||||
{
|
||||
const auto local_result = this->process_range(start, length);
|
||||
if (local_result.empty()) return;
|
||||
|
||||
std::lock_guard _(mutex);
|
||||
for (const auto& address : local_result)
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (auto& t : threads)
|
||||
{
|
||||
if (t.joinable())
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(result.begin(), result.end());
|
||||
return {std::move(result)};
|
||||
}
|
||||
|
||||
bool signature::has_sse_support() const
|
||||
{
|
||||
if (this->mask_.size() <= 16)
|
||||
{
|
||||
int cpu_id[4];
|
||||
__cpuid(cpu_id, 0);
|
||||
|
||||
if (cpu_id[0] >= 1)
|
||||
{
|
||||
__cpuidex(cpu_id, 1, 0);
|
||||
return (cpu_id[2] & (1 << 20)) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
utils::hook::signature::signature_result operator"" _sig(const char* str, const size_t len)
|
||||
{
|
||||
return utils::hook::signature(std::string(str, len)).process();
|
||||
}
|
49
hook_lib/common/utils/signature.hpp
Normal file
49
hook_lib/common/utils/signature.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "nt.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
class signature final
|
||||
{
|
||||
public:
|
||||
using signature_result = std::vector<uint8_t*>;
|
||||
|
||||
explicit signature(const std::string& pattern, const nt::library& library = {})
|
||||
: signature(pattern, library.get_ptr(), library.get_optional_header()->SizeOfImage)
|
||||
{
|
||||
}
|
||||
|
||||
signature(const std::string& pattern, void* start, void* end)
|
||||
: signature(pattern, start, size_t(end) - size_t(start))
|
||||
{
|
||||
}
|
||||
|
||||
signature(const std::string& pattern, void* start, const size_t length)
|
||||
: start_(static_cast<uint8_t*>(start)), length_(length)
|
||||
{
|
||||
this->load_pattern(pattern);
|
||||
}
|
||||
|
||||
signature_result process() const;
|
||||
|
||||
private:
|
||||
std::string mask_;
|
||||
std::basic_string<uint8_t> pattern_;
|
||||
|
||||
uint8_t* start_;
|
||||
size_t length_;
|
||||
|
||||
void load_pattern(const std::string& pattern);
|
||||
|
||||
signature_result process_parallel() const;
|
||||
signature_result process_serial() const;
|
||||
signature_result process_range(uint8_t* start, size_t length) const;
|
||||
signature_result process_range_linear(uint8_t* start, size_t length) const;
|
||||
signature_result process_range_vectorized(uint8_t* start, size_t length) const;
|
||||
|
||||
bool has_sse_support() const;
|
||||
};
|
||||
}
|
||||
|
||||
utils::hook::signature::signature_result operator"" _sig(const char* str, size_t len);
|
94
hook_lib/common/utils/smbios.cpp
Normal file
94
hook_lib/common/utils/smbios.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "smbios.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <intrin.h>
|
||||
|
||||
namespace utils::smbios
|
||||
{
|
||||
namespace
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4200)
|
||||
struct RawSMBIOSData
|
||||
{
|
||||
BYTE Used20CallingMethod;
|
||||
BYTE SMBIOSMajorVersion;
|
||||
BYTE SMBIOSMinorVersion;
|
||||
BYTE DmiRevision;
|
||||
DWORD Length;
|
||||
BYTE SMBIOSTableData[];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BYTE type;
|
||||
BYTE length;
|
||||
WORD handle;
|
||||
} dmi_header;
|
||||
#pragma warning(pop)
|
||||
|
||||
std::vector<uint8_t> get_smbios_data()
|
||||
{
|
||||
DWORD size = 0;
|
||||
std::vector<uint8_t> data{};
|
||||
|
||||
size = GetSystemFirmwareTable('RSMB', 0, nullptr, size);
|
||||
data.resize(size);
|
||||
GetSystemFirmwareTable('RSMB', 0, data.data(), size);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string parse_uuid(const uint8_t* data)
|
||||
{
|
||||
if (utils::memory::is_set(data, 0, 16) || utils::memory::is_set(data, -1, 16))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
char uuid[16] = {0};
|
||||
*reinterpret_cast<unsigned long*>(uuid + 0) =
|
||||
_byteswap_ulong(*reinterpret_cast<const unsigned long*>(data + 0));
|
||||
*reinterpret_cast<unsigned short*>(uuid + 4) =
|
||||
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 4));
|
||||
*reinterpret_cast<unsigned short*>(uuid + 6) =
|
||||
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 6));
|
||||
memcpy(uuid + 8, data + 8, 8);
|
||||
|
||||
return std::string(uuid, sizeof(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_uuid()
|
||||
{
|
||||
auto smbios_data = get_smbios_data();
|
||||
auto* raw_data = reinterpret_cast<RawSMBIOSData*>(smbios_data.data());
|
||||
|
||||
auto* data = raw_data->SMBIOSTableData;
|
||||
for (DWORD i = 0; i + sizeof(dmi_header) < raw_data->Length;)
|
||||
{
|
||||
auto* header = reinterpret_cast<dmi_header*>(data + i);
|
||||
if (header->length < 4)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (header->type == 0x01 && header->length >= 0x19)
|
||||
{
|
||||
return parse_uuid(data + i + 0x8);
|
||||
}
|
||||
|
||||
i += header->length;
|
||||
while ((i + 1) < raw_data->Length && *reinterpret_cast<uint16_t*>(data + i) != 0)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
8
hook_lib/common/utils/smbios.hpp
Normal file
8
hook_lib/common/utils/smbios.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils::smbios
|
||||
{
|
||||
std::string get_uuid();
|
||||
}
|
177
hook_lib/common/utils/string.cpp
Normal file
177
hook_lib/common/utils/string.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
#include "string.hpp"
|
||||
#include <sstream>
|
||||
#include <cstdarg>
|
||||
#include <algorithm>
|
||||
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
const char* va(const char* fmt, ...)
|
||||
{
|
||||
static thread_local va_provider<8, 256> provider;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
const char* result = provider.get(fmt, ap);
|
||||
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string& s, const char delim)
|
||||
{
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
std::vector<std::string> elems;
|
||||
|
||||
while (std::getline(ss, item, delim))
|
||||
{
|
||||
elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson)
|
||||
}
|
||||
|
||||
return elems;
|
||||
}
|
||||
|
||||
std::string to_lower(std::string text)
|
||||
{
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||
{
|
||||
return static_cast<char>(std::tolower(input));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string to_upper(std::string text)
|
||||
{
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||
{
|
||||
return static_cast<char>(std::toupper(input));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
bool starts_with(const std::string& text, const std::string& substring)
|
||||
{
|
||||
return text.find(substring) == 0;
|
||||
}
|
||||
|
||||
bool ends_with(const std::string& text, const std::string& substring)
|
||||
{
|
||||
if (substring.size() > text.size()) return false;
|
||||
return std::equal(substring.rbegin(), substring.rend(), text.rbegin());
|
||||
}
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
for (unsigned int i = 0; i < data.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
result.append(separator);
|
||||
}
|
||||
|
||||
result.append(va("%02X", data[i] & 0xFF));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string get_clipboard_data()
|
||||
{
|
||||
if (OpenClipboard(nullptr))
|
||||
{
|
||||
std::string data;
|
||||
|
||||
auto* const clipboard_data = GetClipboardData(1u);
|
||||
if (clipboard_data)
|
||||
{
|
||||
auto* const cliptext = static_cast<char*>(GlobalLock(clipboard_data));
|
||||
if (cliptext)
|
||||
{
|
||||
data.append(cliptext);
|
||||
GlobalUnlock(clipboard_data);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
|
||||
return data;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void strip(const char* in, char* out, size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
max--;
|
||||
size_t current = 0;
|
||||
while (*in != 0 && current < max)
|
||||
{
|
||||
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
|
||||
|
||||
if (*in == '^' && (color_index != 7 || *(in + 1) == '7'))
|
||||
{
|
||||
++in;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *in;
|
||||
++out;
|
||||
++current;
|
||||
}
|
||||
|
||||
++in;
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
std::string convert(const std::wstring& wstr)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(wstr.size());
|
||||
|
||||
for (const auto& chr : wstr)
|
||||
{
|
||||
result.push_back(static_cast<char>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring convert(const std::string& str)
|
||||
{
|
||||
std::wstring result;
|
||||
result.reserve(str.size());
|
||||
|
||||
for (const auto& chr : str)
|
||||
{
|
||||
result.push_back(static_cast<wchar_t>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
97
hook_lib/common/utils/string.hpp
Normal file
97
hook_lib/common/utils/string.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
#include "memory.hpp"
|
||||
|
||||
template <class Type, size_t n>
|
||||
constexpr auto ARRAY_COUNT(Type (&)[n]) { return n; }
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
template <size_t Buffers, size_t MinBufferSize>
|
||||
class va_provider final
|
||||
{
|
||||
public:
|
||||
static_assert(Buffers != 0 && MinBufferSize != 0, "Buffers and MinBufferSize mustn't be 0");
|
||||
|
||||
va_provider() : current_buffer_(0)
|
||||
{
|
||||
}
|
||||
|
||||
char* get(const char* format, const va_list ap)
|
||||
{
|
||||
++this->current_buffer_ %= ARRAY_COUNT(this->string_pool_);
|
||||
auto entry = &this->string_pool_[this->current_buffer_];
|
||||
|
||||
if (!entry->size || !entry->buffer)
|
||||
{
|
||||
throw std::runtime_error("String pool not initialized");
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
const int res = vsnprintf_s(entry->buffer, entry->size, _TRUNCATE, format, ap);
|
||||
if (res > 0) break; // Success
|
||||
if (res == 0) return nullptr; // Error
|
||||
|
||||
entry->double_size();
|
||||
}
|
||||
|
||||
return entry->buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
class entry final
|
||||
{
|
||||
public:
|
||||
entry(const size_t _size = MinBufferSize) : size(_size), buffer(nullptr)
|
||||
{
|
||||
if (this->size < MinBufferSize) this->size = MinBufferSize;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
~entry()
|
||||
{
|
||||
if (this->buffer) memory::get_allocator()->free(this->buffer);
|
||||
this->size = 0;
|
||||
this->buffer = nullptr;
|
||||
}
|
||||
|
||||
void allocate()
|
||||
{
|
||||
if (this->buffer) memory::get_allocator()->free(this->buffer);
|
||||
this->buffer = memory::get_allocator()->allocate_array<char>(this->size + 1);
|
||||
}
|
||||
|
||||
void double_size()
|
||||
{
|
||||
this->size *= 2;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
size_t size{};
|
||||
char* buffer{nullptr};
|
||||
};
|
||||
|
||||
size_t current_buffer_{};
|
||||
entry string_pool_[Buffers]{};
|
||||
};
|
||||
|
||||
const char* va(const char* fmt, ...);
|
||||
|
||||
std::vector<std::string> split(const std::string& s, char delim);
|
||||
|
||||
std::string to_lower(std::string text);
|
||||
std::string to_upper(std::string text);
|
||||
bool starts_with(const std::string& text, const std::string& substring);
|
||||
bool ends_with(const std::string& text, const std::string& substring);
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator = " ");
|
||||
|
||||
std::string get_clipboard_data();
|
||||
|
||||
void strip(const char* in, char* out, size_t max);
|
||||
|
||||
std::string convert(const std::wstring& wstr);
|
||||
std::wstring convert(const std::string& str);
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to);
|
||||
}
|
116
hook_lib/common/utils/thread.cpp
Normal file
116
hook_lib/common/utils/thread.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
#include "thread.hpp"
|
||||
#include "string.hpp"
|
||||
#include "finally.hpp"
|
||||
|
||||
#include <TlHelp32.h>
|
||||
|
||||
namespace utils::thread
|
||||
{
|
||||
/*bool set_name(const HANDLE t, const std::string& name)
|
||||
{
|
||||
const nt::library kernel32("kernel32.dll");
|
||||
if (!kernel32)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto set_description = kernel32.get_proc<HRESULT(WINAPI*)(HANDLE, PCWSTR)>("SetThreadDescription");
|
||||
if (!set_description)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return SUCCEEDED(set_description(t, string::convert(name).data()));
|
||||
}
|
||||
|
||||
bool set_name(const DWORD id, const std::string& name)
|
||||
{
|
||||
auto* const t = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, id);
|
||||
if (!t) return false;
|
||||
|
||||
const auto _ = utils::finally([t]()
|
||||
{
|
||||
CloseHandle(t);
|
||||
});
|
||||
|
||||
return set_name(t, name);
|
||||
}
|
||||
|
||||
bool set_name(std::thread& t, const std::string& name)
|
||||
{
|
||||
return set_name(t.native_handle(), name);
|
||||
}
|
||||
|
||||
bool set_name(const std::string& name)
|
||||
{
|
||||
return set_name(GetCurrentThread(), name);
|
||||
}
|
||||
*/
|
||||
std::vector<DWORD> get_thread_ids()
|
||||
{
|
||||
nt::handle<INVALID_HANDLE_VALUE> h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
|
||||
if (!h)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
THREADENTRY32 entry{};
|
||||
entry.dwSize = sizeof(entry);
|
||||
if (!Thread32First(h, &entry))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<DWORD> ids{};
|
||||
|
||||
do
|
||||
{
|
||||
const auto check_size = entry.dwSize < FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID)
|
||||
+ sizeof(entry.th32OwnerProcessID);
|
||||
entry.dwSize = sizeof(entry);
|
||||
|
||||
if (check_size && entry.th32OwnerProcessID == GetCurrentProcessId())
|
||||
{
|
||||
ids.emplace_back(entry.th32ThreadID);
|
||||
}
|
||||
} while (Thread32Next(h, &entry));
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
void for_each_thread(const std::function<void(HANDLE)>& callback, const DWORD access)
|
||||
{
|
||||
const auto ids = get_thread_ids();
|
||||
|
||||
for (const auto& id : ids)
|
||||
{
|
||||
handle thread(id, access);
|
||||
if (thread)
|
||||
{
|
||||
callback(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void suspend_other_threads()
|
||||
{
|
||||
for_each_thread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
SuspendThread(thread);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void resume_other_threads()
|
||||
{
|
||||
for_each_thread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
ResumeThread(thread);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
47
hook_lib/common/utils/thread.hpp
Normal file
47
hook_lib/common/utils/thread.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::thread
|
||||
{
|
||||
//bool set_name(HANDLE t, const std::string& name);
|
||||
//bool set_name(DWORD id, const std::string& name);
|
||||
//bool set_name(std::thread& t, const std::string& name);
|
||||
//bool set_name(const std::string& name);
|
||||
|
||||
template <typename ...Args>
|
||||
std::thread create_named_thread(const std::string& name, Args&&... args)
|
||||
{
|
||||
auto t = std::thread(std::forward<Args>(args)...);
|
||||
set_name(t, name);
|
||||
return t;
|
||||
}
|
||||
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle(const DWORD thread_id, const DWORD access = THREAD_ALL_ACCESS)
|
||||
: handle_(OpenThread(access, FALSE, thread_id))
|
||||
{
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
nt::handle<> handle_{};
|
||||
};
|
||||
|
||||
std::vector<DWORD> get_thread_ids();
|
||||
void for_each_thread(const std::function<void(HANDLE)>& callback, DWORD access = THREAD_ALL_ACCESS);
|
||||
|
||||
void suspend_other_threads();
|
||||
void resume_other_threads();
|
||||
}
|
8486
hook_lib/csv.hpp
Normal file
8486
hook_lib/csv.hpp
Normal file
File diff suppressed because it is too large
Load Diff
378
hook_lib/functions.cpp
Normal file
378
hook_lib/functions.cpp
Normal file
@ -0,0 +1,378 @@
|
||||
#include "functions.hpp"
|
||||
|
||||
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler) {
|
||||
utils::nt::library ntdll("ntdll.dll");
|
||||
ntdll.invoke<void*>("RtlAddVectoredExceptionHandler", First, Handler);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NTSTATUS NtContinue(PCONTEXT threadContext, BOOLEAN raiseAlert) {
|
||||
utils::nt::library ntdll("ntdll.dll");
|
||||
return ntdll.invoke<NTSTATUS>("NtContinue", threadContext, raiseAlert);
|
||||
}
|
||||
|
||||
#pragma region //game functions
|
||||
|
||||
const char* (*va)(const char* fmt, ...);
|
||||
|
||||
void Live_FakeUserSignIn(int controllerIndex, const char* gamertag) {
|
||||
auto func = reinterpret_cast<void(*)(int, const char*)>(0x1413FDA40_g);
|
||||
func(controllerIndex, gamertag);
|
||||
}
|
||||
|
||||
void R_AddCmdDrawText(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost) {
|
||||
auto func = reinterpret_cast<void(*)(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost)>(0x00000001419653E0_g);
|
||||
func(text, maxChars, font, fontHeight, x, y, xScale, yScale, rotation, color, glowStyle, usePost);
|
||||
}
|
||||
|
||||
bool CG_WorldPosToScreenPosReal(int localClientNum, const uintptr_t scrPlace, const float* worldPos, float* outScreenPos) {
|
||||
auto func = reinterpret_cast<bool(*)(int, const uintptr_t, const float*, float*)>(0x141696AA0_g);
|
||||
return func(localClientNum, scrPlace, worldPos, outScreenPos);
|
||||
}
|
||||
|
||||
void CG_DrawRotatedPicPhysical(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material)>(0x141695B20_g);
|
||||
func(scrPlace, x, y, width, height, angle, color, material);
|
||||
}
|
||||
|
||||
uintptr_t FS_ReadFile(const char* qpath, const char** buffer) {
|
||||
auto func = reinterpret_cast<uintptr_t(*)(const char* qpath, const char** buffer)>(0x1413DA530_g);
|
||||
return func(qpath, buffer);
|
||||
}
|
||||
|
||||
const char* Dvar_GetStringSafe(const char* dvar) {
|
||||
auto func = reinterpret_cast<const char* (*)(const char*)>(0x1413E69B0_g);
|
||||
return func(dvar);
|
||||
}
|
||||
|
||||
unsigned int* GetRandSeed() {
|
||||
auto func = reinterpret_cast<unsigned int* (*)()>(0x1413DD630_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
unsigned __int64 Sys_Microseconds() {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)()>(0x14148FC10_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
int I_irand(int min, int max) {
|
||||
auto func = reinterpret_cast<int(*)(int, int)>(0x1413DD8B0_g);
|
||||
return func(min, max);
|
||||
}
|
||||
|
||||
unsigned __int64 I_atoui64_hex(const char* str) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const char*)>(0x1413F3310_g);
|
||||
return func(str);
|
||||
}
|
||||
|
||||
unsigned __int64 I_atoui64(const char* str) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const char*)>(0x1413F3300_g);
|
||||
return func(str);
|
||||
}
|
||||
|
||||
uintptr_t Dvar_FindVarByName(const char* dvarName) {
|
||||
auto func = reinterpret_cast<uintptr_t(*)(const char*)>(0x1413E63A0_g);
|
||||
return func(dvarName);
|
||||
}
|
||||
|
||||
void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style) {
|
||||
auto func = reinterpret_cast<void(*)(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style)>(0x1415AAAA0_g);
|
||||
func(scrPlace, text, maxChars, font, x, y, horzAlign, vertAlign, xScale, yScale, color, style);
|
||||
}
|
||||
|
||||
dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description) {
|
||||
auto func = reinterpret_cast<dvar_t * (*)(const char* dvarName, const char* value, unsigned int flags, const char* description)>(0x1413E7A70_g);
|
||||
return func(dvarName, value, flags, description);
|
||||
}
|
||||
|
||||
dvar_t* Dvar_RegisterBool(const char* dvarName, bool value, unsigned int flags, const char* description) {
|
||||
auto func = reinterpret_cast<dvar_t * (*)(const char* dvarName, bool value, unsigned int flags, const char* description)>(0x1413E7670_g);
|
||||
return func(dvarName, value, flags, description);
|
||||
}
|
||||
|
||||
void LUI_CoD_LuaCall_ExecNow(uintptr_t luaVM, const char* str) {
|
||||
lua_getfield(luaVM, -10002, "Engine");
|
||||
lua_getfield(luaVM, -1, "DAGFFDGFII");
|
||||
lua_remove(luaVM, -2);
|
||||
lua_pushstring(luaVM, str);
|
||||
LuaShared_PCall(luaVM, 1, 1);
|
||||
}
|
||||
|
||||
bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum) {
|
||||
lua_getfield(luaVM, -10002, "Game");
|
||||
lua_getfield(luaVM, -1, "JDAIJCDEB");
|
||||
lua_remove(luaVM, -2);
|
||||
lua_pushinteger(luaVM, 0);
|
||||
lua_pushinteger(luaVM, entityNum);
|
||||
LuaShared_PCall(luaVM, 2, 1);
|
||||
return lua_toboolean(luaVM, 0);
|
||||
}
|
||||
|
||||
void Cbuf_AddText(const char* cmd) {
|
||||
uintptr_t luaVM = *reinterpret_cast<uintptr_t*>(0x151868880_g);
|
||||
if (luaVM) {
|
||||
LUI_CoD_LuaCall_ExecNow(luaVM, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
bool lua_toboolean(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<bool(*)(uintptr_t, int)>(0x1420848D0_g);
|
||||
return func(L, idx);
|
||||
}
|
||||
|
||||
void lua_pushboolean(uintptr_t L, int b) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083E80_g);
|
||||
func(L, b);
|
||||
}
|
||||
|
||||
void lua_remove(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084420_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
void lua_call(uintptr_t L, int nargs, int nresults) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int, int)>(0x1420831D0_g);
|
||||
func(L, nargs, nresults);
|
||||
}
|
||||
|
||||
void lua_getfield(uintptr_t L, int idx, const char* k) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int, const char*)>(0x1420836E0_g);
|
||||
func(L, idx, k);
|
||||
}
|
||||
|
||||
void lua_pushvalue(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084200_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
void lua_pushstring(uintptr_t L, const char* str) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, const char*)>(0x142084120_g);
|
||||
func(L, str);
|
||||
}
|
||||
|
||||
void lua_pushinteger(uintptr_t L, int n) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083FE0_g);
|
||||
func(L, n);
|
||||
}
|
||||
|
||||
void lua_settop(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084790_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults) {
|
||||
auto func = reinterpret_cast<int(*)(uintptr_t, int, int)>(0x1419B7570_g);
|
||||
return func(luaVM, nargs, nresults);
|
||||
}
|
||||
|
||||
bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin) {
|
||||
auto func = reinterpret_cast<bool(*)(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin)>(0x1416A59D0_g);
|
||||
return func(pose, obj, boneIndex, outTagMat, outOrigin);
|
||||
}
|
||||
|
||||
void CG_DrawLine(float X1, float Y1, float X2, float Y2, const float* color, float Width) {
|
||||
float X, Y, Angle, L1, L2, H1;
|
||||
H1 = Y2 - Y1;
|
||||
L1 = X2 - X1;
|
||||
L2 = sqrtf(L1 * L1 + H1 * H1);
|
||||
X = X1 + ((L1 - L2) / 2);
|
||||
Y = Y1 + (H1 / 2);
|
||||
Angle = atan(H1 / L1) * (180 / 3.14159265358979323846);
|
||||
CG_DrawRotatedPicPhysical(0x14EF2DEA0_g, X, Y, L2, Width, Angle, color, *reinterpret_cast<uintptr_t*>(0x152C465A0_g));
|
||||
}
|
||||
|
||||
void CG_DrawBone(int entIndex, uintptr_t ent, int from, int to, const float* color) {
|
||||
float bone1[3], bone2[3];
|
||||
float fromPos[2], toPos[2];
|
||||
char tmat33[0x24];
|
||||
short* clientObjMap = (short*)(0x14D45EC60_g);
|
||||
uintptr_t s_objBuf = *reinterpret_cast<uintptr_t*>(0x14D45EC50_g);
|
||||
uintptr_t dobj = s_objBuf + (0x150 * clientObjMap[entIndex]);
|
||||
if (CG_DObjGetWorldBoneMatrix(ent, dobj, from, (uintptr_t)&tmat33, bone1) && CG_DObjGetWorldBoneMatrix(ent, dobj, to, (uintptr_t)&tmat33, bone2)) {
|
||||
if (CG_WorldPosToScreenPosReal(0, 0x14EF2DEA0_g, bone1, fromPos) && CG_WorldPosToScreenPosReal(0, 0x14EF2DEA0_g, bone2, toPos)) {
|
||||
CG_DrawLine(fromPos[0], fromPos[1], toPos[0], toPos[1], color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CG_DrawBones(int entIndex, uintptr_t ent, const float* color) {
|
||||
//spine
|
||||
CG_DrawBone(entIndex, ent, 41, 35, color);
|
||||
CG_DrawBone(entIndex, ent, 35, 7, color);
|
||||
CG_DrawBone(entIndex, ent, 7, 6, color);
|
||||
CG_DrawBone(entIndex, ent, 6, 30, color);
|
||||
CG_DrawBone(entIndex, ent, 30, 55, color);
|
||||
CG_DrawBone(entIndex, ent, 55, 54, color);
|
||||
CG_DrawBone(entIndex, ent, 54, 53, color);
|
||||
CG_DrawBone(entIndex, ent, 53, 2, color);
|
||||
|
||||
//hips
|
||||
CG_DrawBone(entIndex, ent, 2, 63, color);
|
||||
CG_DrawBone(entIndex, ent, 2, 64, color);
|
||||
}
|
||||
|
||||
bool CheatsOk(int entNum) {
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
uintptr_t client = g_entities[entNum].get<uintptr_t>(0x150);
|
||||
if (sv_cheats->current.enabled) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ms_clients->SendServerCommand(1, "f \"Cheats are not enabled on this server!\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//ingame removed functions
|
||||
void Cmd_Noclip_f(int entNum)
|
||||
{
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
uintptr_t client = g_entities[entNum].get<uintptr_t>(0x150);
|
||||
if (client) {
|
||||
int v6 = *reinterpret_cast<int*>(client + 0x5DD0);
|
||||
if ((*reinterpret_cast<int*>(client + 0x5DD0) & 1) != 0) {
|
||||
v6 = *reinterpret_cast<int*>(client + 0x5DD0) & 0xFFFFFFFE;
|
||||
ms_clients->SendServerCommand(1, "f \"Noclip: ^1OFF\"");
|
||||
}
|
||||
else {
|
||||
v6 = *reinterpret_cast<int*>(client + 0x5DD0) | 1;
|
||||
ms_clients->SendServerCommand(1, "f \"Noclip: ^2ON\"");
|
||||
}
|
||||
*reinterpret_cast<int*>(client + 0x5DD0) = v6;
|
||||
}
|
||||
}
|
||||
|
||||
void SV_Cmd_ArgvBuffer(int arg, char* buffer, unsigned __int64 bufferLength) {
|
||||
auto func = reinterpret_cast<void(*)(int, char*, unsigned __int64)>(0x141298B40_g);
|
||||
func(arg, buffer, bufferLength);
|
||||
}
|
||||
|
||||
void Cmd_ArgvBuffer(int arg, char* buffer, int bufferLength) {
|
||||
if (arg >= cmd_args->argc[cmd_args->nesting])
|
||||
strcpy_s(buffer, bufferLength, "");
|
||||
else
|
||||
strcpy_s(buffer, bufferLength, cmd_args->argv[cmd_args->nesting][arg]);
|
||||
}
|
||||
|
||||
int Cmd_Argc() {
|
||||
return cmd_args->argc[cmd_args->nesting];
|
||||
}
|
||||
|
||||
int SV_Cmd_Argc() {
|
||||
auto func = reinterpret_cast<int(*)()>(0x141298AF0_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
void Cmd_AddCommandInternal(const char* cmdName, void(__fastcall* function)(), cmd_function_s* allocedCmd) {
|
||||
auto func = reinterpret_cast<void(*)(const char*, void(__fastcall*)(), cmd_function_s*)>(0x1412965F0_g);
|
||||
func(cmdName, function, allocedCmd);
|
||||
}
|
||||
|
||||
ClActiveClient* GetClActiveClient() {
|
||||
ms_activeClients = *reinterpret_cast<ClActiveClient**>(0x14EE854F8_g);
|
||||
return ms_activeClients;
|
||||
}
|
||||
|
||||
int ClActiveClient_GetCmdNumber(ClActiveClient* activeClient) {
|
||||
return activeClient->cmdNumber ^ ((activeClient->get<int>(0x8700) ^ (activeClient->cmdNumber) * ((activeClient->get<int>(0x8700) ^ activeClient->cmdNumber) + 2)));
|
||||
}
|
||||
|
||||
usercmd_s* CL_GetUserCmd(int cmdNumber) {
|
||||
ms_activeClients = *reinterpret_cast<ClActiveClient**>(0x14EE854F8_g);
|
||||
return &ms_activeClients->cmds[cmdNumber & 0x7F];
|
||||
}
|
||||
|
||||
void AddReliableCommand(uintptr_t _this, const char* commandBuffer, const int reliableCmdSize, int type) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, const char*, const int, int)>(0x1415E0440_g);
|
||||
func(_this, commandBuffer, reliableCmdSize, type);
|
||||
}
|
||||
|
||||
unsigned int MSG_WriteReliableCommandToBuffer(const char* pszCommand, char* pszBuffer, unsigned int iBufferSize) {
|
||||
auto func = reinterpret_cast<unsigned int(*)(const char*, char*, unsigned int)>(0x1412DDBF0_g);
|
||||
return func(pszCommand, pszBuffer, iBufferSize);
|
||||
}
|
||||
|
||||
void CL_Main_AddReliableCommand(const char* cmd) {
|
||||
uintptr_t ms_connections = *reinterpret_cast<uintptr_t*>(0x14EE85570_g);
|
||||
char buf[1024];
|
||||
int cmdSize = MSG_WriteReliableCommandToBuffer(cmd, buf, 1024);
|
||||
AddReliableCommand(ms_connections, buf, cmdSize, 0);
|
||||
}
|
||||
|
||||
bool BG_Weapons_GetFullWeaponForName(const char* name, Weapon* outWeapon, Weapon* (*getWeaponFunc)(Weapon* result, const char*)) {
|
||||
auto func = reinterpret_cast<bool(*)(const char*, Weapon*, Weapon * (*)(Weapon * result, const char*))>(0x141158130_g);
|
||||
return func(name, outWeapon, getWeaponFunc);
|
||||
}
|
||||
|
||||
void Scr_AddString(scrContext_t* scrContext, const char* value) {
|
||||
auto func = reinterpret_cast<void(*)(scrContext_t*, const char*)>(0x141322D90_g);
|
||||
func(scrContext, value);
|
||||
}
|
||||
|
||||
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount) {
|
||||
auto func = reinterpret_cast<unsigned int(*)(gentity_s*, int, unsigned int)>(0x141257D70_g);
|
||||
return func(ent, handle, paramcount);
|
||||
}
|
||||
|
||||
void Scr_FreeThread(scrContext_t* scrContext, unsigned int handle) {
|
||||
auto func = reinterpret_cast<void(*)(scrContext_t*, unsigned int)>(0x1413242E0_g);
|
||||
func(scrContext, handle);
|
||||
}
|
||||
|
||||
int G_Weapon_GivePlayerWeapon(uintptr_t ps, uintptr_t scrContext, Weapon* weapon, int dualWield, int startInAltMode, int usedBefore) {
|
||||
auto func = reinterpret_cast<int(*)(uintptr_t, uintptr_t, Weapon*, int, int, int)>(0x14127C8B0_g);
|
||||
return func(ps, scrContext, weapon, dualWield, startInAltMode, usedBefore);
|
||||
}
|
||||
|
||||
void G_Items_AddAmmo(uintptr_t ps, Weapon* weapon, bool isAlternate, int count, int fillClip) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, Weapon*, bool, int, int)>(0x141216860_g);
|
||||
func(ps, weapon, isAlternate, count, fillClip);
|
||||
}
|
||||
|
||||
void G_Weapon_SelectWeapon(int clientNum, Weapon* weapon) {
|
||||
auto func = reinterpret_cast<void(*)(int, Weapon*)>(0x14127F840_g);
|
||||
}
|
||||
|
||||
Weapon* BG_FindBaseWeaponForName(Weapon* result, const char* name) {
|
||||
auto func = reinterpret_cast<Weapon * (*)(Weapon*, const char*)>(0x1411570F0_g);
|
||||
return func(result, name);
|
||||
}
|
||||
|
||||
scrContext_t* ScriptContext_Server() {
|
||||
auto func = reinterpret_cast<scrContext_t * (*)()>(0x1412E0E70_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
const char* SL_ConvertToString(int id) {
|
||||
auto func = reinterpret_cast<const char* (*)(int)>(0x14131AA20_g);
|
||||
return func(id);
|
||||
}
|
||||
|
||||
XAssetHeader DB_FindXAssetHeader(XAssetType type, const char* givenName, int allowCreateDefault) {
|
||||
auto func = reinterpret_cast<XAssetHeader(*)(XAssetType, const char*, int)>(0x1411AA890_g);
|
||||
return func(type, givenName, allowCreateDefault);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
dvar_t* player_name;
|
||||
dvar_t* sv_cheats;
|
||||
dvar_t* spawn_br_gas;
|
||||
dvar_t* show_watermark;
|
||||
dvar_t* player_sustainammo;
|
||||
|
||||
cmd_function_s set_byte_f_VAR;
|
||||
cmd_function_s set_short_f_VAR;
|
||||
cmd_function_s set_int_f_VAR;
|
||||
cmd_function_s set_pointer_f_VAR;
|
||||
cmd_function_s quit_f_VAR;
|
||||
cmd_function_s openmenu_f_VAR;
|
||||
cmd_function_s addbot_f_VAR;
|
||||
cmd_function_s ddldump_f_VAR;
|
||||
cmd_function_s weapondefdump_f_VAR;
|
||||
cmd_function_s view_vehicle_ents_f_VAR;
|
||||
cmd_function_s loadout_save_f_VAR;
|
||||
|
||||
CmdArgs* cmd_args;
|
||||
|
||||
Addresses g_Addrs;
|
223
hook_lib/functions.hpp
Normal file
223
hook_lib/functions.hpp
Normal file
@ -0,0 +1,223 @@
|
||||
#pragma once
|
||||
#include "Main.hpp"
|
||||
|
||||
struct gentity_s;
|
||||
|
||||
struct CmdArgs;
|
||||
|
||||
struct Addresses {
|
||||
uintptr_t ModuleBase;
|
||||
uintptr_t jmp_rbx;
|
||||
};
|
||||
|
||||
union DvarValue
|
||||
{
|
||||
bool enabled;
|
||||
int integer;
|
||||
unsigned int unsignedInt;
|
||||
__int64 integer64;
|
||||
unsigned __int64 unsignedInt64;
|
||||
float value;
|
||||
float vector[4];
|
||||
const char* string;
|
||||
unsigned __int8 color[4];
|
||||
};
|
||||
|
||||
struct BbConstUsageFlags
|
||||
{
|
||||
bool initialized;
|
||||
DvarValue codeValue;
|
||||
};
|
||||
|
||||
struct netadr_t;
|
||||
|
||||
struct dvar_t
|
||||
{
|
||||
const char* name;
|
||||
unsigned int checksum;
|
||||
const char* description;
|
||||
unsigned int flags;
|
||||
char level[1];
|
||||
unsigned __int8 type;
|
||||
bool modified;
|
||||
unsigned __int16 hashNext;
|
||||
DvarValue current;
|
||||
DvarValue latched;
|
||||
DvarValue reset;
|
||||
char domain[0x10];
|
||||
BbConstUsageFlags BbConstUsageFlags;
|
||||
};
|
||||
|
||||
struct EncryptionHeader
|
||||
{
|
||||
unsigned int isEncrypted;
|
||||
unsigned __int8 IV[16];
|
||||
};
|
||||
|
||||
struct __declspec(align(8)) XFile
|
||||
{
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 preloadWalkSize;
|
||||
unsigned __int64 blockSize[11];
|
||||
EncryptionHeader encryption;
|
||||
};
|
||||
|
||||
struct DB_FFHeader
|
||||
{
|
||||
unsigned __int64 magic;
|
||||
unsigned int headerVersion;
|
||||
unsigned int xfileVersion;
|
||||
bool dashCompressBuild;
|
||||
bool dashEncryptBuild;
|
||||
unsigned __int8 transientFileType[1];
|
||||
unsigned int residentPartSize;
|
||||
unsigned int residentHash;
|
||||
unsigned int alwaysLoadedPartSize;
|
||||
XFile xfileHeader;
|
||||
};
|
||||
|
||||
struct EncryptionInfo
|
||||
{
|
||||
EncryptionHeader header;
|
||||
unsigned __int8 privateKey[32];
|
||||
};
|
||||
|
||||
struct DBFileHandle
|
||||
{
|
||||
unsigned __int8 fileID[4];
|
||||
unsigned __int64 dcacheFileID;
|
||||
};
|
||||
|
||||
struct cmd_function_s
|
||||
{
|
||||
cmd_function_s* next;
|
||||
const char* name;
|
||||
const char** autoCompleteList;
|
||||
unsigned int autoCompleteListCount;
|
||||
void(__fastcall* function)();
|
||||
};
|
||||
|
||||
struct DBFile
|
||||
{
|
||||
char name[64];
|
||||
DBFileHandle dbFileHandle;
|
||||
bool isSecured;
|
||||
EncryptionInfo encryption;
|
||||
};
|
||||
|
||||
struct Weapon;
|
||||
struct scrContext_t;
|
||||
|
||||
extern dvar_t* player_name;
|
||||
extern dvar_t* sv_cheats;
|
||||
extern dvar_t* spawn_br_gas;
|
||||
extern dvar_t* show_watermark;
|
||||
extern dvar_t* player_sustainammo;
|
||||
|
||||
extern cmd_function_s set_byte_f_VAR;
|
||||
extern cmd_function_s set_short_f_VAR;
|
||||
extern cmd_function_s set_int_f_VAR;
|
||||
extern cmd_function_s set_pointer_f_VAR;
|
||||
extern cmd_function_s quit_f_VAR;
|
||||
extern cmd_function_s openmenu_f_VAR;
|
||||
extern cmd_function_s addbot_f_VAR;
|
||||
extern cmd_function_s ddldump_f_VAR;
|
||||
extern cmd_function_s weapondefdump_f_VAR;
|
||||
extern cmd_function_s view_vehicle_ents_f_VAR;
|
||||
extern cmd_function_s loadout_save_f_VAR;
|
||||
extern CmdArgs* cmd_args;
|
||||
|
||||
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler);
|
||||
NTSTATUS NtContinue(PCONTEXT threadContext, BOOLEAN raiseAlert);
|
||||
|
||||
#pragma region //game functions
|
||||
|
||||
extern const char* (*va)(const char* fmt, ...);
|
||||
|
||||
void Live_FakeUserSignIn(int controllerIndex, const char* gamertag);
|
||||
|
||||
void R_AddCmdDrawText(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost);
|
||||
|
||||
bool CG_WorldPosToScreenPosReal(int localClientNum, const uintptr_t scrPlace, const float* worldPos, float* outScreenPos);
|
||||
|
||||
void CG_DrawRotatedPicPhysical(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material);
|
||||
|
||||
inline bool file_exists(const char* name) {
|
||||
struct stat buffer;
|
||||
return (stat(name, &buffer) == 0);
|
||||
}
|
||||
|
||||
uintptr_t FS_ReadFile(const char* qpath, const char** buffer);
|
||||
const char* Dvar_GetStringSafe(const char* dvar);
|
||||
|
||||
unsigned int* GetRandSeed();
|
||||
unsigned __int64 Sys_Microseconds();
|
||||
int I_irand(int min, int max);
|
||||
unsigned __int64 I_atoui64_hex(const char* str);
|
||||
unsigned __int64 I_atoui64(const char* str);
|
||||
uintptr_t Dvar_FindVarByName(const char* dvarName);
|
||||
|
||||
void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style);
|
||||
dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description);
|
||||
dvar_t* Dvar_RegisterBool(const char* dvarName, bool value, unsigned int flags, const char* description);
|
||||
|
||||
void LUI_CoD_LuaCall_ExecNow(uintptr_t luaVM, const char* str);
|
||||
bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum);
|
||||
|
||||
void Cbuf_AddText(const char* cmd);
|
||||
|
||||
bool lua_toboolean(uintptr_t L, int idx);
|
||||
|
||||
void lua_pushboolean(uintptr_t L, int b);
|
||||
void lua_remove(uintptr_t L, int idx);
|
||||
void lua_call(uintptr_t L, int nargs, int nresults);
|
||||
void lua_getfield(uintptr_t L, int idx, const char* k);
|
||||
void lua_pushvalue(uintptr_t L, int idx);
|
||||
void lua_pushstring(uintptr_t L, const char* str);
|
||||
void lua_pushinteger(uintptr_t L, int n);
|
||||
void lua_settop(uintptr_t L, int idx);
|
||||
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults);
|
||||
|
||||
bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin);
|
||||
|
||||
void CG_DrawLine(float X1, float Y1, float X2, float Y2, const float* color, float Width);
|
||||
void CG_DrawBone(int entIndex, uintptr_t ent, int from, int to, const float* color);
|
||||
void CG_DrawBones(int entIndex, uintptr_t ent, const float* color);
|
||||
|
||||
bool CheatsOk(int entNum);
|
||||
|
||||
void Cmd_Noclip_f(int entNum);
|
||||
|
||||
void SV_Cmd_ArgvBuffer(int arg, char* buffer, unsigned __int64 bufferLength);
|
||||
void Cmd_ArgvBuffer(int arg, char* buffer, int bufferLength);
|
||||
int Cmd_Argc();
|
||||
int SV_Cmd_Argc();
|
||||
|
||||
void Cmd_AddCommandInternal(const char* cmdName, void(__fastcall* function)(), cmd_function_s* allocedCmd);
|
||||
|
||||
void AddReliableCommand(uintptr_t _this, const char* commandBuffer, const int reliableCmdSize, int type);
|
||||
unsigned int MSG_WriteReliableCommandToBuffer(const char* pszCommand, char* pszBuffer, unsigned int iBufferSize);
|
||||
|
||||
void CL_Main_AddReliableCommand(const char* cmd);
|
||||
|
||||
bool BG_Weapons_GetFullWeaponForName(const char* name, Weapon* outWeapon, Weapon* (__fastcall* getWeaponFunc)(Weapon* result, const char*));
|
||||
|
||||
void Scr_AddString(scrContext_t* scrContext, const char* value);
|
||||
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount);
|
||||
void Scr_FreeThread(scrContext_t* scrContext, unsigned int handle);
|
||||
|
||||
int G_Weapon_GivePlayerWeapon(uintptr_t ps, uintptr_t scrContext, Weapon* weapon, int dualWield, int startInAltMode, int usedBefore);
|
||||
void G_Items_AddAmmo(uintptr_t ps, Weapon* weapon, bool isAlternate, int count, int fillClip);
|
||||
|
||||
void G_Weapon_SelectWeapon(int clientNum, Weapon* weapon);
|
||||
Weapon* BG_FindBaseWeaponForName(Weapon* result, const char* name);
|
||||
|
||||
scrContext_t* ScriptContext_Server();
|
||||
|
||||
const char* SL_ConvertToString(int id);
|
||||
|
||||
union XAssetHeader DB_FindXAssetHeader(enum XAssetType type, const char* givenName, int allowCreateDefault);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
extern Addresses g_Addrs;
|
196
hook_lib/hook_lib.vcxproj
Normal file
196
hook_lib/hook_lib.vcxproj
Normal file
@ -0,0 +1,196 @@
|
||||
<?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|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{d84dca02-7bee-40e4-81d5-75eb0aa0a9d3}</ProjectGuid>
|
||||
<RootNamespace>hooklib</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</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>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
|
||||
</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>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>discord_game_sdk</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>discord_game_sdk</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</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>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>minhook.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NOMINMAX;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>minhook.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="common\exception\minidump.cpp" />
|
||||
<ClCompile Include="common\utils\binary_resource.cpp" />
|
||||
<ClCompile Include="common\utils\hardware_breakpoint.cpp" />
|
||||
<ClCompile Include="common\utils\hook.cpp" />
|
||||
<ClCompile Include="common\utils\http.cpp" />
|
||||
<ClCompile Include="common\utils\io.cpp" />
|
||||
<ClCompile Include="common\utils\memory.cpp" />
|
||||
<ClCompile Include="common\utils\nt.cpp" />
|
||||
<ClCompile Include="common\utils\signature.cpp" />
|
||||
<ClCompile Include="common\utils\smbios.cpp" />
|
||||
<ClCompile Include="common\utils\string.cpp" />
|
||||
<ClCompile Include="common\utils\thread.cpp" />
|
||||
<ClCompile Include="functions.cpp" />
|
||||
<ClCompile Include="assets.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="splashscreen.cpp" />
|
||||
<ClCompile Include="structs.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="assets.h" />
|
||||
<ClInclude Include="common\exception\minidump.hpp" />
|
||||
<ClInclude Include="common\utils\binary_resource.hpp" />
|
||||
<ClInclude Include="common\utils\concurrency.hpp" />
|
||||
<ClInclude Include="common\utils\finally.hpp" />
|
||||
<ClInclude Include="common\utils\hardware_breakpoint.hpp" />
|
||||
<ClInclude Include="common\utils\hook.hpp" />
|
||||
<ClInclude Include="common\utils\http.hpp" />
|
||||
<ClInclude Include="common\utils\io.hpp" />
|
||||
<ClInclude Include="common\utils\memory.hpp" />
|
||||
<ClInclude Include="common\utils\nt.hpp" />
|
||||
<ClInclude Include="common\utils\signature.hpp" />
|
||||
<ClInclude Include="common\utils\smbios.hpp" />
|
||||
<ClInclude Include="common\utils\string.hpp" />
|
||||
<ClInclude Include="common\utils\thread.hpp" />
|
||||
<ClInclude Include="csv.hpp" />
|
||||
<ClInclude Include="functions.hpp" />
|
||||
<ClInclude Include="ini.h" />
|
||||
<ClInclude Include="json.hpp" />
|
||||
<ClInclude Include="Main.hpp" />
|
||||
<ClInclude Include="MinHook.hpp" />
|
||||
<ClInclude Include="structs.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
143
hook_lib/hook_lib.vcxproj.filters
Normal file
143
hook_lib/hook_lib.vcxproj.filters
Normal file
@ -0,0 +1,143 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Resource Files">
|
||||
<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="common">
|
||||
<UniqueIdentifier>{9ba1aab7-3c29-4043-88a2-0733bdba52af}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common\exception">
|
||||
<UniqueIdentifier>{67571f10-529c-4ebd-94b6-2cebbbb62a35}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common\utils">
|
||||
<UniqueIdentifier>{03fd645c-a59f-4d26-950c-b411df71f725}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hook_lib">
|
||||
<UniqueIdentifier>{997a4fac-6cde-43a6-84df-2e0e58b4b7fc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hook_lib\game">
|
||||
<UniqueIdentifier>{0999b80b-b47c-4d8e-8776-f5c778bcac9f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="common\utils\binary_resource.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\hardware_breakpoint.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\hook.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\http.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\io.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\memory.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\nt.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\signature.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\smbios.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\string.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\exception\minidump.cpp">
|
||||
<Filter>common\exception</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Main.cpp">
|
||||
<Filter>hook_lib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="functions.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\thread.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="structs.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="assets.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="splashscreen.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="common\utils\binary_resource.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\concurrency.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\finally.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\hardware_breakpoint.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\hook.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\http.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\io.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\memory.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\nt.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\signature.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\smbios.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\string.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\exception\minidump.hpp">
|
||||
<Filter>common\exception</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Main.hpp">
|
||||
<Filter>hook_lib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MinHook.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="functions.hpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\thread.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="structs.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="assets.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ini.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="json.hpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="csv.hpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
15
hook_lib/hook_lib.vcxproj.user
Normal file
15
hook_lib/hook_lib.vcxproj.user
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerCommand>D:\Games\CODMWDebug\Call of Duty Modern Warfare %282019%29\game_dx12_ship_replay.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommand>D:\Games\CODMWDebug\Call of Duty Modern Warfare %282019%29\game_dx12_ship_replay.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerWorkingDirectory>..\..\..\..\Games\CODMWDebug\Call of Duty Modern Warfare %282019%29</LocalDebuggerWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
</Project>
|
789
hook_lib/ini.h
Normal file
789
hook_lib/ini.h
Normal file
@ -0,0 +1,789 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2018 Danijel Durakovic
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// /mINI/ v0.9.14
|
||||
// An INI file reader and writer for the modern age.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// A tiny utility library for manipulating INI files with a straightforward
|
||||
// API and a minimal footprint. It conforms to the (somewhat) standard INI
|
||||
// format - sections and keys are case insensitive and all leading and
|
||||
// trailing whitespace is ignored. Comments are lines that begin with a
|
||||
// semicolon. Trailing comments are allowed on section lines.
|
||||
//
|
||||
// Files are read on demand, upon which data is kept in memory and the file
|
||||
// is closed. This utility supports lazy writing, which only writes changes
|
||||
// and updates to a file and preserves custom formatting and comments. A lazy
|
||||
// write invoked by a write() call will read the output file, find what
|
||||
// changes have been made and update the file accordingly. If you only need to
|
||||
// generate files, use generate() instead. Section and key order is preserved
|
||||
// on read, write and insert.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// /* BASIC USAGE EXAMPLE: */
|
||||
//
|
||||
// /* read from file */
|
||||
// mINI::INIFile file("myfile.ini");
|
||||
// mINI::INIStructure ini;
|
||||
// file.read(ini);
|
||||
//
|
||||
// /* read value; gets a reference to actual value in the structure.
|
||||
// if key or section don't exist, a new empty value will be created */
|
||||
// std::string& value = ini["section"]["key"];
|
||||
//
|
||||
// /* read value safely; gets a copy of value in the structure.
|
||||
// does not alter the structure */
|
||||
// std::string value = ini.get("section").get("key");
|
||||
//
|
||||
// /* set or update values */
|
||||
// ini["section"]["key"] = "value";
|
||||
//
|
||||
// /* set multiple values */
|
||||
// ini["section2"].set({
|
||||
// {"key1", "value1"},
|
||||
// {"key2", "value2"}
|
||||
// });
|
||||
//
|
||||
// /* write updates back to file, preserving comments and formatting */
|
||||
// file.write(ini);
|
||||
//
|
||||
// /* or generate a file (overwrites the original) */
|
||||
// file.generate(ini);
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Long live the INI file!!!
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MINI_INI_H_
|
||||
#define MINI_INI_H_
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include <cctype>
|
||||
|
||||
namespace mINI
|
||||
{
|
||||
namespace INIStringUtil
|
||||
{
|
||||
const char* const whitespaceDelimiters = " \t\n\r\f\v";
|
||||
inline void trim(std::string& str)
|
||||
{
|
||||
str.erase(str.find_last_not_of(whitespaceDelimiters) + 1);
|
||||
str.erase(0, str.find_first_not_of(whitespaceDelimiters));
|
||||
}
|
||||
#ifndef MINI_CASE_SENSITIVE
|
||||
inline void toLower(std::string& str)
|
||||
{
|
||||
std::transform(str.begin(), str.end(), str.begin(), [](const char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
});
|
||||
}
|
||||
#endif
|
||||
inline void replace(std::string& str, std::string const& a, std::string const& b)
|
||||
{
|
||||
if (!a.empty())
|
||||
{
|
||||
std::size_t pos = 0;
|
||||
while ((pos = str.find(a, pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(pos, a.size(), b);
|
||||
pos += b.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef _WIN32
|
||||
const char* const endl = "\r\n";
|
||||
#else
|
||||
const char* const endl = "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class INIMap
|
||||
{
|
||||
private:
|
||||
using T_DataIndexMap = std::unordered_map<std::string, std::size_t>;
|
||||
using T_DataItem = std::pair<std::string, T>;
|
||||
using T_DataContainer = std::vector<T_DataItem>;
|
||||
using T_MultiArgs = typename std::vector<std::pair<std::string, T>>;
|
||||
|
||||
T_DataIndexMap dataIndexMap;
|
||||
T_DataContainer data;
|
||||
|
||||
inline std::size_t setEmpty(std::string& key)
|
||||
{
|
||||
std::size_t index = data.size();
|
||||
dataIndexMap[key] = index;
|
||||
data.emplace_back(key, T());
|
||||
return index;
|
||||
}
|
||||
|
||||
public:
|
||||
using const_iterator = typename T_DataContainer::const_iterator;
|
||||
|
||||
INIMap() { }
|
||||
|
||||
INIMap(INIMap const& other)
|
||||
{
|
||||
std::size_t data_size = other.data.size();
|
||||
for (std::size_t i = 0; i < data_size; ++i)
|
||||
{
|
||||
auto const& key = other.data[i].first;
|
||||
auto const& obj = other.data[i].second;
|
||||
data.emplace_back(key, obj);
|
||||
}
|
||||
dataIndexMap = T_DataIndexMap(other.dataIndexMap);
|
||||
}
|
||||
|
||||
T& operator[](std::string key)
|
||||
{
|
||||
INIStringUtil::trim(key);
|
||||
#ifndef MINI_CASE_SENSITIVE
|
||||
INIStringUtil::toLower(key);
|
||||
#endif
|
||||
auto it = dataIndexMap.find(key);
|
||||
bool hasIt = (it != dataIndexMap.end());
|
||||
std::size_t index = (hasIt) ? it->second : setEmpty(key);
|
||||
return data[index].second;
|
||||
}
|
||||
T get(std::string key) const
|
||||
{
|
||||
INIStringUtil::trim(key);
|
||||
#ifndef MINI_CASE_SENSITIVE
|
||||
INIStringUtil::toLower(key);
|
||||
#endif
|
||||
auto it = dataIndexMap.find(key);
|
||||
if (it == dataIndexMap.end())
|
||||
{
|
||||
return T();
|
||||
}
|
||||
return T(data[it->second].second);
|
||||
}
|
||||
bool has(std::string key) const
|
||||
{
|
||||
INIStringUtil::trim(key);
|
||||
#ifndef MINI_CASE_SENSITIVE
|
||||
INIStringUtil::toLower(key);
|
||||
#endif
|
||||
return (dataIndexMap.count(key) == 1);
|
||||
}
|
||||
void set(std::string key, T obj)
|
||||
{
|
||||
INIStringUtil::trim(key);
|
||||
#ifndef MINI_CASE_SENSITIVE
|
||||
INIStringUtil::toLower(key);
|
||||
#endif
|
||||
auto it = dataIndexMap.find(key);
|
||||
if (it != dataIndexMap.end())
|
||||
{
|
||||
data[it->second].second = obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataIndexMap[key] = data.size();
|
||||
data.emplace_back(key, obj);
|
||||
}
|
||||
}
|
||||
void set(T_MultiArgs const& multiArgs)
|
||||
{
|
||||
for (auto const& it : multiArgs)
|
||||
{
|
||||
auto const& key = it.first;
|
||||
auto const& obj = it.second;
|
||||
set(key, obj);
|
||||
}
|
||||
}
|
||||
bool remove(std::string key)
|
||||
{
|
||||
INIStringUtil::trim(key);
|
||||
#ifndef MINI_CASE_SENSITIVE
|
||||
INIStringUtil::toLower(key);
|
||||
#endif
|
||||
auto it = dataIndexMap.find(key);
|
||||
if (it != dataIndexMap.end())
|
||||
{
|
||||
std::size_t index = it->second;
|
||||
data.erase(data.begin() + index);
|
||||
dataIndexMap.erase(it);
|
||||
for (auto& it2 : dataIndexMap)
|
||||
{
|
||||
auto& vi = it2.second;
|
||||
if (vi > index)
|
||||
{
|
||||
vi--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
data.clear();
|
||||
dataIndexMap.clear();
|
||||
}
|
||||
std::size_t size() const
|
||||
{
|
||||
return data.size();
|
||||
}
|
||||
const_iterator begin() const { return data.begin(); }
|
||||
const_iterator end() const { return data.end(); }
|
||||
};
|
||||
|
||||
using INIStructure = INIMap<INIMap<std::string>>;
|
||||
|
||||
namespace INIParser
|
||||
{
|
||||
using T_ParseValues = std::pair<std::string, std::string>;
|
||||
|
||||
enum class PDataType : char
|
||||
{
|
||||
PDATA_NONE,
|
||||
PDATA_COMMENT,
|
||||
PDATA_SECTION,
|
||||
PDATA_KEYVALUE,
|
||||
PDATA_UNKNOWN
|
||||
};
|
||||
|
||||
inline PDataType parseLine(std::string line, T_ParseValues& parseData)
|
||||
{
|
||||
parseData.first.clear();
|
||||
parseData.second.clear();
|
||||
INIStringUtil::trim(line);
|
||||
if (line.empty())
|
||||
{
|
||||
return PDataType::PDATA_NONE;
|
||||
}
|
||||
char firstCharacter = line[0];
|
||||
if (firstCharacter == ';')
|
||||
{
|
||||
return PDataType::PDATA_COMMENT;
|
||||
}
|
||||
if (firstCharacter == '[')
|
||||
{
|
||||
auto commentAt = line.find_first_of(';');
|
||||
if (commentAt != std::string::npos)
|
||||
{
|
||||
line = line.substr(0, commentAt);
|
||||
}
|
||||
auto closingBracketAt = line.find_last_of(']');
|
||||
if (closingBracketAt != std::string::npos)
|
||||
{
|
||||
auto section = line.substr(1, closingBracketAt - 1);
|
||||
INIStringUtil::trim(section);
|
||||
parseData.first = section;
|
||||
return PDataType::PDATA_SECTION;
|
||||
}
|
||||
}
|
||||
auto lineNorm = line;
|
||||
INIStringUtil::replace(lineNorm, "\\=", " ");
|
||||
auto equalsAt = lineNorm.find_first_of('=');
|
||||
if (equalsAt != std::string::npos)
|
||||
{
|
||||
auto key = line.substr(0, equalsAt);
|
||||
INIStringUtil::trim(key);
|
||||
INIStringUtil::replace(key, "\\=", "=");
|
||||
auto value = line.substr(equalsAt + 1);
|
||||
INIStringUtil::trim(value);
|
||||
parseData.first = key;
|
||||
parseData.second = value;
|
||||
return PDataType::PDATA_KEYVALUE;
|
||||
}
|
||||
return PDataType::PDATA_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
class INIReader
|
||||
{
|
||||
public:
|
||||
using T_LineData = std::vector<std::string>;
|
||||
using T_LineDataPtr = std::shared_ptr<T_LineData>;
|
||||
|
||||
bool isBOM = false;
|
||||
|
||||
private:
|
||||
std::ifstream fileReadStream;
|
||||
T_LineDataPtr lineData;
|
||||
|
||||
T_LineData readFile()
|
||||
{
|
||||
fileReadStream.seekg(0, std::ios::end);
|
||||
const std::size_t fileSize = static_cast<std::size_t>(fileReadStream.tellg());
|
||||
fileReadStream.seekg(0, std::ios::beg);
|
||||
if (fileSize >= 3) {
|
||||
const char header[3] = {
|
||||
static_cast<char>(fileReadStream.get()),
|
||||
static_cast<char>(fileReadStream.get()),
|
||||
static_cast<char>(fileReadStream.get())
|
||||
};
|
||||
isBOM = (
|
||||
header[0] == static_cast<char>(0xEF) &&
|
||||
header[1] == static_cast<char>(0xBB) &&
|
||||
header[2] == static_cast<char>(0xBF)
|
||||
);
|
||||
}
|
||||
else {
|
||||
isBOM = false;
|
||||
}
|
||||
std::string fileContents;
|
||||
fileContents.resize(fileSize);
|
||||
fileReadStream.seekg(isBOM ? 3 : 0, std::ios::beg);
|
||||
fileReadStream.read(&fileContents[0], fileSize);
|
||||
fileReadStream.close();
|
||||
T_LineData output;
|
||||
if (fileSize == 0)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
std::string buffer;
|
||||
buffer.reserve(50);
|
||||
for (std::size_t i = 0; i < fileSize; ++i)
|
||||
{
|
||||
char& c = fileContents[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
output.emplace_back(buffer);
|
||||
buffer.clear();
|
||||
continue;
|
||||
}
|
||||
if (c != '\0' && c != '\r')
|
||||
{
|
||||
buffer += c;
|
||||
}
|
||||
}
|
||||
output.emplace_back(buffer);
|
||||
return output;
|
||||
}
|
||||
|
||||
public:
|
||||
INIReader(std::string const& filename, bool keepLineData = false)
|
||||
{
|
||||
fileReadStream.open(filename, std::ios::in | std::ios::binary);
|
||||
if (keepLineData)
|
||||
{
|
||||
lineData = std::make_shared<T_LineData>();
|
||||
}
|
||||
}
|
||||
~INIReader() { }
|
||||
|
||||
bool operator>>(INIStructure& data)
|
||||
{
|
||||
if (!fileReadStream.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
T_LineData fileLines = readFile();
|
||||
std::string section;
|
||||
bool inSection = false;
|
||||
INIParser::T_ParseValues parseData;
|
||||
for (auto const& line : fileLines)
|
||||
{
|
||||
auto parseResult = INIParser::parseLine(line, parseData);
|
||||
if (parseResult == INIParser::PDataType::PDATA_SECTION)
|
||||
{
|
||||
inSection = true;
|
||||
data[section = parseData.first];
|
||||
}
|
||||
else if (inSection && parseResult == INIParser::PDataType::PDATA_KEYVALUE)
|
||||
{
|
||||
auto const& key = parseData.first;
|
||||
auto const& value = parseData.second;
|
||||
data[section][key] = value;
|
||||
}
|
||||
if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN)
|
||||
{
|
||||
if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
lineData->emplace_back(line);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
T_LineDataPtr getLines()
|
||||
{
|
||||
return lineData;
|
||||
}
|
||||
};
|
||||
|
||||
class INIGenerator
|
||||
{
|
||||
private:
|
||||
std::ofstream fileWriteStream;
|
||||
|
||||
public:
|
||||
bool prettyPrint = false;
|
||||
|
||||
INIGenerator(std::string const& filename)
|
||||
{
|
||||
fileWriteStream.open(filename, std::ios::out | std::ios::binary);
|
||||
}
|
||||
~INIGenerator() { }
|
||||
|
||||
bool operator<<(INIStructure const& data)
|
||||
{
|
||||
if (!fileWriteStream.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!data.size())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
auto it = data.begin();
|
||||
for (;;)
|
||||
{
|
||||
auto const& section = it->first;
|
||||
auto const& collection = it->second;
|
||||
fileWriteStream
|
||||
<< "["
|
||||
<< section
|
||||
<< "]";
|
||||
if (collection.size())
|
||||
{
|
||||
fileWriteStream << INIStringUtil::endl;
|
||||
auto it2 = collection.begin();
|
||||
for (;;)
|
||||
{
|
||||
auto key = it2->first;
|
||||
INIStringUtil::replace(key, "=", "\\=");
|
||||
auto value = it2->second;
|
||||
INIStringUtil::trim(value);
|
||||
fileWriteStream
|
||||
<< key
|
||||
<< ((prettyPrint) ? " = " : "=")
|
||||
<< value;
|
||||
if (++it2 == collection.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
fileWriteStream << INIStringUtil::endl;
|
||||
}
|
||||
}
|
||||
if (++it == data.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
fileWriteStream << INIStringUtil::endl;
|
||||
if (prettyPrint)
|
||||
{
|
||||
fileWriteStream << INIStringUtil::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class INIWriter
|
||||
{
|
||||
private:
|
||||
using T_LineData = std::vector<std::string>;
|
||||
using T_LineDataPtr = std::shared_ptr<T_LineData>;
|
||||
|
||||
std::string filename;
|
||||
|
||||
T_LineData getLazyOutput(T_LineDataPtr const& lineData, INIStructure& data, INIStructure& original)
|
||||
{
|
||||
T_LineData output;
|
||||
INIParser::T_ParseValues parseData;
|
||||
std::string sectionCurrent;
|
||||
bool parsingSection = false;
|
||||
bool continueToNextSection = false;
|
||||
bool discardNextEmpty = false;
|
||||
bool writeNewKeys = false;
|
||||
std::size_t lastKeyLine = 0;
|
||||
for (auto line = lineData->begin(); line != lineData->end(); ++line)
|
||||
{
|
||||
if (!writeNewKeys)
|
||||
{
|
||||
auto parseResult = INIParser::parseLine(*line, parseData);
|
||||
if (parseResult == INIParser::PDataType::PDATA_SECTION)
|
||||
{
|
||||
if (parsingSection)
|
||||
{
|
||||
writeNewKeys = true;
|
||||
parsingSection = false;
|
||||
--line;
|
||||
continue;
|
||||
}
|
||||
sectionCurrent = parseData.first;
|
||||
if (data.has(sectionCurrent))
|
||||
{
|
||||
parsingSection = true;
|
||||
continueToNextSection = false;
|
||||
discardNextEmpty = false;
|
||||
output.emplace_back(*line);
|
||||
lastKeyLine = output.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
continueToNextSection = true;
|
||||
discardNextEmpty = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE)
|
||||
{
|
||||
if (continueToNextSection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (data.has(sectionCurrent))
|
||||
{
|
||||
auto& collection = data[sectionCurrent];
|
||||
auto const& key = parseData.first;
|
||||
auto const& value = parseData.second;
|
||||
if (collection.has(key))
|
||||
{
|
||||
auto outputValue = collection[key];
|
||||
if (value == outputValue)
|
||||
{
|
||||
output.emplace_back(*line);
|
||||
}
|
||||
else
|
||||
{
|
||||
INIStringUtil::trim(outputValue);
|
||||
auto lineNorm = *line;
|
||||
INIStringUtil::replace(lineNorm, "\\=", " ");
|
||||
auto equalsAt = lineNorm.find_first_of('=');
|
||||
auto valueAt = lineNorm.find_first_not_of(
|
||||
INIStringUtil::whitespaceDelimiters,
|
||||
equalsAt + 1
|
||||
);
|
||||
std::string outputLine = line->substr(0, valueAt);
|
||||
if (prettyPrint && equalsAt + 1 == valueAt)
|
||||
{
|
||||
outputLine += " ";
|
||||
}
|
||||
outputLine += outputValue;
|
||||
output.emplace_back(outputLine);
|
||||
}
|
||||
lastKeyLine = output.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (discardNextEmpty && line->empty())
|
||||
{
|
||||
discardNextEmpty = false;
|
||||
}
|
||||
else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN)
|
||||
{
|
||||
output.emplace_back(*line);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (writeNewKeys || std::next(line) == lineData->end())
|
||||
{
|
||||
T_LineData linesToAdd;
|
||||
if (data.has(sectionCurrent) && original.has(sectionCurrent))
|
||||
{
|
||||
auto const& collection = data[sectionCurrent];
|
||||
auto const& collectionOriginal = original[sectionCurrent];
|
||||
for (auto const& it : collection)
|
||||
{
|
||||
auto key = it.first;
|
||||
if (collectionOriginal.has(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
auto value = it.second;
|
||||
INIStringUtil::replace(key, "=", "\\=");
|
||||
INIStringUtil::trim(value);
|
||||
linesToAdd.emplace_back(
|
||||
key + ((prettyPrint) ? " = " : "=") + value
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!linesToAdd.empty())
|
||||
{
|
||||
output.insert(
|
||||
output.begin() + lastKeyLine,
|
||||
linesToAdd.begin(),
|
||||
linesToAdd.end()
|
||||
);
|
||||
}
|
||||
if (writeNewKeys)
|
||||
{
|
||||
writeNewKeys = false;
|
||||
--line;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto const& it : data)
|
||||
{
|
||||
auto const& section = it.first;
|
||||
if (original.has(section))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (prettyPrint && output.size() > 0 && !output.back().empty())
|
||||
{
|
||||
output.emplace_back();
|
||||
}
|
||||
output.emplace_back("[" + section + "]");
|
||||
auto const& collection = it.second;
|
||||
for (auto const& it2 : collection)
|
||||
{
|
||||
auto key = it2.first;
|
||||
auto value = it2.second;
|
||||
INIStringUtil::replace(key, "=", "\\=");
|
||||
INIStringUtil::trim(value);
|
||||
output.emplace_back(
|
||||
key + ((prettyPrint) ? " = " : "=") + value
|
||||
);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public:
|
||||
bool prettyPrint = false;
|
||||
|
||||
INIWriter(std::string const& filename)
|
||||
: filename(filename)
|
||||
{
|
||||
}
|
||||
~INIWriter() { }
|
||||
|
||||
bool operator<<(INIStructure& data)
|
||||
{
|
||||
struct stat buf;
|
||||
bool fileExists = (stat(filename.c_str(), &buf) == 0);
|
||||
if (!fileExists)
|
||||
{
|
||||
INIGenerator generator(filename);
|
||||
generator.prettyPrint = prettyPrint;
|
||||
return generator << data;
|
||||
}
|
||||
INIStructure originalData;
|
||||
T_LineDataPtr lineData;
|
||||
bool readSuccess = false;
|
||||
bool fileIsBOM = false;
|
||||
{
|
||||
INIReader reader(filename, true);
|
||||
if ((readSuccess = reader >> originalData))
|
||||
{
|
||||
lineData = reader.getLines();
|
||||
fileIsBOM = reader.isBOM;
|
||||
}
|
||||
}
|
||||
if (!readSuccess)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
T_LineData output = getLazyOutput(lineData, data, originalData);
|
||||
std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary);
|
||||
if (fileWriteStream.is_open())
|
||||
{
|
||||
if (fileIsBOM) {
|
||||
const char utf8_BOM[3] = {
|
||||
static_cast<char>(0xEF),
|
||||
static_cast<char>(0xBB),
|
||||
static_cast<char>(0xBF)
|
||||
};
|
||||
fileWriteStream.write(utf8_BOM, 3);
|
||||
}
|
||||
if (output.size())
|
||||
{
|
||||
auto line = output.begin();
|
||||
for (;;)
|
||||
{
|
||||
fileWriteStream << *line;
|
||||
if (++line == output.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
fileWriteStream << INIStringUtil::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class INIFile
|
||||
{
|
||||
private:
|
||||
std::string filename;
|
||||
|
||||
public:
|
||||
INIFile(std::string const& filename)
|
||||
: filename(filename)
|
||||
{ }
|
||||
|
||||
~INIFile() { }
|
||||
|
||||
bool read(INIStructure& data) const
|
||||
{
|
||||
if (data.size())
|
||||
{
|
||||
data.clear();
|
||||
}
|
||||
if (filename.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
INIReader reader(filename);
|
||||
return reader >> data;
|
||||
}
|
||||
bool generate(INIStructure const& data, bool pretty = false) const
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
INIGenerator generator(filename);
|
||||
generator.prettyPrint = pretty;
|
||||
return generator << data;
|
||||
}
|
||||
bool write(INIStructure& data, bool pretty = false) const
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
INIWriter writer(filename);
|
||||
writer.prettyPrint = pretty;
|
||||
return writer << data;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MINI_INI_H_
|
24673
hook_lib/json.hpp
Normal file
24673
hook_lib/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
0
hook_lib/main/data0.dcache
Normal file
0
hook_lib/main/data0.dcache
Normal file
0
hook_lib/main/data1.dcache
Normal file
0
hook_lib/main/data1.dcache
Normal file
BIN
hook_lib/main/toc0.dcache
Normal file
BIN
hook_lib/main/toc0.dcache
Normal file
Binary file not shown.
BIN
hook_lib/main/toc1.dcache
Normal file
BIN
hook_lib/main/toc1.dcache
Normal file
Binary file not shown.
BIN
hook_lib/minhook.lib
Normal file
BIN
hook_lib/minhook.lib
Normal file
Binary file not shown.
8
hook_lib/output.log
Normal file
8
hook_lib/output.log
Normal file
@ -0,0 +1,8 @@
|
||||
Base Address: 00007FF7D0550000
|
||||
dvar registered!
|
||||
dvar registered!
|
||||
registering lui dvars
|
||||
Base Address: 00007FF7D0550000
|
||||
dvar registered!
|
||||
dvar registered!
|
||||
registering lui dvars
|
1
hook_lib/resource.h
Normal file
1
hook_lib/resource.h
Normal file
@ -0,0 +1 @@
|
||||
#pragma once
|
9
hook_lib/splashscreen.cpp
Normal file
9
hook_lib/splashscreen.cpp
Normal file
File diff suppressed because one or more lines are too long
15
hook_lib/splashscreen.hpp
Normal file
15
hook_lib/splashscreen.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Main.hpp"
|
||||
typedef unsigned char byte;
|
||||
|
||||
size_t operator"" _b(size_t val);
|
||||
size_t reverse_b(size_t val);
|
||||
size_t reverse_b(const void* val);
|
||||
|
||||
size_t operator"" _g(size_t val);
|
||||
size_t reverse_g(size_t val);
|
||||
size_t reverse_g(const void* val);
|
||||
|
||||
extern byte data_buf[0x12856B];
|
||||
|
||||
void set_splashscreen();
|
116
hook_lib/structs.cpp
Normal file
116
hook_lib/structs.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
#include "structs.h"
|
||||
|
||||
|
||||
|
||||
#pragma region //msg_t
|
||||
|
||||
unsigned __int64 MSG_ReadInt64(const msg_t* msg) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const msg_t*)>(0x1412B9270_g);
|
||||
return func(msg);
|
||||
}
|
||||
|
||||
void MSG_WriteInt64(const msg_t* msg, const unsigned __int64 value) {
|
||||
auto func = reinterpret_cast<void(*)(const msg_t*, const unsigned __int64)>(0x1412BA7F0_g);
|
||||
func(msg, value);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region //XUID
|
||||
|
||||
void XUID::Deserialize(const msg_t* msg) {
|
||||
this->m_id = MSG_ReadInt64(msg);
|
||||
}
|
||||
|
||||
void XUID::Serialize(const msg_t* msg) {
|
||||
MSG_WriteInt64(msg, this->m_id);
|
||||
}
|
||||
|
||||
XUID* XUID::FromHexString(const char* xuidString) {
|
||||
this->m_id = I_atoui64_hex(xuidString);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromMsg(const msg_t* msg) {
|
||||
this->m_id = MSG_ReadInt64(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromString(const char* xuidString) {
|
||||
this->m_id = I_atoui64(xuidString);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromUInt64(unsigned __int64 id) {
|
||||
this->m_id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromUniversalId(unsigned __int64 id) {
|
||||
this->m_id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
unsigned __int64 XUID::GetUniversalId() {
|
||||
return this->m_id;
|
||||
}
|
||||
|
||||
bool XUID::IsNull() {
|
||||
return this->m_id == 0;
|
||||
}
|
||||
|
||||
bool XUID::IsValid() {
|
||||
return this->m_id != 0;
|
||||
}
|
||||
|
||||
XUID* XUID::NullXUID() {
|
||||
this->m_id = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::RandomXUID() {
|
||||
unsigned int* RandSeed;
|
||||
unsigned int BackupRandSeed;
|
||||
this->m_id = 0;
|
||||
RandSeed = GetRandSeed();
|
||||
BackupRandSeed = *RandSeed;
|
||||
*RandSeed = Sys_Microseconds();
|
||||
this->m_id = I_irand(1, 0x7FFFFFFF);
|
||||
*RandSeed = BackupRandSeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
const char* XUID::ToDevString() {
|
||||
return va("%zu", this->m_id);
|
||||
}
|
||||
|
||||
const char* XUID::ToHexString() {
|
||||
return va("%zx", this->m_id);
|
||||
}
|
||||
|
||||
const char* XUID::ToString() {
|
||||
return va("%zu", this->m_id);
|
||||
}
|
||||
|
||||
bool XUID::operator !=(const XUID* xuid) {
|
||||
return this->m_id != xuid->m_id;
|
||||
}
|
||||
|
||||
XUID* XUID::operator =(const XUID* xuid) {
|
||||
this->m_id = xuid->m_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
bool XUID::operator ==(const XUID* xuid) {
|
||||
return this->m_id == xuid->m_id;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
ClActiveClient* ms_activeClients;
|
||||
|
||||
clientUIActive_t* clientUIActives;
|
||||
|
||||
gentity_s* g_entities;
|
2058
hook_lib/structs.h
Normal file
2058
hook_lib/structs.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user