使用方法:
结果如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace std
{
public partial class Memory : Object
{
[DllImportAttribute("kernel32.dll", EntryPoint = "WriteProcessMemory")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
static extern bool WriteProcessMemory(
[InAttribute()] IntPtr hProcess,
[InAttribute()] IntPtr lpBaseAddress,
[InAttribute()] byte[] lpBuffer,
int nSize,
IntPtr lpNumberOfBytesWritten
);
[DllImportAttribute("kernel32.dll", EntryPoint = "ReadProcessMemory")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
static extern bool ReadProcessMemory(
[InAttribute()] IntPtr hProcess,
[InAttribute()] IntPtr lpBaseAddress,
[InAttribute()] IntPtr lpBuffer,
uint nSize,
IntPtr lpNumberOfBytesRead
);
[DllImportAttribute("kernel32.dll", EntryPoint = "OpenProcess")]
static extern IntPtr OpenProcess(
uint dwDesiredAccess,
[MarshalAsAttribute(UnmanagedType.Bool)] bool bInheritHandle,
uint dwProcessId
);
[DllImportAttribute("kernel32.dll", EntryPoint = "GetCurrentProcessId")]
static extern uint GetCurrentProcessId();
[DllImportAttribute("kernel32.dll", EntryPoint = "CloseHandle")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
static extern bool CloseHandle(
[InAttribute()] IntPtr hObject
);
[DllImportAttribute("ntdll.dll", EntryPoint = "RtlCopyMemory")]
static extern uint RtlCompareMemory(
[InAttribute()] IntPtr Source1,
[InAttribute()] IntPtr Source2,
uint Length
);
[DllImportAttribute("Psapi.dll", EntryPoint = "GetModuleFileNameEx")]
static extern uint GetModuleFileNameExA(
[InAttribute()] IntPtr hProcess,
[InAttribute()] IntPtr hModule,
[OutAttribute(), MarshalAsAttribute(UnmanagedType.LPStr)] StringBuilder lpFilename,
[InAttribute()] uint nSize
);
[DllImpo