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

  1.  
  2. // by mammon_ / the_owl / slava
  3.  
  4. #include <idc.idc>
  5.  
  6. static OutputLine(ea, x, nest, OutFileH){
  7.     auto j;
  8.     for ( j = 0; j <= nest; j = j + 1) {
  9.         fprintf(OutFileH, "   ");
  10.     }
  11.     fprintf(OutFileH, atoa(ea) + "  ->  " + Name(x) + " : " + atoa(x) + "\n");
  12. }
  13.  
  14. static GetXrefs(ea, nest, OutFileH){
  15.     auto x, f_end;
  16.     x = Rfirst0(ea);
  17.     if (x != BADADDR) {
  18.         OutputLine(ea, x, nest, OutFileH);
  19.     }
  20. }
  21.  
  22. static TravelFunc(ea, nest, MaxNest , ArrayID, OutFileH) {
  23.    auto x, f_end, type, counter;
  24.    if (nest >= xtol(MaxNest)-1)
  25.       return;
  26.  
  27.    f_end = FindFuncEnd(ea);  // note that FindFuncEnd returns the address of (FunctionEnd+1)
  28.    for (ea; ea < f_end; ea=NextAddr(ea)) {
  29.       x = Rfirst0(ea);
  30.       if (x != BADADDR) {
  31.          type = XrefType();
  32.          if (type == fl_CF || type == fl_CN) {
  33.  
  34.             for(counter = 0; counter <= GetLastIndex(AR_STR,ArrayID); counter = counter+1){ //go through array    
  35.         if (Name(x) == GetArrayElement(AR_STR,ArrayID,counter)){  // do we have this name stored in array?
  36.             OutputLine(ea, x, nest+1, OutFileH);  //out fuction call
  37.             fprintf(OutFileH, "***** RECURSIVE CALL OF FUNCTION   %s *****\n", Name(x)); //out warning
  38.             DelArrayElement(AR_STR,ArrayID,nest+1); // going up, so let's adjust our array.
  39.             return; // hmm.. we may still need some space on our h/d, so let's get out of here right now...
  40.         }
  41.             }
  42.  
  43.             OutputLine(ea, x, nest+1, OutFileH);
  44.         SetArrayString(ArrayID,nest+1,Name(x));  // no such a function in array, so add it
  45.             TravelFunc(x, nest+1, MaxNest, ArrayID, OutFileH); // let's dig deeper
  46.         DelArrayElement(AR_STR,ArrayID,nest+1); //it's ok to call a func multiple times from the same level
  47.          }
  48.       }
  49.    }
  50.    DelArrayElement(AR_STR,ArrayID,nest+1); // going up, so let's adjust our array.
  51. }
  52.  
  53. static main(){
  54.     auto ea, x, i, nest, f_end, EPOrd, OutFileH, OutFName, MaxNest, ArrayID;
  55.  
  56. ArrayID =  CreateArray("RecurFuncNames");  //create array for our recursive calls
  57. if (ArrayID == -1){
  58.     Warning("Can't create array RecurFuncNames"); //hmm... 
  59.     ArrayID = GetArrayId("RecurFuncNames");  //let's see if we already have an array with this name
  60.     DeleteArray(ArrayID);            //if it's there, it's most probably because we abnormaly 
  61.                         //terminated this script without removing the  array from 
  62.                         //the database at the end of main(), so let's try to do it now.
  63.     ArrayID =  CreateArray("RecurFuncNames"); //try to create it again
  64.     if (ArrayID == -1){
  65.         Warning("Still can't create array RecurFuncNames, exiting"); //damn, still doesn't work, so exit
  66.         return;
  67.     }
  68. }
  69.  
  70.     nest = -1;
  71.     MaxNest = AskStr( "10", "Enter max number of levels");
  72.     OutFName = AskStr("FuncTree.txt", "Enter output filename: ");
  73.     OutFileH = fopen(OutFName, "wt");
  74.         ea = ChooseFunction("select a function to parse");
  75.         f_end = FindFuncEnd(ea);
  76.         fprintf(OutFileH, "*** Code references from " + GetFunctionName(ea) + " : " + atoa(ea) + "\n");
  77.         TravelFunc(ea, nest, MaxNest, ArrayID, OutFileH); // shit.. no globals??. let's pass all this crap then. 
  78.     fclose (OutFileH);
  79.     Message("End of output. \n");
  80. DeleteArray(ArrayID);
  81. }
  82.  
  83.