メモリのアドレスの内容を修正して、ゲームの金貨の値を修正することができます
7613 ワード
メモリコンテンツのコアコードの変更を実現するには:
C++コード
C++コード
//
void CMemRepairDlg::InitProcessList()
{
PROCESSENTRY32 pe32;
ZeroMemory(&pe32, 0);
pe32.dwSize = sizeof(PROCESSENTRY32);
//
HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if ( INVALID_HANDLE_VALUE == handle )
{
MessageBox(" CreateToolhelp32Snapshot !");
return;
}
BOOL bRect = ::Process32First(handle, &pe32);
if ( m_map.size() > 0)
m_map.clear();//
CString cs;
while( bRect )
{
((CComboBox*)GetDlgItem(IDC_PROCESSLIST_COBOX))->AddString(pe32.szExeFile);
m_map.insert(std::pair<DWORD, CString>(pe32.th32ProcessID, pe32.szExeFile));
bRect = ::Process32Next(handle, &pe32);
}
((CComboBox*)GetDlgItem(IDC_PROCESSLIST_COBOX))->SetCurSel(3);
//GetModuleFileNameEX::
UpdateData(FALSE);
CloseHandle(handle);
}
//
void CMemRepairDlg::GetCurrentProcessHandle()
{
int nIndex = ((CComboBox*)GetDlgItem(IDC_PROCESSLIST_COBOX))->GetCurSel();
CString processStr = "";
((CComboBox*)GetDlgItem(IDC_PROCESSLIST_COBOX))->GetLBText(nIndex, processStr);
DWORD processId = 0;
if ( m_map.size() > 0 )
{
std::map<DWORD, CString>::iterator iterator;
for( iterator=m_map.begin();iterator != m_map.end();++iterator )
{
if ( !processStr.Compare(iterator->second) )
{
processId = iterator->first;
break;
}
}
}
if ( processId == 0 ) return;
m_handle = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if ( m_handle == NULL )
{
CString errorInfo;
errorInfo.Format("error code:%d !", GetLastError);
MessageBox(errorInfo);
return;
}
}
//
void CMemRepairDlg::ReadOnePageMem(DWORD baseptr, const char* pStr)
{
BYTE byte[4096] = {0};
//lpBaseptr:
BOOL bRect = ::ReadProcessMemory(m_handle, (LPCVOID)baseptr, byte, 4096, NULL);
LPDWORD ptr = NULL;
if ( bRect )
{
for( int i = 0;i < 4*1024-3;++i )
{
ptr = (DWORD*)&byte[i];
if ( *ptr == atoi(pStr) )
{
m_vector.push_back(baseptr+i);
}
}
}
}
//
void CMemRepairDlg::GetBasePtr(const char* pStr)
{
OSVERSIONINFO osInfo;
ZeroMemory(&osInfo, sizeof(OSVERSIONINFO));
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&osInfo);
DWORD baseAddr = 0;
if ( osInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )//98
{
baseAddr = 4*1024*1024;//98 4M
}
else
{
baseAddr = 64*1024;
}
if ( m_vector.size() > 0)
m_vector.clear();
// 2G
for( ;baseAddr < 2*1024*1024*1024;baseAddr+=4*1024 )
{
ReadOnePageMem(baseAddr, pStr);
}
}
//
void CMemRepairDlg::OnSearchBtn()
{
// TODO: Add your control notification handler code here
GetCurrentProcessHandle();
((CEdit*)GetDlgItem(IDC_VALUE_EDIT))->GetWindowText(m_value);
GetBasePtr(m_value.GetBuffer(m_value.GetLength()));
OperatorListBox();
}
//
void CMemRepairDlg::OperatorListBox()
{
CListBox* listBox = (CListBox*)GetDlgItem(IDC_PROCESS_LIST);
std::vector<DWORD>::iterator itrator;
listBox->ResetContent();
CString str;
for( itrator = m_vector.begin();itrator != m_vector.end();++itrator )
{
str.Format("%p", *itrator);
listBox->AddString(str);
}
UpdateData(FALSE);
}
void CMemRepairDlg::OnSelchangeProcessList()
{
// TODO: Add your control notification handler code here
CListBox* listBox = (CListBox*)GetDlgItem(IDC_PROCESS_LIST);
int nIndex = ((CListBox*)GetDlgItem(IDC_PROCESS_LIST))->GetCurSel();
CString strItem;
listBox->GetText(nIndex, strItem);
((CEdit*)GetDlgItem(IDC_ADDR_EDIT))->SetWindowText(strItem);
UpdateData(FALSE);
}
//
void CMemRepairDlg::OnStartBtn()
{
// TODO: Add your control notification handler code here
int nSize = m_vector.size();
DWORD dwValue;
if ( m_nextVector.size() > 0 )
m_nextVector.clear();
std::vector<DWORD>::iterator iterator;
for( iterator = m_vector.begin(); iterator != m_vector.end();++iterator )
{
BOOL bRect = ::ReadProcessMemory(m_handle, (LPCVOID)*iterator, &dwValue, sizeof(DWORD), NULL);
if (bRect)
{
if ( dwValue == atoi(m_value.GetBuffer(m_value.GetLength())) )//
{
m_nextVector.push_back(*iterator);
}
}
}
m_vector.clear();
m_vector = m_nextVector;
OperatorListBox();
}
//
void CMemRepairDlg::OnModifyBtn()
{
// TODO: Add your control notification handler code here
CString addrStr = "";
CString modifyStr = "";
((CEdit*)GetDlgItem(IDC_ADDR_EDIT))->GetWindowText(addrStr);//
((CEdit*)GetDlgItem(IDC_MODIFY_EDIT))->GetWindowText(modifyStr);
MessageBox(addrStr);
DWORD dwValue = atoi(modifyStr.GetBuffer(modifyStr.GetLength()));
DWORD addr = HexToNum(addrStr);;
BOOL bRect = ::WriteProcessMemory(m_handle,(LPVOID)addr, &dwValue, sizeof(DWORD), NULL);
if ( bRect )
MessageBox(" !");
else
{
int nCode = GetLastError();
CString errorInfo;
errorInfo.Format("%d :%d", addr, nCode);
MessageBox(errorInfo);
}
}
//
DWORD CMemRepairDlg::HexToNum(CString str)
{
int nSum = 0;
int nLength = str.GetLength();
int i = 0;
int nTemp = 0;
do
{
TCHAR cChar = str.GetAt(--nLength);
switch(cChar)
{
case 'A':
case 'a':
nTemp = 10;
break;
case 'B':
case 'b':
nTemp = 11;
break;
case 'C':
case 'c':
nTemp = 12;
break;
case 'D':
case 'd':
nTemp = 13;
break;
case 'E':
case 'e':
nTemp = 14;
break;
case 'F':
case 'f':
nTemp = 15;
break;
default:
nTemp = cChar - 48;
break;
}
nSum += nTemp*pow(16, i);
++i;
} while (nLength > 0);
return nSum;
}