- #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;
}