//将值写入指定内存地址中 public void WriteMemoryValue(int baseAddress, string processName, int value) { IntPtr hProcess = Windows32API.OpenProcess(0x1F0FFF, false, GetPid(processName)); //0x1F0FFF 最高权限 Windows32API.WriteProcessMemory(hProcess, (IntPtr)baseAddress, new int[] { value }, 4, IntPtr.Zero); Windows32API.CloseHandle(hProcess); }
public void Inject(int handle, byte[] bytes) { var addr = Windows32API.VirtualAllocEx(handle, 0, bytes.Length, 0x1000, 0x40); Windows32API.WriteProcessMemory(handle, addr, bytes, bytes.Length, 0); int threadId = 0; int hThread = Windows32API.CreateRemoteThread(handle, 0, 0, addr, 0, 0, ref threadId); Windows32API.VirtualFreeEx(handle, addr, 0, 0x8000); Windows32API.CloseHandle(hThread); }