Log mappin slot RVAs
This commit is contained in:
@@ -180,17 +180,70 @@ void LogRed4ext(std::string_view aMessage)
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t GetImageBase()
|
||||
{
|
||||
return reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr));
|
||||
}
|
||||
|
||||
uintptr_t GetImageEnd()
|
||||
{
|
||||
const auto imageBase = GetImageBase();
|
||||
if (!imageBase)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(imageBase);
|
||||
if (dos->e_magic != IMAGE_DOS_SIGNATURE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto* nt = reinterpret_cast<const IMAGE_NT_HEADERS*>(imageBase + dos->e_lfanew);
|
||||
if (nt->Signature != IMAGE_NT_SIGNATURE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return imageBase + nt->OptionalHeader.SizeOfImage;
|
||||
}
|
||||
|
||||
bool IsInImage(const void* aPointer)
|
||||
{
|
||||
const auto imageBase = GetImageBase();
|
||||
const auto imageEnd = GetImageEnd();
|
||||
const auto address = reinterpret_cast<uintptr_t>(aPointer);
|
||||
return imageBase && imageEnd && address >= imageBase && address < imageEnd;
|
||||
}
|
||||
|
||||
void AppendPointerWithRva(std::ostringstream& aLine, const char* aLabel, const void* aPointer)
|
||||
{
|
||||
aLine << " " << aLabel << "=" << aPointer;
|
||||
|
||||
if (IsInImage(aPointer))
|
||||
{
|
||||
const auto imageBase = GetImageBase();
|
||||
const auto address = reinterpret_cast<uintptr_t>(aPointer);
|
||||
aLine << " " << aLabel << "_rva=0x" << std::hex << (address - imageBase) << std::dec;
|
||||
}
|
||||
}
|
||||
|
||||
void AppendReturnRva(std::ostringstream& aLine, const void* aReturnAddress)
|
||||
{
|
||||
if (IsInImage(aReturnAddress))
|
||||
{
|
||||
const auto imageBase = GetImageBase();
|
||||
const auto address = reinterpret_cast<uintptr_t>(aReturnAddress);
|
||||
aLine << " ret_rva=0x" << std::hex << (address - imageBase) << std::dec;
|
||||
}
|
||||
}
|
||||
|
||||
void LogHookCall(const char* aName, uint32_t aCount, void* aThis, void* a2, void* a3, void* a4)
|
||||
{
|
||||
const auto imageBase = reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr));
|
||||
const auto ret = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
std::ostringstream line;
|
||||
line << "hook " << aName << " call=" << aCount << " this=" << aThis << " a2=" << a2 << " a3=" << a3
|
||||
<< " a4=" << a4;
|
||||
if (ret && imageBase && ret >= imageBase)
|
||||
{
|
||||
line << " ret_rva=0x" << std::hex << (ret - imageBase) << std::dec;
|
||||
}
|
||||
AppendReturnRva(line, __builtin_return_address(0));
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
@@ -222,10 +275,15 @@ void LogMappinSystemSlots(uint32_t aCount, void* aSystem, void* aVtable)
|
||||
};
|
||||
|
||||
std::ostringstream line;
|
||||
line << "mappin-system slots call=" << aCount << " system=" << aSystem << " vtable=" << aVtable
|
||||
<< " slot220=" << readSlot(0x220) << " slot228=" << readSlot(0x228)
|
||||
<< " slot250=" << readSlot(0x250) << " slot2e0=" << readSlot(0x2E0)
|
||||
<< " slot368=" << readSlot(0x368) << " slot3a8=" << readSlot(0x3A8);
|
||||
line << "mappin-system slots call=" << aCount;
|
||||
AppendPointerWithRva(line, "system", aSystem);
|
||||
AppendPointerWithRva(line, "vtable", aVtable);
|
||||
AppendPointerWithRva(line, "slot220", readSlot(0x220));
|
||||
AppendPointerWithRva(line, "slot228", readSlot(0x228));
|
||||
AppendPointerWithRva(line, "slot250", readSlot(0x250));
|
||||
AppendPointerWithRva(line, "slot2e0", readSlot(0x2E0));
|
||||
AppendPointerWithRva(line, "slot368", readSlot(0x368));
|
||||
AppendPointerWithRva(line, "slot3a8", readSlot(0x3A8));
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
@@ -453,8 +511,10 @@ void DetourMappinSetTracked(void* aSystem, void* aMappinId)
|
||||
if (gMappinSetTrackedLogCount < 64)
|
||||
{
|
||||
std::ostringstream line;
|
||||
line << "hook MappinSystem::SetTracked slot220 call=" << gMappinSetTrackedLogCount
|
||||
<< " system=" << aSystem << " mappinId=" << aMappinId;
|
||||
line << "hook MappinSystem::SetTracked slot220 call=" << gMappinSetTrackedLogCount;
|
||||
AppendPointerWithRva(line, "system", aSystem);
|
||||
AppendPointerWithRva(line, "mappinId", aMappinId);
|
||||
AppendReturnRva(line, __builtin_return_address(0));
|
||||
LogRed4ext(line.str());
|
||||
++gMappinSetTrackedLogCount;
|
||||
}
|
||||
@@ -470,8 +530,9 @@ void DetourMappinClearTracked(void* aSystem)
|
||||
if (gMappinClearTrackedLogCount < 64)
|
||||
{
|
||||
std::ostringstream line;
|
||||
line << "hook MappinSystem::ClearTracked slot228 call=" << gMappinClearTrackedLogCount
|
||||
<< " system=" << aSystem;
|
||||
line << "hook MappinSystem::ClearTracked slot228 call=" << gMappinClearTrackedLogCount;
|
||||
AppendPointerWithRva(line, "system", aSystem);
|
||||
AppendReturnRva(line, __builtin_return_address(0));
|
||||
LogRed4ext(line.str());
|
||||
++gMappinClearTrackedLogCount;
|
||||
}
|
||||
@@ -490,7 +551,7 @@ void AttachProbeHook(const char* aName, uintptr_t aRva, void* aDetour, void** aO
|
||||
return;
|
||||
}
|
||||
|
||||
auto* target = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr)) + aRva);
|
||||
auto* target = reinterpret_cast<void*>(GetImageBase() + aRva);
|
||||
const auto attached = gSdk->hooking->Attach(gHandle, target, aDetour, aOriginal);
|
||||
|
||||
std::ostringstream line;
|
||||
@@ -518,8 +579,10 @@ void AttachAbsoluteHook(const char* aName, void* aTarget, void* aDetour, void**
|
||||
const auto attached = gSdk->hooking->Attach(gHandle, aTarget, aDetour, aOriginal);
|
||||
|
||||
std::ostringstream line;
|
||||
line << "absolute hook attach " << aName << " target=" << aTarget
|
||||
<< " result=" << (attached ? "ok" : "failed") << " original=" << (aOriginal ? *aOriginal : nullptr);
|
||||
line << "absolute hook attach " << aName;
|
||||
AppendPointerWithRva(line, "target", aTarget);
|
||||
line << " result=" << (attached ? "ok" : "failed");
|
||||
AppendPointerWithRva(line, "original", aOriginal ? *aOriginal : nullptr);
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
@@ -530,7 +593,7 @@ void DetachProbeHook(const char* aName, uintptr_t aRva)
|
||||
return;
|
||||
}
|
||||
|
||||
auto* target = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr)) + aRva);
|
||||
auto* target = reinterpret_cast<void*>(GetImageBase() + aRva);
|
||||
const auto detached = gSdk->hooking->Detach(gHandle, target);
|
||||
|
||||
std::ostringstream line;
|
||||
@@ -548,15 +611,15 @@ void DetachAbsoluteHook(const char* aName, void* aTarget)
|
||||
const auto detached = gSdk->hooking->Detach(gHandle, aTarget);
|
||||
|
||||
std::ostringstream line;
|
||||
line << "absolute hook detach " << aName << " target=" << aTarget
|
||||
<< " result=" << (detached ? "ok" : "failed");
|
||||
line << "absolute hook detach " << aName;
|
||||
AppendPointerWithRva(line, "target", aTarget);
|
||||
line << " result=" << (detached ? "ok" : "failed");
|
||||
LogRed4ext(line.str());
|
||||
}
|
||||
|
||||
void InspectAndHookMappinSystem(void* aThis)
|
||||
{
|
||||
auto* resolver = reinterpret_cast<MappinSystemResolverFunc>(
|
||||
reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr)) + kMappinSystemResolverRva);
|
||||
auto* resolver = reinterpret_cast<MappinSystemResolverFunc>(GetImageBase() + kMappinSystemResolverRva);
|
||||
void* system = resolver ? resolver(aThis) : nullptr;
|
||||
auto* vtable = system ? *reinterpret_cast<void***>(system) : nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user