Guest User

Untitled

a guest
Jul 18th, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. #include <ida.idc>
  2.  
  3. static main(){
  4. auto curAddr, xref, count, sPath, hFile;
  5.  
  6. // WowClientDB_Common__LoadInternal1
  7. curAddr = FindBinary( 0, SEARCH_DOWN, "55 8B EC 56 57 FF 75 ? 8B F9 FF 75 ? E8 ? ? ? ? 8B F0 59 59 85 F6 74 ?" );
  8.  
  9. if ( curAddr == BADADDR ){
  10. Message("Can't find WowClientDB_Common__LoadInternal1, aborting...\n");
  11. return;
  12. }
  13. // WowClientDB_Common__Load
  14. curAddr = NextFunction( curAddr );
  15.  
  16. // store it where our database file is!
  17. sPath = ExtractPath( GetIdbPath() ) + "ClientDBCTables.h";
  18.  
  19. // open our header file
  20. hFile = fopen( sPath, "w" );
  21. if ( hFile != -1 ){
  22. fprintf( hFile, "typedef enum ClientDB{\n\n" );
  23. }
  24.  
  25. // time to loop through and find all cross references to the wow DB_Common_Load function we found above!
  26. for ( xref = RfirstB(curAddr); xref != BADADDR; xref = RnextB(curAddr, xref) ) {
  27. auto prevFunc, disasm, disasmAddr, listStart;
  28.  
  29. prevFunc = PrevFunction( xref );
  30. disasmAddr = xref;
  31.  
  32. // search for the correct offset
  33. do{
  34. disasm = GetDisasm( disasmAddr );
  35.  
  36. if ( disasm == BADADDR ){
  37. break;
  38. }
  39. if ( disasmAddr < prevFunc ){
  40. break;
  41. }
  42.  
  43. // match yay!
  44. if ( strstr( disasm, "mov" ) > -1 && strstr( disasm, "off" ) > -1 && strstr( disasm, "dword" ) == -1 )
  45. break;
  46.  
  47. disasmAddr = PrevHead( disasmAddr, prevFunc );
  48. } while ( 1 );
  49.  
  50. listStart = GetOperandValue(disasmAddr, 1);
  51.  
  52. if ( listStart == BADADDR ){
  53. continue;
  54. }
  55.  
  56. // was this a pointer to the real list?
  57. if ( strstr( disasm, "ds:" ) > -1 ){
  58. listStart = Dword(listStart);
  59. }
  60.  
  61. do{
  62. auto dbNameOffset, dbStruct, dbName;
  63.  
  64. dbStruct = Dword(listStart);
  65. dbNameOffset = Dword(listStart + 0x4);
  66.  
  67. // invalid :( /tear
  68. if ( dbStruct == 0 || dbNameOffset == 0 || dbStruct == 0xFFFFFFFF || dbNameOffset == 0xFFFFFFFF ){
  69. break;
  70. }
  71.  
  72. // grab the name of this table
  73. dbName = WoWDb_GetName(dbNameOffset);
  74.  
  75. if ( strlen(dbName) == 0 ){
  76. break;
  77. }
  78.  
  79. // Rename ida:
  80. RenameFunc( dbStruct, form( "%sDBTable", dbName ) );
  81. // save to file!
  82. if ( hFile != -1 ){
  83. fprintf( hFile, "\t%sDBTable = 0x%X,\n", dbName, dbStruct );
  84. }
  85.  
  86. // IDA doesn't make these dwords dammit! Let's do it!
  87. MakeDword(xref);
  88. MakeDword(xref+0x4);
  89. MakeDword(dbStruct);
  90. MakeDword(dbNameOffset);
  91. MakeDword(dbNameOffset+0xC);
  92.  
  93. listStart = listStart + 8;
  94. count++;
  95.  
  96. } while( 1 );
  97. }
  98.  
  99. Message("Saved and renamed %u tables to %s\n", count, sPath);
  100.  
  101. if ( hFile != -1 ){
  102. fprintf( hFile, "} ClientDB;\n" );
  103. }
  104.  
  105. fclose(hFile);
  106. }
  107.  
  108. // 1 = Success, 0 = Failure
  109. static RenameFunc( dwAddress, sFunction )
  110. {
  111. auto dwRet;
  112.  
  113. dwRet = MakeNameEx( dwAddress, sFunction, SN_NOWARN );
  114.  
  115. if( dwRet == 0 )
  116. {
  117. auto sTemp, i;
  118. for( i = 0; i < 32; i++ )
  119. {
  120. sTemp = form( "%s_%i", sFunction, i );
  121.  
  122. if( ( dwRet = MakeNameEx( dwAddress, sTemp, SN_NOWARN ) ) != 0 )
  123. {
  124. Message( "Info: Renamed to %s instead of %s\n", sTemp, sFunction );
  125. break;
  126. }
  127. }
  128. }
  129. return dwRet;
  130. }
  131.  
  132. static ExtractPath( sPath ){
  133. auto dwIndex;
  134. for ( dwIndex = strlen( sPath ); strstr( substr( sPath, dwIndex, -1 ), "/" ) && dwIndex > 0; dwIndex-- );
  135. return substr( sPath, 0, dwIndex + 1 );
  136. }
  137.  
  138. static WoWDb_GetName( dbBase ){
  139. auto dbName;
  140.  
  141. // mov eax, offset aDbfilesclientA ; "DBFilesClient\\Achievement.dbc"
  142. dbName = GetString( Dword(dbBase), -1, ASCSTR_C );
  143.  
  144. // Return the the token after \ and before .
  145. return substr( dbName, strstr( dbName, "\\" ) + 1, -5 );
  146. }
Add Comment
Please, Sign In to add comment