Example #1
0
        /// <summary>
        ///     Gets a value indicating whether the process is open for memory manipulation.
        /// </summary>
        /// <value>
        ///     <c>true</c> if the process is open for memory manipulation; otherwise, <c>false</c>.
        /// </value>
        /// <remarks>Created 2012-04-23</remarks>
        //public bool IsProcessOpen
        //{
        //    get { return ProcessHandle != null && !ProcessHandle.IsClosed && !ProcessHandle.IsInvalid; }
        //}

        /// <summary>
        ///     Initializes a new instance of the <see cref="MemoryManager" /> class.
        /// </summary>
        /// <param name="proc">The proc.</param>
        internal MemoryManager(Process proc)
        {
            if (proc.HasExited)
            {
                throw new AccessViolationException("Process: " + proc.Id + " has already exited. Can not attach to it.");
            }
            Process.EnterDebugMode();
            Process = proc;
            const ProcessAccessFlags a = ProcessAccessFlags.PROCESS_CREATE_THREAD |
                                         ProcessAccessFlags.PROCESS_QUERY_INFORMATION |
                                         ProcessAccessFlags.PROCESS_SET_INFORMATION | ProcessAccessFlags.PROCESS_TERMINATE |
                                         ProcessAccessFlags.PROCESS_VM_OPERATION | ProcessAccessFlags.PROCESS_VM_READ |
                                         ProcessAccessFlags.PROCESS_VM_WRITE | ProcessAccessFlags.SYNCHRONIZE;

            ProcessHandle = Imports.OpenProcess(a, false, proc.Id);
            ImageBase     = Process.MainModule.BaseAddress;
        }
Example #2
0
 public void Dispose()
 {
     try
     {
         if (ProcessHandle != null)
         {
             ProcessHandle.Dispose();
             ProcessHandle = null;
         }
         try
         {
             Process.LeaveDebugMode();
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex.ToString());
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
     }
 }
Example #3
0
 private static extern bool WriteProcessMemory(SafeMemHandle hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesWritten);
Example #4
0
 private static extern bool VirtualProtectEx(SafeMemHandle hProcess, IntPtr lpAddress, IntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
Example #5
0
 private static extern bool ReadProcessMemory(SafeMemHandle hProcess, IntPtr lpBaseAddress, byte *lpBuffer, int dwSize, out int lpNumberOfBytesRead);
Example #6
0
 internal static extern bool VirtualFreeEx(SafeMemHandle hProcess, IntPtr dwAddress, int nSize, MemoryFreeType dwFreeType);
Example #7
0
 internal static extern IntPtr VirtualAllocEx(SafeMemHandle hProcess, uint dwAddress, int nSize, MemoryAllocationType dwAllocationType, MemoryProtectionType dwProtect);