public void CloseHandle() { int iRetValue; iRetValue = PMC.CloseHandle(m_hProcess); if (iRetValue == 0) { throw new Exception("CloseHandle failed"); } }
public int ReadMem(int MemoryAddress, uint bytesToRead, out byte[] buffer) { IntPtr procHandle = PMC.OpenProcess(PMC.PROCESS_VM_READ | PMC.PROCESS_VM_WRITE | PMC.PROCESS_VM_OPERATION, 1, (uint)m_ReadProcess.Id); if (procHandle == IntPtr.Zero) { buffer = new byte[0]; return(0); } buffer = new byte[bytesToRead]; IntPtr ptrBytesReaded; PMC.ReadProcessMemory(procHandle, (IntPtr)MemoryAddress, buffer, bytesToRead, out ptrBytesReaded); PMC.CloseHandle(procHandle); return(ptrBytesReaded.ToInt32()); }
public int WriteMem(int MemoryAddress, byte[] buf) { IntPtr procHandle = PMC.OpenProcess(PMC.PROCESS_VM_READ | PMC.PROCESS_VM_WRITE | PMC.PROCESS_VM_OPERATION, 1, (uint)m_ReadProcess.Id); if (procHandle == IntPtr.Zero) { return(0); } uint oldProtect; PMC.VirtualProtectEx(procHandle, (IntPtr)MemoryAddress, (uint)buf.Length, PMC.PAGE_READWRITE, out oldProtect); IntPtr ptrBytesWritten; PMC.WriteProcessMemory(procHandle, (IntPtr)MemoryAddress, buf, (uint)buf.Length, out ptrBytesWritten); PMC.CloseHandle(procHandle); return(ptrBytesWritten.ToInt32()); }