[C++] 纯文本查看 复制代码 BOOL _NtWriteProcessMemory(HANDLE hprocess, PVOID address, PVOID buffer, SIZE_T readSize, SIZE_T* realSize);
typedef NTSTATUS(NTAPI* PfnNtWriteVirtualMemory)(
HANDLE ProcessHandle,
PVOID BaseAddress,
PVOID Buffer,
SIZE_T NumberOfBytesToWrite,
SIZE_T* NumberOfBytesWritten OPTIONAL);
BOOL _NtWriteProcessMemory(HANDLE hprocess, PVOID address, PVOID buffer, SIZE_T readSize, SIZE_T* realSize)
{
HMODULE hModule = LoadLibraryA("ntdll.dll");
if (!hModule)
{
return FALSE;
}
PfnNtWriteVirtualMemory p_NtWriteVirtualMemory = (PfnNtWriteVirtualMemory)GetProcAddress(hModule, "NtWriteVirtualMemory");
if (!p_NtWriteVirtualMemory)
{
return FALSE;
}
if (p_NtWriteVirtualMemory(hprocess, address, buffer, readSize, realSize) == 0)
{
return TRUE;
}
return FALSE;
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD processId = 0xDA4; // notepad pid
HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processId);
if (hProcess == NULL) {
printf("Failed to open process: %d\n", GetLastError());
return 1;
}
wchar_t buf[] = L"hahaha";
SIZE_T writed;
_NtWriteProcessMemory(hProcess, (PVOID)0x450930, // ce搜索出来的记事本的文本地址
buf, wcslen(buf)*sizeof(wchar_t), &writed);
CloseHandle(hProcess);
return 0;
}
这个代码测试是通过的,编译成64位程序,对64位的记事本进行写入,可以成功 |