Esempio n. 1
0
        /// <summary>
        /// Similar to System.Diagnostics.WinProcessManager.GetModuleInfos,
        /// except that we include 32 bit modules when we run in x64 mode.
        /// See http://blogs.msdn.com/b/jasonz/archive/2007/05/11/code-sample-is-your-process-using-the-silverlight-clr.aspx
        /// </summary>
        private IEnumerable <NativeMethods.MODULEENTRY32> GetModules()
        {
            int processId;

            NativeMethods.GetWindowThreadProcessId(Hwnd, out processId);

            var me32        = new NativeMethods.MODULEENTRY32();
            var hModuleSnap = NativeMethods.CreateToolhelp32Snapshot(
                NativeMethods.SnapshotFlags.Module | NativeMethods.SnapshotFlags.Module32,
                processId);

            if (!hModuleSnap.IsInvalid)
            {
                using (hModuleSnap)
                {
                    me32.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(me32);
                    if (NativeMethods.Module32First(hModuleSnap, ref me32))
                    {
                        do
                        {
                            yield return(me32);
                        } while (NativeMethods.Module32Next(hModuleSnap, ref me32));
                    }
                }
            }
        }
Esempio n. 2
0
        private static IEnumerable <NativeMethods.MODULEENTRY32> GetModulesFromValidSnap(NativeMethods.ToolHelpHandle hModuleSnap)
        {
            var me32 = new NativeMethods.MODULEENTRY32();

            using (hModuleSnap)
            {
                me32.dwSize = (uint)Marshal.SizeOf(me32);
                if (NativeMethods.Module32First(hModuleSnap, ref me32))
                {
                    do
                    {
                        yield return(me32);
                    } while (NativeMethods.Module32Next(hModuleSnap, ref me32));
                }
            }
        }
Esempio n. 3
0
        public static void DumpTo(this NativeMethods.MODULEENTRY32 module, StringBuilder builder, int tabCount)
        {
            var converter = new ModuleEntryConverter();

            converter.GetProperties(module)
            .Cast <PropertyDescriptor>()
            .OrderBy(pd => pd.Name)
            .Select(pd => new
            {
                Name  = pd.Name,
                Value = pd.GetValue(module).ToString()
            })
            .Aggregate((acc, pair) =>
            {
                builder.AppendFormattedLine(tabCount, "{0} = {1}",
                                            pair.Name, pair.Value);
                return(pair);
            });
        }
Esempio n. 4
0
 public static void DumpTo(this NativeMethods.MODULEENTRY32 module, StringBuilder builder)
 {
     DumpTo(module, builder, 0);
 }
Esempio n. 5
0
        /// <summary>
        /// Similar to System.Diagnostics.WinProcessManager.GetModuleInfos,
        /// except that we include 32 bit modules when we run in x64 mode.
        /// See http://blogs.msdn.com/b/jasonz/archive/2007/05/11/code-sample-is-your-process-using-the-silverlight-clr.aspx
        /// </summary>
        private IEnumerable<NativeMethods.MODULEENTRY32> GetModules()
        {
            int processId;
            NativeMethods.GetWindowThreadProcessId(Hwnd, out processId);

            var me32 = new NativeMethods.MODULEENTRY32();
            var hModuleSnap = NativeMethods.CreateToolhelp32Snapshot(
                NativeMethods.SnapshotFlags.Module | NativeMethods.SnapshotFlags.Module32,
                processId);

            if (!hModuleSnap.IsInvalid)
            {
                using (hModuleSnap)
                {
                    me32.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(me32);
                    if (NativeMethods.Module32First(hModuleSnap, ref me32))
                    {
                        do
                        {
                            yield return me32;
                        } while (NativeMethods.Module32Next(hModuleSnap, ref me32));
                    }
                }
            }
        }