识别在LLVM-IR级别写入内存的函数

时间:2014-05-28 23:02:19

标签: llvm-clang llvm-ir

如何检索指向函数调用访问的内存区域的指针。 我编写了一个Pass,它可以拦截函数调用并检测它是否在不使用Instruction::mayWriteToMemory()的情况下写入内存。是否可以检查访问内存的功能 Instruction::mayReadFromMemory()Instruction::mayWriteToMemory()但是我怎样才能得到正在写入的那些内存区域(程序变量)的地址。

例如,对于c代码

int main(){
char arrd[]="This is destination ";
char arrs[]="COPIED STRING";
strcpy(arrd, arrs);
printf("Final copied string : %s\n", arrd);
return 0;
}

我想得到 strcpy 函数写入的内存区域(变量)的凝视地址和结束地址。

为此生成的LLVM-IR代码是

%arrd = alloca [21 x i8], align 16
%arrs = alloca [14 x i8], align 1
%0 = bitcast [21 x i8]* %arrd to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* getelementptr inbounds ([21 x i8]*       @main.arrd, i32 0, i32 0), i64 21, i32 16, i1 false)
%1 = bitcast [14 x i8]* %arrs to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* getelementptr inbounds ([14 x i8]* @main.arrs, i32 0, i32 0), i64 14, i32 1, i1 false) 
%arraydecay = getelementptr inbounds [21 x i8]* %arrd, i32 0, i32 0
%arraydecay1 = getelementptr inbounds [14 x i8]* %arrs, i32 0, i32 0
%call = call i8* @strcpy(i8* %arraydecay, i8* %arraydecay1) #1
%arraydecay2 = getelementptr inbounds [21 x i8]* %arrd, i32 0, i32 0
%call3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([26 x i8]* @.str, i32  0, i32 0), i8* %arraydecay2) 
ret i32 0 

0 个答案:

没有答案
相关问题