ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/Win32/libWin32/Win32/Threading/ThreadControl.cs
(Generate patch)

Comparing trunk/Win32/libWin32/Win32/Threading/ThreadControl.cs (file contents):
Revision 99 by william, Wed May 9 20:52:20 2012 UTC vs.
Revision 100 by william, Thu May 10 09:03:13 2012 UTC

# Line 21 | Line 21 | namespace libWin32.Win32.Threading
21          public static extern bool OpenProcessToken(IntPtr ProcessHandle, UInt32 DesiredAccess, out IntPtr TokenHandle);
22          [DllImport("kernel32.dll", SetLastError = true)]
23          [return: MarshalAs(UnmanagedType.Bool)]
24 <        public static extern bool CloseHandle(IntPtr hObject);
24 >        public static extern bool CloseHandle(IntPtr hObject);
25 >        [DllImport("psapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
26 >        static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, [Out] StringBuilder lpBaseName, uint nSize);
27 >
28 >        [DllImport("psapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
29 >        public static extern int EnumProcessModules(IntPtr hProcess, [Out] IntPtr lphModule, uint cb, out uint lpcbNeeded);
30  
31          public static void SuspendProcess(int PID)
32          {
# Line 80 | Line 85 | namespace libWin32.Win32.Threading
85              }
86              return "";
87          }
88 +
89 +        public static string GetProcessFilename(Process proc)
90 +        {
91 +            string filename = "";
92 +            Process[] procs = new Process[] { proc };
93 +            int mainModuleIndex = 0;
94 +            foreach (Process p in procs)
95 +            {
96 +                // Setting up the variable for the second argument for EnumProcessModules
97 +                IntPtr[] hMods = new IntPtr[1024];
98 +
99 +                GCHandle gch = GCHandle.Alloc(hMods, GCHandleType.Pinned); // Don't forget to free this later
100 +                IntPtr pModules = gch.AddrOfPinnedObject();
101 +
102 +                // Setting up the rest of the parameters for EnumProcessModules
103 +                uint uiSize = (uint)(Marshal.SizeOf(typeof(IntPtr)) * (hMods.Length));
104 +                uint cbNeeded = 0;
105 +
106 +                if (EnumProcessModules(p.Handle, pModules, uiSize, out cbNeeded) == 1)
107 +                {
108 +                    Int32 uiTotalNumberofModules = (Int32)(cbNeeded / (Marshal.SizeOf(typeof(IntPtr))));
109 +
110 +                    for (int i = 0; i < (int)uiTotalNumberofModules; i++)
111 +                    {
112 +                        StringBuilder strbld = new StringBuilder(1024);
113 +
114 +                        GetModuleFileNameEx(p.Handle, hMods[i], strbld, (uint)(strbld.Capacity));
115 +                        filename = strbld.ToString();
116 +                        if (i == mainModuleIndex)
117 +                            break;
118 +                    }
119 +                    //Console.WriteLine("Number of Modules: " + uiTotalNumberofModules);
120 +                    //Console.WriteLine();
121 +                }
122 +
123 +                // Must free the GCHandle object
124 +                gch.Free();              
125 +            }
126 +            return filename;
127 +        }
128      }
129   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines