fix some styling

This commit is contained in:
nexusverypro
2026-07-03 15:42:15 +01:00
parent dec9a17cf7
commit d76f7d51a8

View File

@@ -24,19 +24,19 @@
// result strings // result strings
const char* RadHookResultToString(RadHookResult result) { const char* RadHookResultToString(RadHookResult result) {
switch (result) { switch (result) {
case RadHookResult::Success: return "Success"; case RadHookResult::Success: return "Success";
case RadHookResult::AlreadyInstalled: return "AlreadyInstalled"; case RadHookResult::AlreadyInstalled: return "AlreadyInstalled";
case RadHookResult::NotInstalled: return "NotInstalled"; case RadHookResult::NotInstalled: return "NotInstalled";
case RadHookResult::AlreadyEnabled: return "AlreadyEnabled"; case RadHookResult::AlreadyEnabled: return "AlreadyEnabled";
case RadHookResult::AlreadyDisabled: return "AlreadyDisabled"; case RadHookResult::AlreadyDisabled: return "AlreadyDisabled";
case RadHookResult::MemoryAllocFailed: return "MemoryAllocFailed"; case RadHookResult::MemoryAllocFailed: return "MemoryAllocFailed";
case RadHookResult::MemoryProtectFailed: return "MemoryProtectFailed"; case RadHookResult::MemoryProtectFailed:return "MemoryProtectFailed";
case RadHookResult::DisassemblyFailed: return "DisassemblyFailed"; case RadHookResult::DisassemblyFailed: return "DisassemblyFailed";
case RadHookResult::InvalidTarget: return "InvalidTarget"; case RadHookResult::InvalidTarget: return "InvalidTarget";
case RadHookResult::InvalidDetour: return "InvalidDetour"; case RadHookResult::InvalidDetour: return "InvalidDetour";
case RadHookResult::InvalidHandle: return "InvalidHandle"; case RadHookResult::InvalidHandle: return "InvalidHandle";
case RadHookResult::TrampolineTooFar: return "TrampolineTooFar"; case RadHookResult::TrampolineTooFar: return "TrampolineTooFar";
default: return "Unknown"; default: return "Unknown";
} }
} }
@@ -258,8 +258,10 @@ void RestoreProtection(void* /*addr*/, size_t /*size*/, unsigned long /*oldProte
} }
void FlushICache(void* addr, size_t size) { void FlushICache(void* addr, size_t size) {
__builtin___clear_cache(reinterpret_cast<char*>(addr), __builtin___clear_cache(
reinterpret_cast<char*>(addr) + size); reinterpret_cast<char*>(addr),
reinterpret_cast<char*>(addr) + size
);
} }
#endif #endif
@@ -493,8 +495,7 @@ RadHookResult InstallHook(RadHookOpaque* h, void* target, void* detour) {
int32_t originalDisp = 0; int32_t originalDisp = 0;
std::memcpy(&originalDisp, reinterpret_cast<const uint8_t*>(target) + off, 4); 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); uintptr_t absTarget = reinterpret_cast<uintptr_t>(target) + off + 4 + static_cast<intptr_t>(originalDisp);
intptr_t newDisp = static_cast<intptr_t>(absTarget) - intptr_t newDisp = static_cast<intptr_t>(absTarget) - (reinterpret_cast<intptr_t>(trampolineAlloc) + off + 4);
(reinterpret_cast<intptr_t>(trampolineAlloc) + off + 4);
if (newDisp < INT32_MIN || newDisp > INT32_MAX) { if (newDisp < INT32_MIN || newDisp > INT32_MAX) {
FreeExec(trampolineAlloc, allocSize); FreeExec(trampolineAlloc, allocSize);
return RadHookResult::TrampolineTooFar; return RadHookResult::TrampolineTooFar;
@@ -505,8 +506,12 @@ RadHookResult InstallHook(RadHookOpaque* h, void* target, void* detour) {
uint8_t* jumpBack = reinterpret_cast<uint8_t*>(trampolineAlloc) + stolenLen; uint8_t* jumpBack = reinterpret_cast<uint8_t*>(trampolineAlloc) + stolenLen;
uintptr_t backAddr = reinterpret_cast<uintptr_t>(target) + 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); std::memcpy(jumpBack + 6, &backAddr, 8);
FlushICache(trampolineAlloc, allocSize); FlushICache(trampolineAlloc, allocSize);
@@ -521,8 +526,13 @@ RadHookResult InstallHook(RadHookOpaque* h, void* target, void* detour) {
h->originalLength = stolenLen; h->originalLength = stolenLen;
uint8_t hookStub[kX64StubLen]; 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); uintptr_t detourAddr = reinterpret_cast<uintptr_t>(detour);
std::memcpy(hookStub + 6, &detourAddr, 8); std::memcpy(hookStub + 6, &detourAddr, 8);
std::memcpy(h->stubBytes, hookStub, kX64StubLen); std::memcpy(h->stubBytes, hookStub, kX64StubLen);