Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MemoryClass.hpp"
- /*
- * MemoryClass
- *
- * Copyright (c) 2012 Igromanru
- * Credits: KN4CK3R
- */
- MemoryClass::MemoryClass(HANDLE hProcess)
- {
- this->hProcess = hProcess;
- }
- MemoryClass::~MemoryClass(void)
- {
- //if (this->hProcess != NULL)
- //{
- // CloseHandle(this->hProcess);
- //}
- }
- DWORD MemoryClass::getReadBuffer()
- {
- return this->lpReadBuffer;
- }
- DWORD MemoryClass::getWriteBuffer()
- {
- return this->lpWriteBuffer;
- }
- bool MemoryClass::WriteMemory(DWORD dwBaseAddress, LPVOID lpBuffer, int iBufferSize)
- {
- bool status = WriteProcessMemory(this->hProcess, (LPVOID)dwBaseAddress , lpBuffer, iBufferSize, &lpWriteBuffer);
- return status;
- }
- bool MemoryClass::ReadMemory(DWORD dwBaseAddress, LPVOID lpBuffer, int iBufferSize)
- {
- bool status = ReadProcessMemory(this->hProcess, (LPVOID)dwBaseAddress , lpBuffer, iBufferSize, &lpReadBuffer);
- return status;
- }
- DWORD MemoryClass::ReadPointerAdress(DWORD dwOffsetsArray[], int iArraySize, DWORD dwBaseAddress)
- {
- DWORD adress;
- this->ReadMemory(dwBaseAddress+dwOffsetsArray[0], &adress, sizeof(adress));
- for (int i = 1; i < iArraySize-1; i++)
- {
- if (adress != NULL)
- {
- this->ReadMemory(adress+dwOffsetsArray[i], &adress, sizeof(adress));
- }else {
- return -2;
- }
- }
- return adress+dwOffsetsArray[iArraySize-1];
- }
- DWORD MemoryClass::GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId)
- {
- MODULEENTRY32 lpModuleEntry = {0};
- HANDLE hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwProcessId );
- if(!hSnapShot)
- return NULL;
- lpModuleEntry.dwSize = sizeof(lpModuleEntry);
- BOOL bModule = Module32First( hSnapShot, &lpModuleEntry );
- while(bModule)
- {
- if(!strcmp( lpModuleEntry.szModule, lpModuleName ) )
- {
- CloseHandle( hSnapShot );
- return (DWORD)lpModuleEntry.modBaseAddr;
- }
- bModule = Module32Next( hSnapShot, &lpModuleEntry );
- }
- CloseHandle( hSnapShot );
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement