public static bool SetDebugPrivileges() { IntPtr zero = IntPtr.Zero; MemoryApi.LUID luid = default(MemoryApi.LUID); luid.HighPart = 0; luid.LowPart = 0u; MemoryApi.TOKEN_PRIVILEGES tOKEN_PRIVILEGES = default(MemoryApi.TOKEN_PRIVILEGES); IntPtr currentProcess = MemoryApi.GetCurrentProcess(); if (!MemoryApi.OpenProcessToken(currentProcess, 40u, out zero)) { return(false); } if (!MemoryApi.LookupPrivilegeValue("", "SeDebugPrivilege", out luid)) { return(false); } tOKEN_PRIVILEGES.PrivilegeCount = 1u; tOKEN_PRIVILEGES.Luid = luid; tOKEN_PRIVILEGES.Attributes = 2u; return(MemoryApi.AdjustTokenPrivileges(zero, false, ref tOKEN_PRIVILEGES, 0u, IntPtr.Zero, IntPtr.Zero) && MemoryApi.CloseHandle(zero) != 0); }
public bool CloseProcess() { if (MemoryApi.CloseHandle(this.ProcessHwnd) == 0) { return(false); } this.ProcessToRead = new Process(); this.ProcessHwnd = IntPtr.Zero; return(true); }
private int WriteProcessMemory(UIntPtr MemoryAddress, byte[] buffer) { uint size = (uint)buffer.Length; if (this.ProcessToRead == null) { throw new ArgumentNullException("Process too writing too is null"); } IntPtr intPtr; return(MemoryApi.WriteProcessMemory(this.ProcessHwnd, MemoryAddress, buffer, size, out intPtr)); }
private byte[] ReadProcessMemory(UIntPtr MemoryAddress, uint bytesToRead) { byte[] array = new byte[bytesToRead]; if (this.ProcessToRead == null) { return(array); } IntPtr intPtr; MemoryApi.ReadProcessMemory(this.ProcessHwnd, MemoryAddress, array, bytesToRead, out intPtr); return(array); }
private void OpenProcess(uint Mode) { if (this.ProcessToRead != null) { this.ProcessHwnd = MemoryApi.OpenProcess(Mode, 1, (uint)this.ProcessToRead.Id); return; } else { throw new ArgumentNullException("Process to open is null"); } }