如何检查 LLVM StoreInst 的目标是否为函数指针
How to check if a target of an LLVM StoreInst is a function pointer
如何检查 LLVM StoreInst
的存储目标是否为函数指针?
给定一个 LLVM 加载/存储指令,有两个单独的部分需要计算。首先,位置的类型是什么。其次,类型是否满足某些属性等。
if (StoreInst *si = dyn_cast<StoreInst>(&*I))
{
Value* v = si->getPointerOperand();
Type* ptrType = v->getType()->getPointerElementType();
现在,指针类型就是存储数据的类型。但是我们想知道底层类型是否实际上是一个函数,从而使它成为一个函数指针(或指针指针等)。
if (PointerType* pt = dyn_cast<PointerType>(ptrType))
{
do {
// The call to getTypeAtIndex has to be made on a composite type
// And needs explicitly an unsigned int, otherwise 0
// can ambiguously be NULL.
Type* pointedType = pt->getTypeAtIndex((unsigned int)0);
if (pointedType->isFunctionTy())
{
errs() << "Found the underlying function type\n";
break;
}
// This may be a pointer to a pointer to ...
ptrType = pointedType;
} while (pt = dyn_cast<PointerType>(ptrType));
此代码检测到以下存储 - store i8* (i8*)* @tFunc, i8* (i8*)** %8, align 8
,它将指向函数 tFunc 的指针存储到另一个位置。
如何检查 LLVM StoreInst
的存储目标是否为函数指针?
给定一个 LLVM 加载/存储指令,有两个单独的部分需要计算。首先,位置的类型是什么。其次,类型是否满足某些属性等。
if (StoreInst *si = dyn_cast<StoreInst>(&*I))
{
Value* v = si->getPointerOperand();
Type* ptrType = v->getType()->getPointerElementType();
现在,指针类型就是存储数据的类型。但是我们想知道底层类型是否实际上是一个函数,从而使它成为一个函数指针(或指针指针等)。
if (PointerType* pt = dyn_cast<PointerType>(ptrType))
{
do {
// The call to getTypeAtIndex has to be made on a composite type
// And needs explicitly an unsigned int, otherwise 0
// can ambiguously be NULL.
Type* pointedType = pt->getTypeAtIndex((unsigned int)0);
if (pointedType->isFunctionTy())
{
errs() << "Found the underlying function type\n";
break;
}
// This may be a pointer to a pointer to ...
ptrType = pointedType;
} while (pt = dyn_cast<PointerType>(ptrType));
此代码检测到以下存储 - store i8* (i8*)* @tFunc, i8* (i8*)** %8, align 8
,它将指向函数 tFunc 的指针存储到另一个位置。