Advertisement
dcomicboy

Main.cpp

Jul 17th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. #include "Manager.h"
  2. #include <detours.h>
  3.  
  4. /*----- Main Globals ---------------------------------------*/
  5. DWORD g_dwAddress = 0;
  6. bool g_bDone = false;
  7. vector<int> g_Addresses;
  8.  
  9. /*----- Add an Address to the Vector ---------------------------------------*/
  10. void AddAddress( int Addy )
  11. {
  12. g_Addresses.push_back( Addy );
  13. }
  14.  
  15. /*----- Check if the Address isn't in the Vector yet ---------------------------------------*/
  16. bool IsUnique( int Addy )
  17. {
  18. for ( int i = 0; i < g_Addresses.size(); i++ )
  19. if( g_Addresses[ i ] == Addy )
  20. return false;
  21. return true;
  22. }
  23.  
  24. /*----- Hook the function which gets the Class-addresses by Name ---------------------------------------*/
  25. typedef int( __stdcall* o_GetClassByName )( string* strClassName );
  26. o_GetClassByName pGetClassByName = 0;
  27.  
  28. int __stdcall hkGetClassByName( string* strClassName )
  29. {
  30. _asm pushad;
  31.  
  32. int iTmpAddress = pGetClassByName( strClassName );//iTmpAddress is the Address of the Class
  33.  
  34. /*----- If we don't have the Address yet ---------------------------------------*/
  35. if( IsUnique( iTmpAddress ) && iTmpAddress != NULL )
  36. {
  37. DWORD dwBase = (DWORD)GetModuleHandle( NULL ) + 0x56EF58;//<- Change 0x56EF58 to what you want. It defines the Scan Start
  38. for ( DWORD dwCur = dwBase; dwCur <= dwBase + 0xEEEEE/*<- Scan Range*/; dwCur += 0x4 )//Scan for a Direct Pointer to the Current Class-Address
  39. {
  40. if( *(DWORD*)dwCur == (DWORD)iTmpAddress )//If the Current Address we scan points to the Class-address -> Log it
  41. {
  42. /*Change that to what you want. For example:*/
  43. /*
  44. CManager::Log( "#define: CLASS_%s 0x%X", strClassName->c_str(), dwCur );
  45. */
  46. Manager::Log( "Class: %s Address: 0x%X TempAddress: 0x%X", strClassName->c_str(), dwCur, iTmpAddress );
  47. break;
  48. }
  49. }
  50. /*----- We logged it, add it to the Vector so we don't log it all the Time ---------------------------------------*/
  51. AddAddress( iTmpAddress );
  52. }
  53.  
  54. _asm popad;
  55. return iTmpAddress;//Return the Return of the 'Real' function
  56. }
  57.  
  58. DWORD __stdcall Start( LPVOID )
  59. {
  60. /*----- Let's go sure we got the Address of the function ---------------------------------------*/
  61. for( ;g_dwAddress == 0; Sleep( 300 ) )
  62. g_dwAddress = Manager::ClassByNameAddress();
  63.  
  64. Manager::Log( "Address Found! (0x%X)", g_dwAddress );
  65. Manager::Log( "Hooking Function...." );
  66.  
  67. /*----- Hook the Function ---------------------------------------*/
  68. pGetClassByName = (o_GetClassByName)DetourFunction( (PBYTE)g_dwAddress, (PBYTE)hkGetClassByName );
  69.  
  70. return 0;
  71. }
  72.  
  73.  
  74. bool __stdcall DllMain( HANDLE _HDllHandle, DWORD _Reason, LPVOID _Reserved)
  75. {
  76. if( _Reason == 1 )
  77. CreateThread( 0, 0, Start, 0, 0, 0 );
  78. return true;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement