15,471
社区成员
发帖
与我相关
我的任务
分享
DWORD pid;
HWND hWnd = ::FindWindow(NULL, TEXT("TestServer"));
if (!hWnd)
{
AfxMessageBox(L"没有找到");
}
::GetWindowThreadProcessId(hWnd, &pid);
HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
LPVOID lpBaseAddress = (LPVOID)14177052;
UpdateData();
//DWORD dwValue = _wtoi(m_strWrite);
LPCTSTR kk = m_strWrite;
if (!::WriteProcessMemory(hProcess, lpBaseAddress, (void*)kk, 10, 0))
return;
VirtualProtectEx(hProcess, lpBaseAddress, 8, PAGE_EXECUTE_READWRITE,0 );
这句也加了,没反应。
DWORD pid;
HWND hWnd = ::FindWindow(NULL, TEXT("TestServer"));
if (!hWnd)
{
AfxMessageBox(L"没有找到");
}
::GetWindowThreadProcessId(hWnd, &pid);
HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
LPVOID lpBaseAddress = (LPVOID)14177052;
CString strPrompt;
BOOL bRet = FALSE;
CString aa;
m_editStr.GetWindowTextW(aa);
LPCTSTR paa = aa;
aa.Trim();
int width = aa.GetLength()*2+2;
BYTE* strModi = new BYTE[width];
memcpy(strModi, paa, width);
MEMORY_BASIC_INFORMATION mbi;
DWORD dwOldProtect;
if (sizeof(mbi) != VirtualQueryEx(hProcess, lpBaseAddress, &mbi, sizeof(mbi)))
{
strPrompt.Format(L"查询0x%x的页面信息失败" ); AfxMessageBox(strPrompt);
}
if (FALSE == VirtualProtectEx(hProcess, mbi.BaseAddress, mbi.RegionSize,
PAGE_EXECUTE_READWRITE, &dwOldProtect))
{
strPrompt.Format(L"设置0x%x的页面属性失败"); AfxMessageBox(strPrompt);
}
bRet = WriteProcessMemory(hProcess, lpBaseAddress, strModi, width, NULL);
if (FALSE == bRet)
{
strPrompt.Format(L"修改0x%x的值失败"); AfxMessageBox(strPrompt);
}
delete strModi;
非常感谢各位的帮助,现在问题解决了。
LPTSTR pText = NULL;
pText = (LPTSTR)VirtualAllocEx(hProcess, NULL, 256, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProcess,pText ,你的字符串,长度,NULL);
VirtualProtectEx(hProcess, lpBaseAddress, 8, PAGE_EXECUTE_READWRITE,0 );
这句也加了,没反应。[/quote]
在内存中,整形和字符串是没有区别的,既然整形没问题,那么字符串也应该行的,注意字符串的大小,以后最后以0结束。
先一点点的调整字符串的大小,然后观察情况进行分析。
比如int a=10;可以将a写入进去,然后这样:
*(char *)&a ='A'; *(((char *)&a) + 1) = 0;
这样a的地址就是存的字符”A"了,然后调试分析,一点点加长字符串的长度。