Obtain the first address of the target process.
Add the following code to the header file:
#include <windows.h> #include <tlhelp32.h>
Add the following function to the Cpp file to obtain the first address of the target process:
(Note that AfxMessageBox is defined in afxwin. h. If it is not used in MFC, change it as appropriate)
// Obtain the first address of the target process, BOOL CImageBloodDlg: getProcessAddr (DWORD dwPID, DWORD & baseAddr) {HANDLE hModuleSnap = INVALID_HANDLE_VALUE; MODULEENTRY32 me32; // obtain the snapshothModuleSnap = snapshot (TH32CS_SNAPMODULE, dwPID) of all processes in the target process; if (hModuleSnap = snapshot) {AfxMessageBox (_ T ("createconlhelp32snapshot (of modules) fail "); return (FALSE);} // set the MODULEENTRY32 Data Structure size field me32.dwSize = sizeof (MODULEE NTRY32); // retrieves the information of the first module. if (! Module32First (hModuleSnap, & me32) {AfxMessageBox (_ T ("Module32First fail"); // display CloseHandle (hModuleSnap) for failed calls ); // clear the handle object return (FALSE);} // get the base address baseAddr = (DWORD) me32.modBaseAddr from me32; // do not forget to clear the module handle object CloseHandle (hModuleSnap ); return (TRUE );}
Call this function to obtain the first address of the target process.