Exemple #1
0
        public static ModuleEntry[] GetModules(uint processID)
        {
            List <ModuleEntry> moduleList = new List <ModuleEntry>();

            IntPtr handle = ToolhelpAPI.CreateToolhelp32Snapshot(ToolhelpAPI.TH32CS_SNAPMODULE, processID);

            if ((int)handle > 0)
            {
                try
                {
                    MODULEENTRY32 meCurrent;
                    MODULEENTRY32 me32 = new MODULEENTRY32();

                    //Get byte array to pass to the API calls
                    byte[] meBytes = me32.ToByteArray();

                    //Get the first process
                    int retval = ToolhelpAPI.Module32First(handle, meBytes);

                    while (retval == 1)
                    {
                        //Convert bytes to the class
                        meCurrent = new MODULEENTRY32(meBytes);
                        //New instance
                        ModuleEntry module = new ModuleEntry(meCurrent);

                        moduleList.Add(module);

                        retval = ToolhelpAPI.Module32Next(handle, meBytes);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Exception: " + ex.Message);
                }

                //Close handle
                ToolhelpAPI.CloseToolhelp32Snapshot(handle);

                return(moduleList.ToArray());
            }
            else
            {
                throw new Exception("Unable to create snapshot");
            }
        }
Exemple #2
0
 public ModuleEntry[] GetModules()
 {
     return(ModuleEntry.GetModules(this.ProcessID));
 }