Improve hook reliability - fixes GMalloc nullptr and proper alloc size

This commit is contained in:
AeonLucid
2021-10-30 23:31:56 +02:00
parent 341c8de5ba
commit afb082ee88
3 changed files with 15 additions and 10 deletions
+12 -4
View File
@@ -48,13 +48,21 @@ namespace SDK
{
FString(const wchar_t* other)
{
Max = Count = *other ? std::wcslen(other) + 1 : 0;
const size_t charLen = std::wcslen(other);
if (Count)
if (charLen == 0)
{
Data = static_cast<wchar_t*>(GMalloc->Malloc(Count));
Count = 0;
Max = 0;
Data = nullptr;
}
else
{
Count = charLen + 1;
Max = Count;
Data = static_cast<wchar_t*>((*GMalloc)->Malloc(Count * 2));
wcscpy_s(Data, Count, other);
memcpy(Data, other, charLen * 2);
}
}
+1 -1
View File
@@ -75,5 +75,5 @@ namespace SDK
virtual const TCHAR* GetDescriptiveName() = 0;
};
FMalloc* GMalloc;
FMalloc** GMalloc;
}
+1 -4
View File
@@ -38,10 +38,7 @@ DWORD WINAPI OnDllAttach(LPVOID base)
const auto hModulePtr = reinterpret_cast<uintptr_t>(hModule);
// Initialize GMalloc.
do
{
SDK::GMalloc = *reinterpret_cast<SDK::FMalloc**>(hModulePtr + OffsetGMalloc);
} while (SDK::GMalloc == nullptr);
SDK::GMalloc = reinterpret_cast<SDK::FMalloc**>(hModulePtr + OffsetGMalloc);
// Initialize MinHook.
if (MH_Initialize() != MH_OK)