Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #include <idc.idc>
  2.  
  3. /************************************************************************
  4. Desc: Label each LUA scripts its appropriate name
  5. Author: kynox
  6. Credit: bobbysing for RenameFunc
  7. Website: http://www.gamedeception.net
  8. *************************************************************************/
  9.  
  10. // 1 = Success, 0 = Failure
  11. static RenameFunc( dwAddress, sFunction )
  12. {
  13. auto dwRet;
  14.  
  15. dwRet = MakeNameEx( dwAddress, sFunction, SN_NOWARN );
  16.  
  17. if( dwRet == 0 )
  18. {
  19. auto sTemp, i;
  20. for( i = 0; i < 32; i++ )
  21. {
  22. sTemp = form( "%s_%i", sFunction, i );
  23.  
  24. if( ( dwRet = MakeNameEx( dwAddress, sTemp, SN_NOWARN ) ) != 0 )
  25. {
  26. Message( "Info: Renamed to %s instead of %s\n", sTemp, sFunction );
  27. break;
  28. }
  29. }
  30. }
  31. return dwRet;
  32. }
  33.  
  34. static Luafunc_GetName( structAddr )
  35. {
  36. return GetString( Dword( structAddr ), -1, ASCSTR_C );
  37. }
  38.  
  39. static Luafunc_GetFunc( structAddr )
  40. {
  41. return Dword( structAddr + 4 );
  42. }
  43.  
  44. static HandleLuaFunc( structBase )
  45. {
  46. auto funcName, funcAddr;
  47. funcName = Luafunc_GetName( structBase );
  48. funcAddr = Luafunc_GetFunc( structBase );
  49.  
  50. RenameFunc( funcAddr, form( "Script_%s", funcName ) );
  51. }
  52.  
  53. static HandleLuaFuncWithClass( structBase, className )
  54. {
  55. auto funcName, funcAddr;
  56. funcName = Luafunc_GetName( structBase );
  57. funcAddr = Luafunc_GetFunc( structBase );
  58.  
  59. RenameFunc( funcAddr, form( "Script_%s_%s", className, funcName ) );
  60. }
  61.  
  62. static main()
  63. {
  64. // Normal func:
  65. auto registerFunc, xRef;
  66. registerFunc = FindBinary( 0, SEARCH_DOWN, "55 8B EC 56 8B 35 ? ? ? ? 6A ? FF 75 ? 56 E8 ? ? ? ? FF 75 ? 56 E8" );
  67.  
  68. if ( registerFunc == BADADDR )
  69. {
  70. Message( "LabelLuaFuncs: Error, couldn't find FrameScript_RegisterFunction.\n" );
  71. return;
  72. }
  73.  
  74. registerFunc = NextFunction(PrevFunction( registerFunc ));
  75.  
  76. for( xRef = RfirstB( registerFunc ); xRef != BADADDR; xRef = RnextB( registerFunc, xRef ) )
  77. {
  78. auto structBase, numFuncs, i;
  79.  
  80. structBase = Dword(xRef - 0x4);
  81.  
  82. if (Byte( xRef + 0xA ) == 0x83)
  83. {
  84. numFuncs = Byte( xRef + 0xC );
  85. }
  86. else
  87. {
  88. numFuncs = Dword( xRef + 0xC );
  89. }
  90.  
  91. if (numFuncs < 50000)
  92. {
  93. Message( "Found 0x%x, count: 0x%x, (xref: 0x%x)\n", structBase, numFuncs, xRef);
  94. for ( i = 0; i < numFuncs; i = i + 0x8 )
  95. {
  96. HandleLuaFunc( structBase + i );
  97. }
  98. }
  99. }
  100.  
  101. // Special func:
  102. registerFunc = BADADDR;
  103. xRef = BADADDR;
  104. registerFunc = FindBinary( 0, SEARCH_DOWN, "53 8B DC 51 51 83 E4" );
  105.  
  106. if ( registerFunc == BADADDR )
  107. {
  108. Message( "LabelLuaFuncs: Error, couldn't find FrameScript_RegisterSpecialFunction.\n" );
  109. return;
  110. }
  111.  
  112. registerFunc = NextFunction( PrevFunction( registerFunc ) );
  113.  
  114. for( xRef = RfirstB( registerFunc ); xRef != BADADDR; xRef = RnextB( registerFunc, xRef ) )
  115. {
  116. auto offsetClassName,className;
  117. structBase = Dword( xRef - 0x5 + 0x1 );
  118. numFuncs = Byte( xRef - 0x7 + 0x1 );
  119. offsetClassName = Dword( xRef - 0xC + 0x1 );
  120. className = GetString( offsetClassName, -1, ASCSTR_C );
  121. if (numFuncs < 50000)
  122. {
  123. Message( "Found 0x%x, count: 0x%x\n", structBase, numFuncs);
  124. for ( i = 0; i < numFuncs * 0x8; i = i + 0x8 )
  125. {
  126. HandleLuaFuncWithClass( structBase + i, className);
  127. }
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement