begin process at 2008 08 21 20:44:46
1 229 631 membres
443 nouveaux aujourd'hui
14 264 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

[DEV-C++][G++] LISTER LES DLL CHARGÉES PAR PROCESSUS...


Information sur la source

Catégorie :API Niveau : Initié Date de création : 26/05/2003 Date de mise à jour : 26/05/2003 13:41:55 Vu / téléchargé: 3 668 / 293

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

Description

Ce programme liste (en mode console) les DLL chargées par processus.
Il a été compilé avec G++ au sein de l'environnement DEV-C++, et testé sous Windows 2000.
Il utilse la classe NString de NitRic et nécessite la librairie libth32.a

XoowPS.exe -h retourne l'aide de la ligne de commande.

Source

  • #include <iostream>
  • #include <iomanip>
  • #include <windows.h>
  • #include <tlhelp32.h>
  • #include <string.h>
  • #include "nstring.h"
  • #include "res/resource.h"
  • #include "argparser.h"
  • void AfficheDLLParProcessus(int nopid)
  • {
  • HANDLE hSnapShot1;
  • PROCESSENTRY32 uProcess;
  • HANDLE hSnapShot2;
  • MODULEENTRY32 me32;
  • String DllLoaded = "";
  • bool bResult;
  • bool r;
  • hSnapShot1 = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  • uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);
  • r = Process32First(hSnapShot1, &uProcess);
  • while ( r ) // Cette boucle énnumère tout les processus
  • {
  • r = Process32Next(hSnapShot1, &uProcess);
  • if ((uProcess.th32ProcessID == nopid) || (nopid == 0))
  • {
  • if (uProcess.th32ProcessID < 99999) {
  • String myProcessName = uProcess.szExeFile;
  • myProcessName.ToLower();
  • std::cout << std::setw(4) << uProcess.th32ProcessID << " " << myProcessName << std::endl;
  • hSnapShot2 = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, uProcess.th32ProcessID );
  • if ((int)hSnapShot2 != -1 )
  • {
  • me32.dwSize = sizeof(me32);
  • bResult = Module32First( hSnapShot2, &me32 );
  • while( bResult )
  • {
  • DllLoaded = me32.szExePath;
  • DllLoaded.ToLower();
  • std::cout << std::setw(4) << " " << DllLoaded << std::endl;
  • bResult = Module32Next( hSnapShot2, &me32 );
  • }
  • }
  • if( hSnapShot2 ) CloseHandle( hSnapShot2 );
  • //std::cout << std::endl;
  • }
  • }
  • };
  • CloseHandle(hSnapShot1);
  • }
  • void AfficheProcessusPourDLL(String myDllName)
  • {
  • HANDLE hSnapShot1;
  • PROCESSENTRY32 uProcess;
  • HANDLE hSnapShot2;
  • MODULEENTRY32 me32;
  • String DllLoaded = "";
  • String DllLoadedName = "";
  • String DllLoadedPath = "";
  • bool bResult;
  • bool r;
  • short NbProcess = 0;
  • hSnapShot1 = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  • uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);
  • r = Process32First(hSnapShot1, &uProcess);
  • while ( r ) // Cette boucle énnumère tout les processus
  • {
  • r = Process32Next(hSnapShot1, &uProcess);
  • if (uProcess.th32ProcessID < 99999) {
  • String myProcessName = uProcess.szExeFile;
  • myProcessName.ToLower();
  • hSnapShot2 = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, uProcess.th32ProcessID );
  • if ((int)hSnapShot2 != -1 )
  • {
  • me32.dwSize = sizeof(me32);
  • bResult = Module32First( hSnapShot2, &me32 );
  • while( bResult )
  • {
  • DllLoaded = me32.szExePath;
  • DllLoaded.ToLower();
  • DllLoadedName = me32.szModule;
  • DllLoadedName.ToLower();
  • if (DllLoadedName == myDllName)
  • {
  • if (NbProcess++ == 0)
  • {
  • std::cout << "Le module DLL '" << DllLoadedName << "' ";
  • std::cout << "a pour chemin '" << DllLoaded << "' ";
  • std::cout << "et est utilisee par les processus suivants :" << std::endl;
  • }
  • std::cout << "- " << std::setw(4) << uProcess.th32ProcessID << " " << myProcessName << std::endl;
  • }
  • bResult = Module32Next( hSnapShot2, &me32 );
  • }
  • }
  • if( hSnapShot2 ) CloseHandle( hSnapShot2 );
  • }
  • };
  • CloseHandle(hSnapShot1);
  • }
  • int main(int argc, char *argv[])
  • {
  • /* --- VARIABLES ---*/
  • int pid = 0;
  • String dllname = "";
  • /* --- FIN VARIABLES ---*/
  • try
  • {
  • parse(argc,argv)
  • .withDescription("Liste les DLL chargées pour chaque processus.")
  • .forParameter('p',"pid", pid, "liste les DLL chargees pour le processus", false)
  • .forParameter('d',"dll", dllname, "liste les processus utilisant la DLL specifiee", false);
  • if (pid) AfficheDLLParProcessus(pid);
  • if ((pid==0) && (dllname == "")) AfficheDLLParProcessus(0);
  • if (dllname != "") AfficheProcessusPourDLL(dllname);
  • }
  • catch (Argument::error e) // Now we treat gracefully the argument errors!
  • {
  • std::cout<<e.what()<<std::endl<<"use -h or --help for details"<<std::endl;
  • exit(1);
  • }
  • return 0;
  • }
