Pushok

vietcong ammo patch

Jan 24th, 2012
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. DWORD WINAPI Thread( LPVOID lParam )
  4. {
  5.     HMODULE hModule = GetModuleHandle( L"game.dll" );
  6.     MODULEINFO mdlinfo;
  7.     GetModuleInformation( GetCurrentProcess(), hModule, &mdlinfo, sizeof( mdlinfo ) );
  8.     unsigned char GameSavLoad1[] = { 0x81, 0xEC, 0x28, 0x02 };
  9.     unsigned char GameSavLoad2[] = { 0x00, 0x00, 0x53, 0x55 };
  10.     unsigned char GameSavLoad3[] = { 0x56, 0x57, 0x68, 0x54 };
  11.    
  12.     unsigned int head_offs = 0x676134;
  13.     unsigned int def_offs = 0x4F80C0;
  14.     unsigned int offset = 0;
  15.    
  16.     int c= (int)hModule;
  17.     int max = (int)hModule + mdlinfo.SizeOfImage - sizeof( unsigned char[4] ) * 3;
  18.    
  19.     while( c != max )
  20.     {
  21.             if( memcmp( (void*)(c), GameSavLoad1, sizeof( GameSavLoad1 ) ) == 0 &&
  22.                 memcmp( (void*)(c + sizeof( unsigned char[4] ) ), GameSavLoad2, sizeof( GameSavLoad2 ) ) == 0 &&
  23.                 memcmp( (void*)(c + sizeof( unsigned char[4] ) * 2 ), GameSavLoad3, sizeof( GameSavLoad3 ) ) == 0)
  24.             {
  25.                 break;
  26.             }
  27.  
  28.             offset++; c++;
  29.     }
  30.  
  31.     //TCHAR str[128];
  32.     //TCHAR str1[128];
  33.     //wsprintf( str, L"Offset found %x!\nHead:%x+%x=%x\nAny:%x+%x=%x", offset, c, head_offs , c + head_offs , c, def_offs, def_offs + c  );
  34.     //wsprintf( str1, L"Size: %x", mdlinfo.SizeOfImage - sizeof( unsigned char[4] ) * 3 );
  35.     //MessageBox( 0, str, 0, MB_OK );
  36.     //MessageBox( 0, str1, 0, MB_OK );
  37.  
  38.     if( c != max )
  39.     {
  40.         unsigned char ammo_sig[] = { 0x66, 0x29, 0x5C, 0x7E };
  41.         unsigned char ammo_patch[] = { 0x83, 0x6C, 0x7E, 0x3C, 0x00};
  42.        
  43.         while( c != max )
  44.         {
  45.                 if( memcmp( (void*)(c), ammo_sig, sizeof( ammo_sig ) ) == 0 )
  46.                 {
  47.                     DWORD dwOldState;
  48.  
  49.                     VirtualProtect( (void*)c, sizeof( ammo_patch ), PAGE_READWRITE, &dwOldState );
  50.  
  51.                     if( true )
  52.                     {
  53.                         *(unsigned char*)( c ) = ammo_patch[0];
  54.                         *(unsigned char*)( c + 1 ) = ammo_patch[1];
  55.                         *(unsigned char*)( c + 2 ) = ammo_patch[2];
  56.                         *(unsigned char*)( c + 3 ) = ammo_patch[3];
  57.                         *(unsigned char*)( c + 4 ) = ammo_patch[4];
  58.                    
  59.                         TCHAR szMsg[128];
  60.                         wsprintf( szMsg, L"Memory patched: %x %x %x %x %x", *(unsigned char*)( c ), *(unsigned char*)( c + 1 ), *(unsigned char*)( c + 2 ), *(unsigned char*)( c + 3 ), *(unsigned char*)( c + 4 ) );
  61.  
  62.                         MessageBox( 0, szMsg, 0, MB_OK );
  63.                     }
  64.                     else
  65.                     {
  66.  
  67.                     }
  68.  
  69.                     break;
  70.                 }
  71.  
  72.                 c++;
  73.         }
  74.     }
  75.     else
  76.     {
  77.         MessageBox( 0, L"Something went wrong.", 0, MB_OK );
  78.     }
  79.  
  80.     return 0;
  81. }
  82.  
  83. BOOL APIENTRY DllMain( HMODULE hModule,
  84.                        DWORD  ul_reason_for_call,
  85.                        LPVOID lpReserved
  86.                      )
  87. {
  88.     switch (ul_reason_for_call)
  89.     {
  90.     case DLL_PROCESS_ATTACH:
  91.        
  92.         CreateThread( 0, 0, Thread, 0, 0, 0 );
  93.        
  94.         break;
  95.     case DLL_THREAD_ATTACH:
  96.     case DLL_THREAD_DETACH:
  97.     case DLL_PROCESS_DETACH:
  98.         break;
  99.     }
  100.     return TRUE;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment