将下面内容保存到一个文本文件,然后用idapro的装入idc文件执行它,执行前先将光标定位在要生成代码的过程上.
#include "idc.idc"
static ElementExist(arrayid,size,val)
{
auto i,v;
for(i=0;i<size;i++)
{
v=GetArrayElement(AR_LONG,arrayid,i);
if(v==val)
return 1;
}
return 0;
}
static GenFuncIns(st,arrayid,size)
{
auto start,end,i,ins,x,xt;
start=st;
end=FindFuncEnd(start);
for(i=start;i<end;)
{
ins=GetDisasm(i);
for(x=Rfirst(i);x!=BADADDR;x=Rnext(i,x))
{
xt=XrefType();
if(xt == fl_CN && !ElementExist(arrayid,size,x))
{
SetArrayLong(arrayid,size,x);
size++;
}
}
i=ItemEnd(i);/*FindCode(i,1);*/
Message(form("%s\r\n",ins));
}
return size;
}
static main()
{
auto arrayid,size,pos,st;
st=ScreenEA();
if(st==BADADDR)
{
Warning("您需要选中一个函数起始地址!");
return;
}
arrayid=CreateArray("gen_func_ins");
if(arrayid<0)
{
arrayid=GetArrayId("gen_func_ins");
}
pos=0;
SetArrayLong(arrayid,pos,st);
size=1;
for(pos=0;pos<size;pos++)
{
st=GetArrayElement(AR_LONG,arrayid,pos);
Message(form("proc:%8.8x\r\n",st));
size=GenFuncIns(st,arrayid,size);
Message("\r\n");
}
DeleteArray(arrayid);
}
这是dreaman写的,原贴地址
http://bbs.pediy.com/showthread.php?t=23231
[课程]Linux pwn 探索篇!