mirror of
https://git.recroomarchive.org/Radium/libradhook.git
synced 2026-08-07 09:10:59 +00:00
fix some styling
This commit is contained in:
@@ -24,19 +24,19 @@
|
||||
// result strings
|
||||
const char* RadHookResultToString(RadHookResult result) {
|
||||
switch (result) {
|
||||
case RadHookResult::Success: return "Success";
|
||||
case RadHookResult::AlreadyInstalled: return "AlreadyInstalled";
|
||||
case RadHookResult::NotInstalled: return "NotInstalled";
|
||||
case RadHookResult::AlreadyEnabled: return "AlreadyEnabled";
|
||||
case RadHookResult::AlreadyDisabled: return "AlreadyDisabled";
|
||||
case RadHookResult::MemoryAllocFailed: return "MemoryAllocFailed";
|
||||
case RadHookResult::MemoryProtectFailed: return "MemoryProtectFailed";
|
||||
case RadHookResult::DisassemblyFailed: return "DisassemblyFailed";
|
||||
case RadHookResult::InvalidTarget: return "InvalidTarget";
|
||||
case RadHookResult::InvalidDetour: return "InvalidDetour";
|
||||
case RadHookResult::InvalidHandle: return "InvalidHandle";
|
||||
case RadHookResult::TrampolineTooFar: return "TrampolineTooFar";
|
||||
default: return "Unknown";
|
||||
case RadHookResult::Success: return "Success";
|
||||
case RadHookResult::AlreadyInstalled: return "AlreadyInstalled";
|
||||
case RadHookResult::NotInstalled: return "NotInstalled";
|
||||
case RadHookResult::AlreadyEnabled: return "AlreadyEnabled";
|
||||
case RadHookResult::AlreadyDisabled: return "AlreadyDisabled";
|
||||
case RadHookResult::MemoryAllocFailed: return "MemoryAllocFailed";
|
||||
case RadHookResult::MemoryProtectFailed:return "MemoryProtectFailed";
|
||||
case RadHookResult::DisassemblyFailed: return "DisassemblyFailed";
|
||||
case RadHookResult::InvalidTarget: return "InvalidTarget";
|
||||
case RadHookResult::InvalidDetour: return "InvalidDetour";
|
||||
case RadHookResult::InvalidHandle: return "InvalidHandle";
|
||||
case RadHookResult::TrampolineTooFar: return "TrampolineTooFar";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,8 +258,10 @@ void RestoreProtection(void* /*addr*/, size_t /*size*/, unsigned long /*oldProte
|
||||
}
|
||||
|
||||
void FlushICache(void* addr, size_t size) {
|
||||
__builtin___clear_cache(reinterpret_cast<char*>(addr),
|
||||
reinterpret_cast<char*>(addr) + size);
|
||||
__builtin___clear_cache(
|
||||
reinterpret_cast<char*>(addr),
|
||||
reinterpret_cast<char*>(addr) + size
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -493,8 +495,7 @@ RadHookResult InstallHook(RadHookOpaque* h, void* target, void* detour) {
|
||||
int32_t originalDisp = 0;
|
||||
std::memcpy(&originalDisp, reinterpret_cast<const uint8_t*>(target) + off, 4);
|
||||
uintptr_t absTarget = reinterpret_cast<uintptr_t>(target) + off + 4 + static_cast<intptr_t>(originalDisp);
|
||||
intptr_t newDisp = static_cast<intptr_t>(absTarget) -
|
||||
(reinterpret_cast<intptr_t>(trampolineAlloc) + off + 4);
|
||||
intptr_t newDisp = static_cast<intptr_t>(absTarget) - (reinterpret_cast<intptr_t>(trampolineAlloc) + off + 4);
|
||||
if (newDisp < INT32_MIN || newDisp > INT32_MAX) {
|
||||
FreeExec(trampolineAlloc, allocSize);
|
||||
return RadHookResult::TrampolineTooFar;
|
||||
@@ -505,8 +506,12 @@ RadHookResult InstallHook(RadHookOpaque* h, void* target, void* detour) {
|
||||
|
||||
uint8_t* jumpBack = reinterpret_cast<uint8_t*>(trampolineAlloc) + stolenLen;
|
||||
uintptr_t backAddr = reinterpret_cast<uintptr_t>(target) + stolenLen;
|
||||
jumpBack[0] = 0xFF; jumpBack[1] = 0x25;
|
||||
jumpBack[2] = 0; jumpBack[3] = 0; jumpBack[4] = 0; jumpBack[5] = 0;
|
||||
{
|
||||
jumpBack[0] = 0xFF;
|
||||
jumpBack[1] = 0x25;
|
||||
jumpBack[2] = 0; jumpBack[3] = 0;
|
||||
jumpBack[4] = 0; jumpBack[5] = 0;
|
||||
}
|
||||
std::memcpy(jumpBack + 6, &backAddr, 8);
|
||||
|
||||
FlushICache(trampolineAlloc, allocSize);
|
||||
@@ -521,8 +526,13 @@ RadHookResult InstallHook(RadHookOpaque* h, void* target, void* detour) {
|
||||
h->originalLength = stolenLen;
|
||||
|
||||
uint8_t hookStub[kX64StubLen];
|
||||
hookStub[0] = 0xFF; hookStub[1] = 0x25;
|
||||
hookStub[2] = 0; hookStub[3] = 0; hookStub[4] = 0; hookStub[5] = 0;
|
||||
{
|
||||
hookStub[0] = 0xFF;
|
||||
hookStub[1] = 0x25;
|
||||
hookStub[2] = 0; hookStub[3] = 0;
|
||||
hookStub[4] = 0; hookStub[5] = 0;
|
||||
}
|
||||
|
||||
uintptr_t detourAddr = reinterpret_cast<uintptr_t>(detour);
|
||||
std::memcpy(hookStub + 6, &detourAddr, 8);
|
||||
std::memcpy(h->stubBytes, hookStub, kX64StubLen);
|
||||
|
||||
Reference in New Issue
Block a user