static refs(start)
{
auto func,end,target,inst,name,flags,xref,s,output;
flags
=
SEARCH_DOWN | SEARCH_NEXT;
output
=
"";
func
=
GetFunctionAttr(start,FUNCATTR_START);
if
(func !
=
-
1
)
{
name
=
Name(func);
end
=
GetFunctionAttr(func,FUNCATTR_END);
for
(inst
=
func; (inst < end)&&(inst !
=
BADADDR) ; inst
=
FindCode(inst,flags))
{
for
(target
=
Rfirst(inst);target !
=
BADADDR; target
=
Rnext(inst,target))
{
xref
=
XrefType();
if
(xref
=
=
fl_CN || xref
=
=
fl_CF)
{
s
=
sprintf(
"%s call -> %s from --> %x \n"
,name,Name(target),inst);
output
=
sprintf(
"%s%s"
,output,s);
}
}
}
}
return
output;
}
static main()
{
auto addr,
file
, start,end, args,
locals
, frame, firstArg, name, ret,s1,s2,s3,s4,output;
addr
=
0
;
for
(addr
=
NextFunction(addr); addr !
=
BADADDR; addr
=
NextFunction(addr))
{
name
=
Name(addr);
start
=
GetFunctionAttr(addr, FUNCATTR_START);
end
=
GetFunctionAttr(addr, FUNCATTR_END);
locals
=
GetFunctionAttr(addr, FUNCATTR_FRSIZE);
frame
=
GetFrame(addr);
/
/
retrieve a handle to the function’s stack frame
ret
=
GetMemberOffset(frame,
" r"
);
/
/
" r"
is
the name of the
return
address
if
(ret
=
=
-
1
)
continue
;
firstArg
=
ret
+
4
;
args
=
GetStrucSize(frame)
-
firstArg;
s1
=
sprintf(
"Function: %s, starts at %x, ends at %x\n"
, name, addr, end);
s2
=
sprintf(
" Local variable area is %d bytes\n"
,
locals
);
s3
=
sprintf(
" Arguments occupy %d bytes (%d args)\n"
, args, args
/
4
);
s4
=
refs(start);
output
=
sprintf(
"%s%s%s%s%s"
,output,s1,s2,s3,s4);
}
file
=
fopen(
"output.txt"
,
"wt+"
);
writestr(
file
,output);
fclose(
file
);
qexit(
0
);
}