Beispiel #1
0
        public static ModuleInfo[] EnumModules(int pid)
        {
            using (var handle = Win32.CreateToolhelp32Snapshot(CreateToolhelpSnapshotFlags.SnapModules |
                                                               (Environment.Is64BitProcess ? CreateToolhelpSnapshotFlags.SnapModules32 : CreateToolhelpSnapshotFlags.None), pid)) {
                if (handle.DangerousGetHandle() == Win32.InvalidFileHandle)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                var modules = new List <ModuleInfo>(128);
                var me      = new ModuleEntry();
                me.Init();

                if (!Win32.Module32First(handle, ref me))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                do
                {
                    modules.Add(new ModuleInfo {
                        Pid         = pid,
                        Name        = me.szModule,
                        FullPath    = me.szExePath,
                        BaseAddress = me.modBaseAddr,
                        Size        = me.modBaseSize,
                        Handle      = me.hModule
                    });
                } while (Win32.Module32Next(handle, ref me));

                return(modules.ToArray());
            }
        }
Beispiel #2
0
 internal static extern bool Module32Next(SafeFileHandle hSnapshot, ref ModuleEntry pe);