![]() |
|
![]() 高级会员
|
dreaman这段代码写的不错,我给改了几句,让生成的代码有跳转地址,对于改写可以减少工作。但那个":"号还是有点问题,到处乱加,哈哈,我对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,name; 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++; } } if ((name=GetTrueNameEx(i,i)) != 0) if (LocByName(name) == start) Message("%s\r\n",name); else Message("%s:\r\n",name); i=ItemEnd(i);/*FindCode(i,1);*/ Message(form(" %s\r\n",ins)); } return size; } static main() { auto arrayid,size,pos,st,name; 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)); if ((name=GetType(st)) != 0) Message("%s\r\n",GetType(st)); size=GenFuncIns(st,arrayid,size); Message("\r\n"); } DeleteArray(arrayid); }
|
||
|
![]() 初级会员
|
哈哈 我也修改了一下 这样可以写到文件里了 而且对于错误的call也能辨认 #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,funcend; 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,file,funcend; st=ScreenEA(); file=fopen("c:\Get.asm","a+"); 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)); funcend=FindFuncEnd(st); if (funcend!=BADADDR) { Message("正在将这个函数代码写入c:\Get.asm中...\r\n"); GenerateFile(OFILE_ASM,file, st,funcend, 0); } else { Message(form("proc:%8.8x Write false\r\n",st)); } size=GenFuncIns(st,arrayid,size); } DeleteArray(arrayid); Message("All done, exiting...\n"); }
|
||
|
![]() 高级会员
|
再改写一下,见笑了。 生成的文件放在c盘的根目录不好,所以改到当前打开的 idb 文件目录下,文件名由 idb 的文件名加上 Part 组成。 代码:
#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,funcend;
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,file,funcend,path;
st=ScreenEA();
path = GetIdbPath();
path = substr(path, 0, strlen(path) - 4) + "Part.asm";
file=fopen(path,"w+");
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));
funcend=FindFuncEnd(st);
if (funcend!=BADADDR)
{
Message("正在将这个函数代码写入 %s \n",path);
GenerateFile(OFILE_ASM,file, st,funcend, 0);
}
else
{
Message(form("proc:%8.8x Write false\r\n",st));
}
size=GenFuncIns(st,arrayid,size);
}
DeleteArray(arrayid);
fclose(file);
Message("All done, exiting...\n");
}
|
||
|