Advertisement
Guest User

Untitled

a guest
Sep 1st, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #pragma once
  2. class Memory
  3. {
  4. public:
  5.     Memory(const std::string &ClassName);
  6.     bool Read(unsigned int Address, std::string& Buffer);
  7.     virtual ~Memory(void);
  8. private:
  9.     HANDLE h_Process;
  10.     DWORD h_PID;
  11.     HWND h_HWND;
  12. };
  13.  
  14.  
  15.  
  16. Memory::Memory(const std::string &ClassName)
  17. {
  18.     this->h_HWND = FindWindow(ClassName.c_str(), NULL);
  19.     GetWindowThreadProcessId(this->h_HWND, &this->h_PID);
  20.     this->h_Process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->h_PID);
  21. }
  22.  
  23. bool Memory::Read(unsigned int Address, std::string& Buffer)
  24. {
  25.     SIZE_T ByteOfRead;
  26.     if(Address == NULL)
  27.         return false;
  28.  
  29.     if (!ReadProcessMemory(this->h_Process, (LPCVOID)Address, (LPVOID)&Buffer, sizeof(std::string), &ByteOfRead))
  30.         return false;
  31.  
  32.     if ( ByteOfRead != sizeof(Buffer) )
  33.         return false;
  34.  
  35.     return true;
  36. }
  37.  
  38. Memory::~Memory(void)
  39. {
  40.     this->h_HWND = NULL;
  41.     this->h_PID = NULL;
  42.     if(this->h_Process != NULL)
  43.         CloseHandle(this->h_Process);
  44.     this->h_Process = NULL;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement