From 906dd61092f53f09092dacd7ed3f7772f507cce3 Mon Sep 17 00:00:00 2001 From: qubka Date: Fri, 11 Oct 2024 23:49:39 +0100 Subject: [PATCH] Replace uintptr_t by uint64_t --- src/callback.cpp | 36 ++++++++++++++++++------------------ src/callback.hpp | 18 +++++++++--------- src/plugin.cpp | 16 ++++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/callback.cpp b/src/callback.cpp index 7fa844d..3c3886d 100644 --- a/src/callback.cpp +++ b/src/callback.cpp @@ -41,7 +41,7 @@ asmjit::TypeId PLH::Callback::getTypeId(DataType type) { return asmjit::TypeId::kVoid; } -uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmjit::Arch arch, const CallbackEntry pre, const CallbackEntry post) { +uint64_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmjit::Arch arch, const CallbackEntry pre, const CallbackEntry post) { if (m_functionPtr) { return m_functionPtr; } @@ -110,7 +110,7 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj } // setup the stack structure to hold arguments for user callback - uint32_t stackSize = (uint32_t)(sizeof(uintptr_t) * sig.argCount()); + uint32_t stackSize = (uint32_t)(sizeof(uint64_t) * sig.argCount()); asmjit::x86::Mem argsStack = cc.newStack(stackSize, 16); asmjit::x86::Mem argsStackIdx(argsStack); @@ -120,8 +120,8 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj // stackIdx <- stack[i]. argsStackIdx.setIndex(i); - // r/w are sizeof(uintptr_t) width now - argsStackIdx.setSize(sizeof(uintptr_t)); + // r/w are sizeof(uint64_t) width now + argsStackIdx.setSize(sizeof(uint64_t)); // set i = 0 cc.mov(i, 0); @@ -139,8 +139,8 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj return 0; } - // next structure slot (+= sizeof(uintptr_t)) - cc.add(i, sizeof(uintptr_t)); + // next structure slot (+= sizeof(uint64_t)) + cc.add(i, sizeof(uint64_t)); } auto callbackSig = asmjit::FuncSignature::build(); @@ -154,18 +154,18 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj cc.lea(argStruct, argsStack); // create buffer for property struct - asmjit::x86::Mem propStack = cc.newStack(sizeof(uintptr_t), 16); + asmjit::x86::Mem propStack = cc.newStack(sizeof(uint64_t), 16); asmjit::x86::Gp propStruct = cc.newUIntPtr("propStruct"); cc.lea(propStruct, propStack); // create buffer for return struct - asmjit::x86::Mem retStack = cc.newStack(sizeof(uintptr_t), 16); + asmjit::x86::Mem retStack = cc.newStack(sizeof(uint64_t), 16); asmjit::x86::Gp retStruct = cc.newUIntPtr("retStruct"); cc.lea(retStruct, retStack); { asmjit::x86::Mem propStackIdx(propStack); - propStackIdx.setSize(sizeof(uintptr_t)); + propStackIdx.setSize(sizeof(uint64_t)); Property property{ (int32_t) sig.argCount(), ReturnFlag::Default }; cc.mov(propStackIdx, *(int64_t*) &property); } @@ -207,8 +207,8 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj return 0; } - // next structure slot (+= sizeof(uintptr_t)) - cc.add(i, sizeof(uintptr_t)); + // next structure slot (+= sizeof(uint64_t)) + cc.add(i, sizeof(uint64_t)); } // deref the trampoline ptr (holder must live longer, must be concrete reg since push later) @@ -232,7 +232,7 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj origInvokeNode->setRet(0, retRegister); asmjit::x86::Mem retStackIdx(retStack); - retStackIdx.setSize(sizeof(uintptr_t)); + retStackIdx.setSize(sizeof(uint64_t)); if (asmjit::TypeUtils::isInt(sig.ret())) { cc.mov(retStackIdx, retRegister.as()); } else { @@ -270,15 +270,15 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj return 0; } - // next structure slot (+= sizeof(uintptr_t)) - cc.add(i, sizeof(uintptr_t)); + // next structure slot (+= sizeof(uint64_t)) + cc.add(i, sizeof(uint64_t)); } cc.bind(noPost); if (sig.hasRet()) { asmjit::x86::Mem retStackIdx(retStack); - retStackIdx.setSize(sizeof(uintptr_t)); + retStackIdx.setSize(sizeof(uint64_t)); if (asmjit::TypeUtils::isInt(sig.ret())) { asmjit::x86::Gp tmp = cc.newUIntPtr(); cc.mov(tmp, retStackIdx); @@ -306,7 +306,7 @@ uintptr_t PLH::Callback::getJitFunc(const asmjit::FuncSignature& sig, const asmj return m_functionPtr; } -uintptr_t PLH::Callback::getJitFunc(const DataType retType, const std::vector& paramTypes, const CallbackEntry pre, const CallbackEntry post) { +uint64_t PLH::Callback::getJitFunc(const DataType retType, const std::vector& paramTypes, const CallbackEntry pre, const CallbackEntry post) { asmjit::FuncSignature sig(asmjit::CallConvId::kHost, asmjit::FuncSignature::kNoVarArgs, getTypeId(retType)); for (const DataType& type : paramTypes) { sig.addArg(getTypeId(type)); @@ -381,11 +381,11 @@ PLH::Callback::View PLH::Callback::getCallbacks(const CallbackType type) { return { m_callbacks[to_integral(type)], std::shared_lock(m_mutex) }; } -uintptr_t* PLH::Callback::getTrampolineHolder() { +uint64_t* PLH::Callback::getTrampolineHolder() { return &m_trampolinePtr; } -uintptr_t* PLH::Callback::getFunctionHolder() { +uint64_t* PLH::Callback::getFunctionHolder() { return &m_functionPtr; } diff --git a/src/callback.hpp b/src/callback.hpp index 1b5ad4c..4267d5d 100644 --- a/src/callback.hpp +++ b/src/callback.hpp @@ -66,12 +66,12 @@ namespace PLH { // asm depends on this specific type // we the ILCallback allocates stack space that is set to point here - volatile uintptr_t m_arguments; + volatile uint64_t m_arguments; private: // must be char* for aliasing rules to work when reading back out char* getArgPtr(const uint8_t idx) const { - return (char*) &m_arguments + sizeof(uintptr_t) * idx; + return (char*) &m_arguments + sizeof(uint64_t) * idx; } }; @@ -88,7 +88,7 @@ namespace PLH { uint8_t* getRetPtr() const { return (unsigned char*)&m_retVal; } - volatile uintptr_t m_retVal; + volatile uint64_t m_retVal; }; struct Property { @@ -104,11 +104,11 @@ namespace PLH { Callback(); ~Callback(); - uintptr_t getJitFunc(const asmjit::FuncSignature& sig, asmjit::Arch arch, CallbackEntry pre, CallbackEntry post); - uintptr_t getJitFunc(DataType retType, const std::vector& paramTypes, CallbackEntry pre, CallbackEntry post); + uint64_t getJitFunc(const asmjit::FuncSignature& sig, asmjit::Arch arch, CallbackEntry pre, CallbackEntry post); + uint64_t getJitFunc(DataType retType, const std::vector& paramTypes, CallbackEntry pre, CallbackEntry post); - uintptr_t* getTrampolineHolder(); - uintptr_t* getFunctionHolder(); + uint64_t* getTrampolineHolder(); + uint64_t* getFunctionHolder(); View getCallbacks(CallbackType type); std::string_view getError() const; @@ -123,9 +123,9 @@ namespace PLH { std::array, 2> m_callbacks; std::shared_mutex m_mutex; - uintptr_t m_functionPtr = 0; + uint64_t m_functionPtr = 0; union { - uintptr_t m_trampolinePtr = 0; + uint64_t m_trampolinePtr = 0; const char* m_errorCode; }; }; diff --git a/src/plugin.cpp b/src/plugin.cpp index 4bb5ebc..789ed76 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -63,9 +63,9 @@ Callback* PolyHookPlugin::hookDetour(void* pFunc, DataType returnType, const std return nullptr; } - uintptr_t JIT = callback->getJitFunc(returnType, arguments, &PreCallback, &PostCallback); + uint64_t JIT = callback->getJitFunc(returnType, arguments, &PreCallback, &PostCallback); - auto detour = std::make_unique((uintptr_t)pFunc, JIT, callback->getTrampolineHolder()); + auto detour = std::make_unique((uint64_t)pFunc, JIT, callback->getTrampolineHolder()); if (!detour->hook()) return nullptr; @@ -96,16 +96,16 @@ Callback* PolyHookPlugin::hookVirtual(void* pClass, int index, DataType returnTy return nullptr; } - uintptr_t JIT = callback->getJitFunc(returnType, arguments, &PreCallback, &PostCallback); + uint64_t JIT = callback->getJitFunc(returnType, arguments, &PreCallback, &PostCallback); auto& [redirectMap, origVFuncs] = m_tables[pClass]; redirectMap[index] = JIT; - auto vtable = std::make_unique((uintptr_t) pClass, redirectMap, &origVFuncs); + auto vtable = std::make_unique((uint64_t) pClass, redirectMap, &origVFuncs); if (!vtable->hook()) return nullptr; - uintptr_t origVFunc = origVFuncs[index]; + uint64_t origVFunc = origVFuncs[index]; *callback->getTrampolineHolder() = origVFunc; void* key = m_vhooks.emplace(pClass, std::move(vtable)).first->second.get(); @@ -158,7 +158,7 @@ bool PolyHookPlugin::unhookVirtual(void* pClass, int index) { return true; } - vtable = std::make_unique((uintptr_t) pClass, redirectMap, &origVFuncs); + vtable = std::make_unique((uint64_t) pClass, redirectMap, &origVFuncs); if (!vtable->hook()) return false; @@ -241,7 +241,7 @@ void* PolyHookPlugin::findOriginalAddr(void* pClass, void* pAddr) { int PolyHookPlugin::getVTableIndex(void* pFunc) const { constexpr size_t size = 12; - MemoryProtector protector((uintptr_t)pFunc, size, R, *(MemAccessor*)this); + MemoryProtector protector((uint64_t)pFunc, size, R, *(MemAccessor*)this); #if defined(__GNUC__) || defined(__clang__) struct GCC_MemFunPtr { @@ -299,7 +299,7 @@ int PolyHookPlugin::getVTableIndex(void* pFunc) const { // Check where it'd jump addr += 5 /*size of the instruction*/ + *(uint32_t*)(addr + 1); - protector = std::make_unique((uintptr_t)addr, size, R, *(MemAccessor*)this); + protector = std::make_unique((uint64_t)addr, size, R, *(MemAccessor*)this); } bool ok = false;