From 8c977059ba539e70c4b7b613a4be2716b5cec8b3 Mon Sep 17 00:00:00 2001 From: phra Date: Wed, 27 Oct 2021 00:37:08 +0200 Subject: [PATCH] refactor: small fixes --- fluctuate.cpp | 16 ++++++++-------- fluctuate.hpp | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/fluctuate.cpp b/fluctuate.cpp index 35b4860..4ed5f12 100644 --- a/fluctuate.cpp +++ b/fluctuate.cpp @@ -4,11 +4,6 @@ unsigned char originalBytes[16] = { 0 }; unsigned int originalProtection = 0; unsigned int XOR_KEY = 0; -unsigned int generate_random_int() { - std::srand(std::time(nullptr)); - return std::rand() | std::rand() << 16; -} - #ifdef _DEBUG_ // https://gist.github.com/ccbrown/9722406 void DumpHex(const void* data, size_t size) { @@ -73,6 +68,11 @@ void print_type(DWORD type) { } #endif +unsigned int generate_random_int() { + std::srand(std::time(nullptr)); + return std::rand() | std::rand() << 16; +} + void xor32(void* address, unsigned int size, unsigned int key) { #ifdef _DEBUG_ wprintf(L"xor32: before xor 0x%p:\n", address); @@ -173,7 +173,7 @@ void xor_region_and_change_protection(void* address, unsigned int key, DWORD new } } - FlushInstructionCache(GetCurrentProcess(), allocation_base, region_size); + FlushInstructionCache((HANDLE)-1, allocation_base, region_size); xor32(allocation_base, region_size, key); if (!VirtualProtect(allocation_base, region_size, newProtection, &oldProt)) { @@ -184,7 +184,7 @@ void xor_region_and_change_protection(void* address, unsigned int key, DWORD new ExitProcess(-1); } - FlushInstructionCache(GetCurrentProcess(), allocation_base, region_size); + FlushInstructionCache((HANDLE)-1, allocation_base, region_size); } void inline_hook_function(BOOL enable, char* addressToHook, void* jumpAddress) { @@ -222,7 +222,7 @@ void inline_hook_function(BOOL enable, char* addressToHook, void* jumpAddress) { ExitProcess(-1); } - FlushInstructionCache(GetCurrentProcess(), addressToHook, trampolineLength); + FlushInstructionCache((HANDLE)-1, addressToHook, trampolineLength); if (!VirtualProtect(addressToHook, trampolineLength, oldProt, &oldProt)) { #ifdef _DEBUG_ diff --git a/fluctuate.hpp b/fluctuate.hpp index 0f9de2d..cd58885 100644 --- a/fluctuate.hpp +++ b/fluctuate.hpp @@ -5,6 +5,9 @@ #include #include #include +#ifdef _DEBUG_ +#include +#endif void fluctuate();