#include <iostream>
#include <iomanip>
#include <windows.h>
#include <tlhelp32.h>
#include <string.h>
#include "nstring.h"
#include "res/resource.h"
#include "argparser.h"

void AfficheDLLParProcessus(int nopid)
{
    HANDLE hSnapShot1;
    PROCESSENTRY32 uProcess;
    HANDLE hSnapShot2;
    MODULEENTRY32 me32;
    String DllLoaded = "";
    bool bResult;
    bool r;
    
    hSnapShot1 = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);

    uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);

    r = Process32First(hSnapShot1, &uProcess);
       
    while ( r )  // Cette boucle énnumère tout les processus
    {
        r = Process32Next(hSnapShot1, &uProcess);
        
        if ((uProcess.th32ProcessID == nopid) || (nopid == 0)) 
        {        
        if (uProcess.th32ProcessID < 99999) {
        String myProcessName = uProcess.szExeFile;
        myProcessName.ToLower();
        std::cout << std::setw(4) << uProcess.th32ProcessID << " " << myProcessName << std::endl;
        
          hSnapShot2 = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, uProcess.th32ProcessID );
          
       if ((int)hSnapShot2 != -1 )
       {
              me32.dwSize = sizeof(me32);
              bResult = Module32First( hSnapShot2, &me32 );
              while( bResult )
              {

                            DllLoaded = me32.szExePath;
                            DllLoaded.ToLower();
                            std::cout << std::setw(4) << " " << DllLoaded << std::endl;
                            bResult = Module32Next( hSnapShot2, &me32 );
              }
       }
       
       if( hSnapShot2 ) CloseHandle( hSnapShot2 );
       //std::cout << std::endl;
       }
       }
    };
    
    CloseHandle(hSnapShot1);
}


void AfficheProcessusPourDLL(String myDllName)
{
    HANDLE hSnapShot1;
    PROCESSENTRY32 uProcess;
    HANDLE hSnapShot2;
    MODULEENTRY32 me32;
    String DllLoaded = "";
    String DllLoadedName = "";
    String DllLoadedPath = "";
    bool bResult;
    bool r;
    short NbProcess = 0;
    
    hSnapShot1 = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);

    uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);

    r = Process32First(hSnapShot1, &uProcess);
       
    while ( r )  // Cette boucle énnumère tout les processus
    {
        r = Process32Next(hSnapShot1, &uProcess);
        
        if (uProcess.th32ProcessID < 99999) {
        String myProcessName = uProcess.szExeFile;
        myProcessName.ToLower();
        
          hSnapShot2 = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, uProcess.th32ProcessID );
          
       if ((int)hSnapShot2 != -1 )
       {
              me32.dwSize = sizeof(me32);
              bResult = Module32First( hSnapShot2, &me32 );
              while( bResult )
              {

                            DllLoaded = me32.szExePath;
                            DllLoaded.ToLower();
                            DllLoadedName = me32.szModule;
                            DllLoadedName.ToLower();
                            if (DllLoadedName == myDllName)
                            {
                            if (NbProcess++ == 0) 
                            {
                                std::cout << "Le module DLL '" << DllLoadedName << "' ";
                                std::cout << "a pour chemin '" << DllLoaded << "' ";
                                std::cout << "et est utilisee par les processus suivants :" << std::endl;
                            }
                            std::cout << "- " << std::setw(4) << uProcess.th32ProcessID << " " << myProcessName << std::endl;
                            }
                            bResult = Module32Next( hSnapShot2, &me32 );
                            
              }
       }
       
       if( hSnapShot2 ) CloseHandle( hSnapShot2 );
       }
    };
    
    CloseHandle(hSnapShot1);
}


int main(int argc, char *argv[])
{
    /* --- VARIABLES ---*/
    int pid = 0; 
    String dllname = "";
    /* --- FIN VARIABLES ---*/    
    
    try
    {
        parse(argc,argv)
                .withDescription("Liste les DLL chargées pour chaque processus.")
                .forParameter('p',"pid", pid, "liste les DLL chargees pour le processus", false)
                .forParameter('d',"dll", dllname, "liste les processus utilisant la DLL specifiee", false);
    
        if (pid) AfficheDLLParProcessus(pid);
        if ((pid==0) && (dllname == "")) AfficheDLLParProcessus(0);
        if (dllname != "") AfficheProcessusPourDLL(dllname);
    }
    catch (Argument::error e)  // Now we treat gracefully the argument errors!
    {
        std::cout<<e.what()<<std::endl<<"use -h or --help for details"<<std::endl;
        exit(1);
    }   
    
    return 0;
}
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

  • signaler à un administrateur
    Commentaire de HotSpot le 27/05/2003 10:54:50

    je le savais pas .. merci ..

Ajouter un commentaire

Pub



Appels d'offres

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Boutique

Boutique de goodies CodeS-SourceS