參考一下:
#include <stdio.h>
#include <windows.h>
#define DATA_SIZE 1024
void main(void)
{
LPVOID lpAddress = VirtualAlloc( NULL,
DATA_SIZE,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE );
if ( lpAddress )
{
DWORD dwProcessId = GetCurrentProcessId();
HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS,
FALSE,
dwProcessId );
if ( hProcess )
{
char szBuffer[] = "MyData";
DWORD dwWrite;
if ( WriteProcessMemory( hProcess,
lpAddress,
szBuffer,
sizeof(szBuffer),
&dwWrite ) )
{
char szData[1024];
if ( ReadProcessMemory( hProcess,
lpAddress,
szData,
sizeof(szBuffer),
&dwWrite ) )
printf( "%s/n", szData );
}
CloseHandle( hProcess );
}
VirtualFree( lpAddress, 0, MEM_RESERVE );
}
}