搜索到内存然后修改它,就像金山游侠游戏修改器。
BOOL FindFirst(DWORD dwValue);
BOOL FindNext(DWORD dwValue);
DWORD g_arList[1024];
int g_nListCnt;
HANDLE g_hProcess;
FindFirst进行第一次搜索,然后将搜索到的地址保存在g_arList中,地址的个数记录在g_nListCnt中。
然后检查g_nListCnt的值,如果大于1 那么就说明搜索到的地址多于1个。
然后来修改,调用FindNext函数,它在g_arList中查找,并更新,并将地址的个数写到g_nListCnt中
然后检查g_nListCnt 直到最终g_nListCnt等于1为止。
BOOL FindFirst(DWORD dwValue)
{
constDWORD dwOneGB = 1024*1024*1024; //1GB
constDWORD dwOnePage = 4*1024; //4KB
if(g_hProcess== NULL)
returnFALSE;
//查看操作系统类型,以决定开始地址
DWORDdwBase;
OSVERSIONINFOvi = { sizeof(vi) };
::GetVersionEx(&vi);
if(vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
dwBase= 4*1024*1024; //Windows 98系列,4MB
else
dwBase= 640*1024; // Windows NT系列,64KB
//在开始地址到2GB的地址空间进行查找
for(;dwBase < 2*dwOneGB; dwBase += dwOnePage)
{
//比较1页大小的内存
CompareAPage(dwBase,dwValue);
}
returnTRUE;
}
BOOL FindNext(DWORD dwValue)
{
// 保存m_arList数组中有效地址的个数,初始化新的m_nListCnt值
int nOrgCnt = g_nListCnt;
g_nListCnt = 0;
// 在m_arList数组记录的地址处查找
BOOL bRet = FALSE; // 假设失败
DWORD dwReadValue;
for(int i=0; i<nOrgCnt; i++)
{
if(::ReadProcessMemory(g_hProcess, (LPVOID)g_arList[i], &dwReadValue, sizeof(DWORD), NULL))
{
if(dwReadValue == dwValue)
{
g_arList[g_nListCnt++] = g_arList[i];
bRet = TRUE;
}
}
}
return bRet;
}
2012/8/5
jofranks 于南昌