home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mammon_ / func_tree.idc < prev    next >
Text File  |  2000-05-25  |  2KB  |  50 lines

  1.  
  2. //func_tree.idc
  3. //This script will prompt the user for a function name, then will output all of the calls
  4. //made by that function...it will travel recursively into each call, up to 25 "levels" deep,
  5. //to determine what calls are made by each routine called by the main function.
  6. //This script is part of an attempt to give IDA some code-abstracton functionality. Its
  7. //main purpose is to show what subroutines and API routines are called by a user-determined
  8. //function. The output is printed in the IDA message window.
  9.  
  10.  
  11. #include <idc.idc>    //provides IDC function prototypes
  12.  
  13. static OutputXref(ea, x, nest)   //Prints Calls to the Message Window
  14. {
  15.     auto j;
  16.     for ( j; j <= nest; j = j + 1) {   //nesting routine: indents two spaces for every
  17.         Message("  ");                 //level of recursion
  18.     }
  19.     Message( atoa(ea) + " refers to " + Name(x) + "\n");  //outputs a code address and what routine
  20. }                                                         //that address calls
  21.  
  22. static GetXrefs(ea, nest)    //recursively travels though the program, outputting each
  23. {                            //call it finds via OutputXref()
  24.     auto x, t, f_end;
  25.     nest = nest + 1;         //determine level of indentation for the output of calls
  26.     f_end = FindFuncEnd(ea); //made by this function
  27.     for ( ea; ea <= f_end; ea = NextAddr(ea) ) { //For each Address in this function/routine
  28.         x = Rfirst0(ea);                        //Get Xref for this address
  29.         if ( x != BADADDR && nest < 25 ) {      //While there is an Xref
  30.             t = XrefType();                      //Get what type of Xref this is (jmp, call, etc)
  31.             if ( (t == fl_CF) || (t == fl_CN)) { //Output & recurse only if a call
  32.                 OutputXref (ea, x, nest);
  33.                 GetXrefs(x, nest);  //call GetXrefs to get that calls made by this called routine
  34.             }                       //(Recursion)
  35.         }
  36.     }
  37.     nest = nest - 1;                //undo indentation before exiting this function/routine
  38. }
  39.  
  40. static main()
  41. {
  42.     auto ea, nest;
  43.     nest = 0;
  44.     ea = ChooseFunction("Select a function to parse:");  //ask user for function name
  45.     GetXrefs(ea, nest);                                  //Bulk of program
  46.     Message("End of output.\n");
  47. }
  48.  
  49.  
  50.