/[RomCheater]/trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs
ViewVC logotype

Diff of /trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/21 20:45:35	410
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/21 21:07:34	411
@@ -23,19 +23,18 @@
     {
         // constants information can be found in <winnt.h>
         [Flags]
-        public enum ProcessAccessType
+        enum ProcessAccessFlags : uint
         {
-            PROCESS_TERMINATE = (0x0001),
-            PROCESS_CREATE_THREAD = (0x0002),
-            PROCESS_SET_SESSIONID = (0x0004),
-            PROCESS_VM_OPERATION = (0x0008),
-            PROCESS_VM_READ = (0x0010),
-            PROCESS_VM_WRITE = (0x0020),
-            PROCESS_DUP_HANDLE = (0x0040),
-            PROCESS_CREATE_PROCESS = (0x0080),
-            PROCESS_SET_QUOTA = (0x0100),
-            PROCESS_SET_INFORMATION = (0x0200),
-            PROCESS_QUERY_INFORMATION = (0x0400)
+            All = 0x001F0FFF,
+            Terminate = 0x00000001,
+            CreateThread = 0x00000002,
+            VMOperation = 0x00000008,
+            VMRead = 0x00000010,
+            VMWrite = 0x00000020,
+            DupHandle = 0x00000040,
+            SetInformation = 0x00000200,
+            QueryInformation = 0x00000400,
+            Synchronize = 0x00100000
         }
         [Flags]
         public enum AllocationProtect : uint
@@ -99,13 +98,13 @@
                 //{
                 //    logger.Warn.WriteLine("Failed to set SeDebugPrivilege on current process");
                 //}
-                ProcessAccessType access;
-                access = ProcessAccessType.PROCESS_VM_READ
-                    | ProcessAccessType.PROCESS_VM_WRITE
-                    | ProcessAccessType.PROCESS_VM_OPERATION;
+                ProcessAccessFlags access;
+                access = ProcessAccessFlags.VMRead
+                    | ProcessAccessFlags.VMWrite
+                    | ProcessAccessFlags.VMOperation;
                 //m_hProcess = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
-                handle = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
-                m_hProcess = new SafeWaitHandle(handle, false);
+                handle = ProcessMemoryReaderApi.OpenProcess(access, true, m_ReadProcess.Id);
+                //m_hProcess = new SafeWaitHandle(handle, false);
             }
             catch (SEHException ex)
             {
@@ -124,20 +123,22 @@
         {
             try
             {
-                //if (handle.IsInvalid) { return; }
-                //if (handle.IsClosed) { return; }
-                m_hProcess.Close();
-                m_hProcess.Dispose();
-                m_hProcess = null;
-                handle = IntPtr.Zero;
-                m_ReadProcess = null;
+                ////if (handle.IsInvalid) { return; }
+                ////if (handle.IsClosed) { return; }
+                //m_hProcess.Close();
+                //m_hProcess.Dispose();
+                //m_hProcess = null;
+                //handle = IntPtr.Zero;
+                //m_ReadProcess = null;
                 //string stack_trace = System.Environment.StackTrace;
-                //int iRetValue;
-                //iRetValue = ProcessMemoryReaderApi.CloseHandle(m_hProcess);
-                //if (iRetValue == 0)
-                //{
-                //    throw new Exception("CloseHandle failed");
-                //}
+                int iRetValue;
+                iRetValue = ProcessMemoryReaderApi.CloseHandle(handle);
+                handle = IntPtr.Zero;
+                ReadProcess = null;
+                if (iRetValue == 0)
+                {
+                    throw new Exception("CloseHandle failed");
+                }
             }
             catch (SEHException ex)
             {
@@ -167,7 +168,7 @@
             //			DWORD dwProcessId       // process identifier
             //			);
             [DllImport("kernel32.dll")]
-            public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
+            public static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
 
             //		BOOL CloseHandle(
             //			HANDLE hObject   // handle to object

 

  ViewVC Help
Powered by ViewVC 1.1.22