mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-09 20:24:16 +00:00
test dll changes
This commit is contained in:
2
thirdparty/hijackkit/.gitignore
vendored
Normal file
2
thirdparty/hijackkit/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.vs/
|
||||
out/
|
11
thirdparty/hijackkit/CMakeLists.txt
vendored
Normal file
11
thirdparty/hijackkit/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required (VERSION 3.8)
|
||||
project (HijackKit)
|
||||
|
||||
add_library(HijackKit "include/utils.h" "include/memory.h" "include/tricks.h" "source/memory.cpp" "source/utils.cpp")
|
||||
target_include_directories(HijackKit PUBLIC "include/")
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||
set_property(TARGET HijackKit PROPERTY CXX_STANDARD 20)
|
||||
endif()
|
||||
|
||||
set_target_properties(HijackKit PROPERTIES LINKER_LANGUAGE CXX)
|
1
thirdparty/hijackkit/README.txt
vendored
Normal file
1
thirdparty/hijackkit/README.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
https://github.com/Jettford/HijackKit
|
18
thirdparty/hijackkit/include/memory.h
vendored
Normal file
18
thirdparty/hijackkit/include/memory.h
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace hijack {
|
||||
namespace memory {
|
||||
inline void Protect(size_t address, size_t size, std::function<void()> function);
|
||||
inline void* Read(size_t address, size_t size);
|
||||
inline void Patch(size_t address, size_t size, void* data);
|
||||
|
||||
template<class T>
|
||||
inline void Patch(size_t address, T data) {
|
||||
hijack::memory::Patch(address, sizeof(T), &data);
|
||||
}
|
||||
}
|
||||
}
|
46
thirdparty/hijackkit/include/tricks.h
vendored
Normal file
46
thirdparty/hijackkit/include/tricks.h
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <winnt.h>
|
||||
#include <ntifs.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace hijack {
|
||||
namespace tricks {
|
||||
struct ModuleInfo {
|
||||
wchar_t* m_ModuleName;
|
||||
size_t m_ModuleBase;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline T* GetVFunc(void* instance, size_t index) {
|
||||
return (T*)*(size_t*)((size_t)instance + index * sizeof(size_t));
|
||||
}
|
||||
|
||||
inline std::vector<ModuleInfo> LookupDLL() {
|
||||
size_t pedAddr = __readgsqword(0x60);
|
||||
|
||||
size_t ldrData = *(size_t*)(pedAddr + 0x18);
|
||||
size_t firstEntry = *(size_t*)(ldrData + 0x10);
|
||||
size_t currentEntry = firstEntry;
|
||||
|
||||
std::vector<ModuleInfo> modules;
|
||||
|
||||
while (*(DWORD*)(currentEntry + 0x60) != NULL) {
|
||||
wchar_t* dllName = (wchar_t*)(currentEntry + 0x60);
|
||||
size_t dllBase = *(size_t*)(currentEntry + 0x30);
|
||||
|
||||
ModuleInfo info;
|
||||
info.m_ModuleName = dllName;
|
||||
info.m_ModuleBase = dllBase;
|
||||
|
||||
modules.push_back(info);
|
||||
|
||||
currentEntry = *(size_t*)currentEntry;
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
}
|
10
thirdparty/hijackkit/include/utils.h
vendored
Normal file
10
thirdparty/hijackkit/include/utils.h
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace hjiack {
|
||||
namespace utils {
|
||||
uintptr_t GetModuleBaseAddress(const wchar_t* moduleName);
|
||||
void AllocateConsole();
|
||||
}
|
||||
}
|
28
thirdparty/hijackkit/source/memory.cpp
vendored
Normal file
28
thirdparty/hijackkit/source/memory.cpp
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "memory.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
void hijack::memory::Protect(size_t address, size_t size, std::function<void()> function) {
|
||||
DWORD oldProtect;
|
||||
VirtualProtect((void*)address, size, PAGE_EXECUTE_READWRITE, &oldProtect);
|
||||
|
||||
function();
|
||||
|
||||
VirtualProtect((void*)address, size, oldProtect, &oldProtect);
|
||||
}
|
||||
|
||||
void* hijack::memory::Read(size_t address, size_t size) {
|
||||
void* returnData = malloc(size);
|
||||
|
||||
Protect(address, size, [&]() {
|
||||
memcpy(returnData, (void*)address, size);
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
void hijack::memory::Patch(size_t address, size_t size, void* data) {
|
||||
Protect(address, size, [&]() {
|
||||
memcpy((void*)address, data, size);
|
||||
});
|
||||
}
|
45
thirdparty/hijackkit/source/utils.cpp
vendored
Normal file
45
thirdparty/hijackkit/source/utils.cpp
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "utils.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <TlHelp32.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
uintptr_t hjiack::utils::GetModuleBaseAddress(const wchar_t* moduleName) {
|
||||
uintptr_t modBaseAddr = 0;
|
||||
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, GetCurrentProcessId());
|
||||
|
||||
if (hSnap != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
MODULEENTRY32 modEntry;
|
||||
modEntry.dwSize = sizeof(modEntry);
|
||||
if (Module32First(hSnap, &modEntry))
|
||||
{
|
||||
do
|
||||
{
|
||||
auto a = std::wstring((wchar_t*)modEntry.szModule);
|
||||
if (!_wcsicmp(a.c_str(), moduleName))
|
||||
{
|
||||
modBaseAddr = (uintptr_t)modEntry.modBaseAddr;
|
||||
break;
|
||||
}
|
||||
} while (Module32Next(hSnap, &modEntry));
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hSnap);
|
||||
|
||||
return modBaseAddr;
|
||||
}
|
||||
|
||||
void hjiack::utils::AllocateConsole() {
|
||||
AllocConsole();
|
||||
|
||||
|
||||
freopen_s((FILE**)__acrt_iob_func(1), "CONOUT$", "w", __acrt_iob_func(1));
|
||||
freopen_s((FILE**)__acrt_iob_func(2), "CONOUT$", "w", __acrt_iob_func(2));
|
||||
freopen_s((FILE**)__acrt_iob_func(0), "CONIN$", "r", __acrt_iob_func(0));
|
||||
}
|
||||
|
Reference in New Issue
Block a user