class ProcessMemoryWorkApi
{
//HANDLE OpenProcess(
// DWORD dwDesiredAccess,// access flag
// BOOL bInheritHandle, // handle inheritance flag
// DWORD dwProcessId // process identifier
// );
[DllImport("kernel32.dll")]
public static extern
IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
//BOOL CloseHandle(
// HANDLE hObject // handle to object to close
// );
[DllImport("kernel32.dll")]
public static extern
Int32 CloseHandle(IntPtr hObject);
//BOOL WriteProcessMemory(
// HANDLE hProcess, // handle to process whose memory is written to
// LPVOID lpBaseAddress, // address to start writing to
// LPVOID lpBuffer, // pointer to buffer to write data to
// DWORD nSize, // number of bytes to write
// LPDWORD lpNumberOfBytesWritten // actual number of bytes written
// );
[DllImport("kernel32.dll")]
public static extern
Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, uint[] lpBuffer, UInt32 nSize, IntPtr lpNumberOfBytesWritten);
//BOOL ReadProcessMemory(
// HANDLE hProcess, // handle of the process whose memory is read
// LPCVOID lpBaseAddress, // address to start reading
// LPVOID lpBuffer, // address of buffer to place read data
// DWORD nSize, // number of bytes to read
// LPDWORD lpNumberOfBytesRead // address of number of bytes read
// );
[DllImport("kernel32.dll")]
public static extern
Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, uint[] lpBuffer, UInt32 nSize, IntPtr lpNumberOfBytesRead);
}
本程序代码测试环境:
WinXP (Professional SP2)
Microsoft Visual Studio 2005 (Installed Edition: C# Express)
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727