Advertisement
igromanru

MemoryClass.cpp

Jun 28th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include "MemoryClass.hpp"
  2. /*
  3.  * MemoryClass
  4.  *
  5.  * Copyright (c) 2012 Igromanru
  6.  * Credits: KN4CK3R
  7.  */
  8. MemoryClass::MemoryClass(HANDLE hProcess)
  9. {
  10.     this->hProcess = hProcess;
  11. }
  12.  
  13. MemoryClass::~MemoryClass(void)
  14. {
  15.     //if (this->hProcess != NULL)
  16.     //{
  17.     //  CloseHandle(this->hProcess);
  18.     //}
  19. }
  20.  
  21. DWORD MemoryClass::getReadBuffer()
  22. {
  23.     return this->lpReadBuffer;
  24. }
  25.  
  26. DWORD MemoryClass::getWriteBuffer()
  27. {
  28.     return this->lpWriteBuffer;
  29. }
  30.  
  31. bool MemoryClass::WriteMemory(DWORD dwBaseAddress, LPVOID lpBuffer, int iBufferSize)
  32. {
  33.     bool status = WriteProcessMemory(this->hProcess, (LPVOID)dwBaseAddress , lpBuffer, iBufferSize, &lpWriteBuffer);
  34.     return status;
  35. }
  36.  
  37. bool MemoryClass::ReadMemory(DWORD dwBaseAddress, LPVOID lpBuffer, int iBufferSize)
  38. {
  39.     bool status = ReadProcessMemory(this->hProcess, (LPVOID)dwBaseAddress , lpBuffer, iBufferSize, &lpReadBuffer);
  40.     return status;
  41. }
  42.  
  43. DWORD MemoryClass::ReadPointerAdress(DWORD dwOffsetsArray[], int iArraySize, DWORD dwBaseAddress)
  44. {
  45.     DWORD adress;
  46.     this->ReadMemory(dwBaseAddress+dwOffsetsArray[0], &adress, sizeof(adress));
  47.     for (int i = 1; i < iArraySize-1; i++)
  48.     {
  49.         if (adress != NULL)
  50.         {
  51.             this->ReadMemory(adress+dwOffsetsArray[i], &adress, sizeof(adress));
  52.         }else {
  53.             return -2;
  54.         }      
  55.     }
  56.     return adress+dwOffsetsArray[iArraySize-1];
  57. }
  58.  
  59. DWORD MemoryClass::GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId)
  60. {
  61.     MODULEENTRY32 lpModuleEntry = {0};
  62.     HANDLE hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwProcessId );
  63.  
  64.     if(!hSnapShot)
  65.         return NULL;
  66.     lpModuleEntry.dwSize = sizeof(lpModuleEntry);
  67.     BOOL bModule = Module32First( hSnapShot, &lpModuleEntry );
  68.     while(bModule)
  69.     {
  70.         if(!strcmp( lpModuleEntry.szModule, lpModuleName ) )
  71.         {
  72.             CloseHandle( hSnapShot );
  73.             return (DWORD)lpModuleEntry.modBaseAddr;
  74.         }
  75.         bModule = Module32Next( hSnapShot, &lpModuleEntry );
  76.     }
  77.     CloseHandle( hSnapShot );
  78.     return NULL;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement