Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include "minhook/MinHook.h"
- #include <cstdint>
- #include <vector>
- #include <string>
- #include <iostream>
- #pragma comment(lib, "libMinHook.x86.lib")
- #define InRange(x, a, b) (x >= a && x <= b)
- #define getBit(x) (InRange((x & (~0x20)), 'A', 'F') ? ((x & (~0x20)) - 'A' + 0xA): (InRange(x, '0', '9') ? x - '0': 0))
- #define getByte(x) (getBit(x[0]) << 4 | getBit(x[1]))
- typedef void(__cdecl* oprintfunc)(char*, ...);
- oprintfunc printfunc = nullptr;
- std::uint8_t* scan(void* module, const char* signature)
- {
- static auto pattern_to_byte = [](const char* pattern) {
- auto bytes = std::vector<int>{};
- auto start = const_cast<char*>(pattern);
- auto end = const_cast<char*>(pattern) + strlen(pattern);
- for (auto current = start; current < end; ++current) {
- if (*current == '?') {
- ++current;
- if (*current == '?')
- ++current;
- bytes.push_back(-1);
- }
- else {
- bytes.push_back(strtoul(current, ¤t, 16));
- }
- }
- return bytes;
- };
- auto dosHeader = (PIMAGE_DOS_HEADER)module;
- auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew);
- auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage;
- auto patternBytes = pattern_to_byte(signature);
- auto scanBytes = reinterpret_cast<std::uint8_t*>(module);
- auto s = patternBytes.size();
- auto d = patternBytes.data();
- for (auto i = 0ul; i < sizeOfImage - s; ++i) {
- bool found = true;
- for (auto j = 0ul; j < s; ++j) {
- if (scanBytes[i + j] != d[j] && d[j] != -1) {
- found = false;
- break;
- }
- }
- if (found) {
- return &scanBytes[i];
- }
- }
- return nullptr;
- }
- int hookedPrint(char* Format, ...) {
- std::cout << "[hookedPrint]: " << Format << std::endl;
- if (std::string(Format).find("Loading script") != -1) {
- return 0;
- }
- }
- bool __stdcall DllMain( HINSTANCE hModule,
- unsigned long ul_reason_for_call,
- void* lpReserved
- )
- {
- if (ul_reason_for_call == 1) {
- DisableThreadLibraryCalls(hModule);
- AllocConsole();
- FILE* fDummy;
- freopen_s(&fDummy, "CONIN$", "r", stdin);
- freopen_s(&fDummy, "CONOUT$", "w", stderr);
- freopen_s(&fDummy, "CONOUT$", "w", stdout);
- std::uint8_t* func_addr = scan(GetModuleHandleW(L"SAMPFUNCS.asi"), "55 8B EC B8 ? ? ? ? E8 ? ? ? ? 8D 45 0C");
- MH_Initialize();
- MH_CreateHook(reinterpret_cast<void*>(func_addr), &hookedPrint, reinterpret_cast<void**>(&printfunc));
- MH_EnableHook(reinterpret_cast<void*>(func_addr));
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement