-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#pragma once | ||
|
||
#ifdef RED4EXT_STATIC_LIB | ||
#include <RED4ext/Relocation.hpp> | ||
#endif | ||
|
||
#include <mutex> | ||
#include <sstream> | ||
|
||
#include <Windows.h> | ||
|
||
#include <RED4ext/Common.hpp> | ||
|
||
RED4EXT_INLINE uintptr_t RED4ext::RelocBase::GetImageBase() | ||
{ | ||
static const auto base = reinterpret_cast<uintptr_t>(GetModuleHandle(nullptr)); | ||
return base; | ||
} | ||
|
||
RED4EXT_INLINE | ||
uintptr_t RED4ext::UniversalRelocBase::Resolve(UniversalRelocSegment aSegment, uint64_t aHash) | ||
{ | ||
using functionType = uintptr_t (*)(UniversalRelocSegment, uint64_t); | ||
static functionType resolveFunc = nullptr; | ||
|
||
static std::once_flag flag; | ||
std::call_once(flag, | ||
[]() | ||
{ | ||
constexpr auto dllName = "RED4ext.dll"; | ||
constexpr auto functionName = "RED4ext_ResolveAddress"; | ||
|
||
auto handle = LoadLibraryA(dllName); | ||
if (!handle) | ||
{ | ||
std::stringstream stream; | ||
stream << "Failed to get '" << dllName | ||
<< "' handle.\nProcess will now close.\n\nLast error: " << GetLastError(); | ||
|
||
MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); | ||
TerminateProcess(GetCurrentProcess(), 1); | ||
} | ||
|
||
resolveFunc = reinterpret_cast<functionType>(GetProcAddress(handle, functionName)); | ||
if (resolveFunc == nullptr) | ||
{ | ||
std::stringstream stream; | ||
stream << "Failed to get '" << functionName | ||
<< "' address.\nProcess will now close.\n\nLast error: " << GetLastError(); | ||
|
||
MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); | ||
TerminateProcess(GetCurrentProcess(), 1); | ||
} | ||
}); | ||
|
||
auto address = resolveFunc(aSegment, aHash); | ||
if (address == 0) | ||
{ | ||
std::stringstream stream; | ||
stream << "Failed to resolve address for hash " << std::hex << aHash << ".\nProcess will now close."; | ||
|
||
MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); | ||
TerminateProcess(GetCurrentProcess(), 1); | ||
} | ||
|
||
return address; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef RED4EXT_STATIC_LIB | ||
#error Please define 'RED4EXT_STATIC_LIB' to compile this file. | ||
#endif | ||
|
||
#include <RED4ext/Relocation-inl.hpp> | ||
|