fix: sync with qt5platform-plugins

623ce74a8c

Log: 同步qt5platform-plugins
This commit is contained in:
heyuming 2023-03-27 16:29:05 +08:00 committed by zccrs
parent 4c6390cd5b
commit fb4845350a
2 changed files with 2 additions and 26 deletions

View File

@ -182,14 +182,7 @@ public:
if (fun1_offset > UINT_LEAST16_MAX)
return false;
if (!isFinalClass(vfptr_t1)) {
vfptr_t1 = (quintptr *)adjustThis(vfptr_t1);
if (!vfptr_t1) {
qCWarning(vtableHook) << "The type of target object isn't the last item of inheritance chain and can't adjust pointer "
"'This' to correct address, abort. " << vfptr_t1;
return false;
}
}
quintptr *vfun = vfptr_t1 + fun1_offset / sizeof(quintptr);
if (forceWrite)
@ -334,8 +327,6 @@ public:
private:
static bool copyVtable(quintptr **obj);
static bool clearGhostVtable(const void *obj);
static bool isFinalClass(quintptr *obj);
static quintptr **adjustThis(quintptr *obj);
template <typename T>
static T adjustToTop(T obj) // vtableTop: vtable start address, Usually refers to offset_to_top

View File

@ -283,9 +283,7 @@ quintptr DVtableHook::originalFun(const void *obj, quintptr functionOffset)
qCWarning(vtableHook) << "Not override the object virtual table: " << obj;
return 0;
}
if (!isFinalClass((quintptr *)*_obj))
_obj = adjustThis((quintptr *)*_obj); // adjust to correct position
Q_CHECK_PTR(_obj);
int vtable_size = getVtableSize(_obj);
// 获取obj对象原本虚表的入口
quintptr *vfptr_t2 = (quintptr*)(*_obj)[vtable_size - 1];
@ -298,19 +296,6 @@ quintptr DVtableHook::originalFun(const void *obj, quintptr functionOffset)
return *(vfptr_t2 + functionOffset / sizeof(quintptr));
}
bool DVtableHook::isFinalClass(quintptr *obj)
{
return *(obj - 2) == 0 ? true : false; // adjust pointer from Vtable Entry to Vtable start address, there are offset_to_top and rtti pointer.
}
quintptr **DVtableHook::adjustThis(quintptr *obj)
{
qint64 offset = *(quintptr*)(obj - 2);
if (offset > 0) // invalid offset
return nullptr;
return (quintptr **)(obj + offset); // if obj isn't the last item in the inheritance chain, we should adjust pointer 'This' manually.
}
#if defined(Q_OS_LINUX)
static int readProtFromPsm(quintptr adr, size_t length)
{