shjit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include "InlineHook.h"
|
||||
#include <stdio.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <memoryapi.h>
|
||||
#include "../cstrike/core/spoofcall/lazy_importer.hpp"
|
||||
bool detour(BYTE* src, BYTE* dst, const uintptr_t len)
|
||||
{
|
||||
if (len < 5) return false;
|
||||
DWORD curProtection;
|
||||
LI_FN(VirtualProtect).safe()(src, len, PAGE_EXECUTE_READWRITE, &curProtection);
|
||||
memset(src, 0x90, len);
|
||||
uintptr_t relativeAddress = ((uintptr_t)dst - (uintptr_t)src) - 5;
|
||||
*(BYTE*)src = 0xE9;
|
||||
*(uintptr_t*)((uintptr_t)src + 1) = relativeAddress;
|
||||
DWORD temp;
|
||||
LI_FN(VirtualProtect).safe()(src, len, curProtection, &temp);
|
||||
return true;
|
||||
}
|
||||
|
||||
BYTE* trampHook(BYTE* src, BYTE* dst, const uintptr_t len)
|
||||
{
|
||||
if (len < 5) return 0;
|
||||
void* gateway = LI_FN(VirtualAlloc).safe()(0, len + 5, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
||||
memcpy(gateway, src, len);
|
||||
intptr_t gatewayRelativeAddr = ((intptr_t)src - (intptr_t)gateway) - 5;
|
||||
*(char*)((intptr_t)gateway + len) = 0xE9;
|
||||
*(intptr_t*)((intptr_t)gateway + len + 1) = gatewayRelativeAddr;
|
||||
// detour(src, dst, len);
|
||||
return (BYTE*) gateway;
|
||||
}
|
||||
|
||||
void InlineHook::Hook(void* src, void* dest, const size_t len)
|
||||
{
|
||||
const BYTE* src_bytes = (BYTE*) src;
|
||||
|
||||
for(int i = 0; i < len; i++)
|
||||
og_bytes.push_back(src_bytes[i]);
|
||||
|
||||
source = (DWORD) src;
|
||||
|
||||
original = (DWORD)trampHook((BYTE*) src, (BYTE*) dest, len);
|
||||
|
||||
if(original)
|
||||
bEnabled = true;
|
||||
}
|
||||
|
||||
void InlineHook::Unhook()
|
||||
{
|
||||
BYTE* bytes = (BYTE*) source;
|
||||
|
||||
int i = 0;
|
||||
for(const BYTE& b : og_bytes)
|
||||
bytes[i++] = b;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <regex>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include <process.h>
|
||||
#include <DbgHelp.h>
|
||||
#include <filesystem>
|
||||
#include <libloaderapi.h>
|
||||
#include <Psapi.h>
|
||||
#include <corecrt_math_defines.h>
|
||||
#include <numbers>
|
||||
#include <iomanip>
|
||||
#include <iosfwd>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <list>
|
||||
#include <TlHelp32.h>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
class InlineHook
|
||||
{
|
||||
std::vector<BYTE> og_bytes;
|
||||
DWORD original = 0;
|
||||
DWORD source = 0;
|
||||
bool bEnabled = false;
|
||||
public:
|
||||
InlineHook(){}
|
||||
|
||||
void Hook(void* src, void* dest, const size_t len);
|
||||
void Unhook();
|
||||
|
||||
template<typename T>
|
||||
T GetOg()
|
||||
{
|
||||
return (T)original;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "ShadowVMT.h"
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <memoryapi.h>
|
||||
#include "../spoofcall/lazy_importer.hpp"
|
||||
ShadowVMT::ShadowVMT()
|
||||
: class_base(nullptr), vftbl_len(0), new_vftbl(nullptr), old_vftbl(nullptr)
|
||||
{
|
||||
}
|
||||
ShadowVMT::ShadowVMT(void* base)
|
||||
: class_base(base), vftbl_len(0), new_vftbl(nullptr), old_vftbl(nullptr)
|
||||
{
|
||||
}
|
||||
ShadowVMT::~ShadowVMT()
|
||||
{
|
||||
UnhookAll();
|
||||
}
|
||||
|
||||
bool ShadowVMT::Setup(void* base)
|
||||
{
|
||||
if(base != nullptr)
|
||||
class_base = base;
|
||||
|
||||
if(class_base == nullptr)
|
||||
return false;
|
||||
|
||||
old_vftbl = *(std::uintptr_t**)class_base;
|
||||
vftbl_len = CalcVtableLength(old_vftbl) * sizeof(std::uintptr_t);
|
||||
|
||||
if(vftbl_len == 0)
|
||||
return false;
|
||||
|
||||
new_vftbl = new std::uintptr_t[vftbl_len + 1]();
|
||||
|
||||
std::memcpy(&new_vftbl[1], old_vftbl, vftbl_len * sizeof(std::uintptr_t));
|
||||
|
||||
try {
|
||||
DWORD old;
|
||||
LI_FN(VirtualProtect).safe()(class_base, sizeof(uintptr_t), PAGE_READWRITE, &old);
|
||||
new_vftbl[0] = old_vftbl[-1];
|
||||
*(std::uintptr_t**)class_base = &new_vftbl[1];
|
||||
LI_FN(VirtualProtect).safe()(class_base, sizeof(uintptr_t), old, &old);
|
||||
} catch(...) {
|
||||
delete[] new_vftbl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
std::size_t ShadowVMT::CalcVtableLength(std::uintptr_t* vftbl_start)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION memInfo = { NULL };
|
||||
int m_nSize = -1;
|
||||
do {
|
||||
m_nSize++;
|
||||
LI_FN( VirtualQuery).safe()(reinterpret_cast<LPCVOID>(vftbl_start[m_nSize]), &memInfo, sizeof(memInfo));
|
||||
} while (memInfo.Protect == PAGE_EXECUTE_READ || memInfo.Protect == PAGE_EXECUTE_READWRITE);
|
||||
|
||||
return m_nSize;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <regex>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include <process.h>
|
||||
#include <DbgHelp.h>
|
||||
#include <filesystem>
|
||||
#include <libloaderapi.h>
|
||||
#include <Psapi.h>
|
||||
#include <corecrt_math_defines.h>
|
||||
#include <numbers>
|
||||
#include <iomanip>
|
||||
#include <iosfwd>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <list>
|
||||
#include <TlHelp32.h>
|
||||
#include <cstring>
|
||||
class ShadowVMT
|
||||
{
|
||||
public:
|
||||
ShadowVMT();
|
||||
ShadowVMT(void* base);
|
||||
~ShadowVMT();
|
||||
|
||||
bool Setup(void* class_base = nullptr);
|
||||
|
||||
template<typename T>
|
||||
void HookIndex(int index, T fun)
|
||||
{
|
||||
new_vftbl[index + 1] = reinterpret_cast<std::uintptr_t>(fun);
|
||||
}
|
||||
void UnhookIndex(int index)
|
||||
{
|
||||
new_vftbl[index] = old_vftbl[index];
|
||||
}
|
||||
void UnhookAll()
|
||||
{
|
||||
try {
|
||||
if (old_vftbl != nullptr) {
|
||||
DWORD old;
|
||||
VirtualProtect(class_base, sizeof(uintptr_t), PAGE_READWRITE, &old);
|
||||
*(std::uintptr_t**)class_base = old_vftbl;
|
||||
old_vftbl = nullptr;
|
||||
VirtualProtect(class_base, sizeof(uintptr_t), old, &old);
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T GetOg(int index)
|
||||
{
|
||||
return (T)old_vftbl[index];
|
||||
}
|
||||
|
||||
private:
|
||||
inline std::size_t CalcVtableLength(std::uintptr_t* vftbl_start);
|
||||
|
||||
void* class_base;
|
||||
std::size_t vftbl_len;
|
||||
std::uintptr_t* new_vftbl;
|
||||
std::uintptr_t* old_vftbl;
|
||||
};
|
||||
Reference in New Issue
Block a user