Advertisement
Guest User

IDC Tatanga Function Renaming

a guest
Aug 14th, 2012
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. //
  2. // Auto rename Tatanga/Gataka names
  3. //
  4.  
  5. #include <idc.idc>
  6.  
  7.  
  8. static main() {
  9. auto FunctionStart, FunctionEnd, curr, FunctionName;
  10. auto s, fc;
  11.  
  12. for (FunctionStart=NextFunction(0); FunctionStart != BADADDR; FunctionStart=NextFunction(FunctionStart) )
  13. {
  14. FunctionEnd = GetFunctionAttr(FunctionStart, FUNCATTR_END);
  15. for(curr = FunctionStart; curr <= FunctionEnd; curr = curr + ItemSize(curr))
  16. {
  17. // Filter pushes
  18. if(GetMnem(curr) != "push" || ItemSize(curr) != 5)
  19. continue;
  20. // Only ASCII strings
  21. if(GetStringType(GetOperandValue(curr, 0)) != 0)
  22. continue;
  23.  
  24. s = GetString(GetOperandValue(curr, 0), -1, 0);
  25.  
  26. // Filter filename (check for drive)
  27. if(substr(s, 1, 2) == ":")
  28. continue;
  29. fc = substr(s, 0, 1);
  30. // Filter to valid first char for function name
  31. if(!(fc >= "a" && fc <= "z") && !(fc >= "A" && fc <= "Z"))
  32. continue;
  33.  
  34. FunctionName = GetFunctionNameXXXX(s);
  35. if(FunctionName == "")
  36. continue;
  37.  
  38. if(AskYN(0, FunctionName) == 1)
  39. {
  40. RenameFunc(FunctionStart, FunctionName);
  41. break;
  42. }
  43. }
  44. }
  45. }
  46.  
  47. static GetFunctionNameXXXX(unprocessed_name)
  48. {
  49. auto name, i, curr;
  50. auto ValidName;
  51.  
  52. i = 0;
  53. while(i < strlen(unprocessed_name))
  54. {
  55. curr = substr(unprocessed_name, i, i+1);
  56.  
  57. // Invalid char in func name
  58. if(!(curr >= "a" && curr <= "z") && !(curr >= "A" && curr <= "Z") && !(curr >= "0" && curr <= "9") && curr != ":")
  59. {
  60. return "";
  61. }
  62.  
  63. // end of name
  64. if(curr == ":" && substr(unprocessed_name, i+1, i+2) == " ")
  65. {
  66. return name;
  67. }
  68.  
  69. // append
  70. i++;
  71. name = substr(unprocessed_name, 0, i);
  72. // skip second ":" of class
  73. if(curr == ":" && substr(unprocessed_name, i, i+1) == ":")
  74. i++;
  75. }
  76. return "";
  77. }
  78.  
  79. // 1 = Success, 0 = Failure
  80. static RenameFunc( dwAddress, sFunction )
  81. {
  82. auto dwRet;
  83.  
  84. dwRet = MakeNameEx( dwAddress, sFunction, SN_NOCHECK );
  85.  
  86. if( dwRet == 0 )
  87. {
  88. auto sTemp, i;
  89. for( i = 0; i < 32; i++ )
  90. {
  91. sTemp = form( "%s_%i", sFunction, i );
  92.  
  93. if( ( dwRet = MakeNameEx( dwAddress, sTemp, SN_NOCHECK ) ) != 0 )
  94. {
  95. Message( "Info: Renamed to %s instead of %s\n", sTemp, sFunction );
  96. break;
  97. }
  98. }
  99. }
  100. return dwRet;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement