枚举一个函数里的所有调用

//枚举一个函数里的所有调用
//
#include <idc.idc>
static main()
{
	auto func,end,target,inst,name,flags,xref;
	flags = SEARCH_DOWN | SEARCH_NEXT;
	func = GetFunctionAttr(ScreenEA(),FUNCATTR_START);
	if(func != -1)
	{
		name = Name(func);
		end = GetFunctionAttr(func,FUNCATTR_END);
		for(inst = func; inst < end; inst = FindCode(inst,flags))
		{
			for(target = Rfirst(inst) ; target != BADADDR; target = Rnext(inst,target))	//Rfirst取得第一个对它的代码的调用
			{
				xref = XrefType();	//这个程序中只是对调用其它函数的交叉引用感兴趣,所以只关注fl_CN和fl_CF类型的交叉引用
				if(xref == fl_CN || xref == fl_CF)
				{
					Message("%s calls %s from 0x%x\n",name,Name(target),inst);
				}
			}
		}
	}
	else
	{
		Warning("No function found at location %x",ScreenEA());
	}
}

结果如下:

  

posted @ 2014-08-21 09:25  M-先生  阅读(691)  评论(1编辑  收藏  举报