1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include "MemReader.h"
//=========================================================================
void GetPID(MemReader* MemPtr, char* pName)
{
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pInfo;
pInfo.dwSize = sizeof(PROCESSENTRY32);
MemPtr->m_pName = pName;
if (Process32First(snapshot, &pInfo))
{
while (Process32Next(snapshot, &pInfo))
{
if (_stricmp(MemPtr->m_pName, pInfo.szExeFile) == 0)
{
MemPtr->m_pID = pInfo.th32ProcessID;
CloseHandle(snapshot);
return;
}
}
}
CloseHandle(snapshot);
MemPtr->m_pID = 0;
return;
}
//=========================================================================
void Open(MemReader* MemPtr , DWORD accessRights)
{
printf("Process ID: %X \n", MemPtr->m_pID);
MemPtr->m_hProc = OpenProcess(accessRights, false, MemPtr->m_pID);
if (MemPtr->m_hProc)
printf("Process open \n");
else
printf("Error culdnot open process \n");
}
//=========================================================================
void Close(MemReader* MemPtr)
{
CloseHandle(MemPtr->m_hProc);
}
//=========================================================================
void Read(MemReader* MemPtr, DWORD from, size_t size)
{
int flag = 0;
flag = ReadProcessMemory(MemPtr->m_hProc, (LPCVOID)from, &MemPtr->m_buffer, size, NULL);
if (!flag)
printf("The Read func NOT succsess \n");
DWORD r = GetLastError();
printf("%d \n", r); // show 5!
}
|