Simple2012

Untitled

Oct 16th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | None | 0 0
  1. // test.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <windows.h>
  6. #include <tchar.h>
  7. #include <stdio.h>
  8. #include <psapi.h>
  9. #include <TlHelp32.h>
  10. #include <iostream>
  11. #include <cstring>
  12. #include <tchar.h>
  13. using namespace std;
  14. // To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
  15. // and compile with -DPSAPI_VERSION=1
  16.  
  17.  
  18.  
  19. TCHAR* PrintModules( DWORD processID, DWORD TibianicPID )
  20. {
  21.     HMODULE hMods[1024];
  22.     HANDLE hProcess;
  23.     DWORD cbNeeded;
  24.     unsigned int i;
  25.  
  26.     // Print the process identifier.
  27.     printf( "\nProcess ID: %u\n", processID );
  28.  
  29.     // Get a handle to the process.
  30.     hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
  31.                             PROCESS_VM_READ,
  32.                             FALSE, processID );
  33.     if (NULL == hProcess)
  34.         return 0;
  35.  
  36.    // Get a list of all the modules in this process.
  37.     if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
  38.     {
  39.         for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
  40.         {
  41.             TCHAR szModName[MAX_PATH];
  42.  
  43.             // Get the full path to the module's file.
  44.             if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
  45.                                       sizeof(szModName) / sizeof(TCHAR)))
  46.             {
  47.                 // Print the module name and handle value.
  48.                 if (processID == TibianicPID){
  49.                     _tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
  50.                     return szModName;
  51.                 }
  52.             }
  53.         }
  54.     }
  55.    
  56.     // Release the handle to the process.
  57.  
  58.     CloseHandle( hProcess );
  59.  
  60.     return 0;
  61. }
  62.  
  63. int main( void )
  64. {
  65.     DWORD pAddressIn = 0xF3090;
  66.     DWORD pAddress1;
  67.     DWORD pAddress2; // This will store our value we read.
  68.     DWORD pAddress3 = 0x00400000; // This will store our value we read.
  69.     DWORD offset1 = 0x378;
  70.     DWORD offset2 = 0x218;
  71.     DWORD offset3 = 0x10C;
  72.     DWORD offset4 = 0x1C0;
  73.     DWORD offset5 = 0x78;
  74.  
  75.     HWND hWnd = FindWindow( NULL , _T("Tibianic Client") );
  76.     DWORD TibianicPID; //This will store our Process ID, used to read/write into the memory
  77.     GetWindowThreadProcessId(hWnd, &TibianicPID); //Get the process id and place it in pid
  78.  
  79.     DWORD aProcesses[1024];
  80.     DWORD cbNeeded;
  81.     DWORD cProcesses;
  82.     unsigned int i;
  83.  
  84.     // Get the list of process identifiers.
  85.     if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
  86.         return 1;
  87.  
  88.     // Calculate how many process identifiers were returned.
  89.     cProcesses = cbNeeded / sizeof(DWORD);
  90.  
  91.     // Print the names of the modules for each process.
  92.  
  93.     for ( i = 0; i < cProcesses; i++ )
  94.     {
  95.         pAddress1 = (DWORD)PrintModules( aProcesses[i], TibianicPID );
  96.         if(pAddress1 != 0)
  97.             pAddress2 = pAddress1;
  98.     }
  99.    
  100.     cout << "pAddress1: " << pAddress1 << endl;
  101.     cout << "pAddress2: " << pAddress2 << endl;
  102.  
  103.  
  104.  
  105.     /* Reading Memory & Opening process */
  106.     HANDLE phandle = OpenProcess(PROCESS_VM_READ,0, TibianicPID); // Get permission to read
  107.     if(!phandle){ // Once again, if it fails, tell us
  108.             cout <<"Error message: " << GetLastError() << " Dvs Access denied" << endl;
  109.             cin.get();
  110.             return 0;
  111.     }
  112.  
  113.     cout << "Base address is: " << pAddress3 << endl;
  114.     ReadProcessMemory(phandle,(void*)(pAddress3+pAddressIn),&pAddress3,sizeof(pAddress3),0);
  115.     cout << "Value read is: " << pAddress3 << endl;
  116.     ReadProcessMemory(phandle,(void*)(pAddress3+offset1),&pAddress3,sizeof(pAddress3),0);
  117.     cout << "Value read is: " << pAddress3 << endl;
  118.     ReadProcessMemory(phandle,(void*)(pAddress3+offset2),&pAddress3,sizeof(pAddress3),0);
  119.     cout << "Value read is: " << pAddress3 << endl;
  120.     ReadProcessMemory(phandle,(void*)(pAddress3+offset3),&pAddress3,sizeof(pAddress3),0);
  121.     cout << "Value read is: " << pAddress3 << endl;
  122.     ReadProcessMemory(phandle,(void*)(pAddress3+offset4),&pAddress3,sizeof(pAddress3),0);
  123.     cout << "Value read is: " << pAddress3 << endl;
  124.     ReadProcessMemory(phandle,(void*)(pAddress3+offset5),&pAddress3,sizeof(pAddress3),0);
  125.     cout << "Value read is: " << pAddress3 << endl;
  126.     ReadProcessMemory(phandle,(void*)(pAddress3),&pAddress3,sizeof(pAddress3),0);
  127.     cout << "Value read is: " << pAddress3 << endl;
  128.  
  129.  
  130.     ReadProcessMemory(phandle,(void*)(0x00A57830),&pAddress2,sizeof(pAddress2),0);
  131.     cout << "Real value read is: " << pAddress2 << endl;
  132.     cin.get();
  133.     return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment