Traversing the dynamic-link library (DLL) used by the program first requires traversing all processes, matching the process name with the process ID, and then outputting all the libraries (DLLs) that are used according to the process name.
In the example, Image.exe is a pre-boot program. The code contains code to traverse the process, and to output dynamic-link libraries (DLLs).
Code:
* * * main.cpp * * Created on:2014.06.08 * author:spike//*vs 2012*/#include <iostre am> #include <iomanip> #include <string> #include <map> #include <windows.h&
Gt
#include <TlHelp32.h> using namespace std;
BOOL Traverseprocesses (std::map<std::string, int>& _nameid) {PROCESSENTRY32 pe32;
pe32.dwsize = sizeof (PE32);
HANDLE Hprocesssnap = createtoolhelp32snapshot (th32cs_snapprocess, 0); if (Hprocesssnap = = Invalid_handle_value) {std::cout << "createtoolhelp32snapshot error!" << std::en
DL;;
return false;
BOOL bresult =process32first (Hprocesssnap, &pe32);
int num (0);
while (bresult) {std::string name = Pe32.szexefile;
int id = PE32.TH32PROCESSID; Std::cout << "[<< ++num <<"]: "<<" PRocess Name: "//More Highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus///<< Name <<
"" << "ProcessID:" << id<< Std::endl; _nameid.insert (std::p air<string, int> (name, id));
Dictionary Storage bresult = Process32Next (HPROCESSSNAP,&PE32);
} closehandle (HPROCESSSNAP);
return true;
BOOL Traversemodels (const std::string _name) {DWORD dwid;
/*printf ("Please enter the name of a process to traverse processmodels:");
std::string name;
Cin >> name;*/std::map<std::string, int> NameID;
if (!traverseprocesses (NameID)) {//variable process cout << "Print processes error!" << Endl;
} Dwid = Nameid[_name];
HANDLE Hmodulesnap = CreateToolhelp32Snapshot (Th32cs_snapmodule, Dwid); if (Hmodulesnap = = Invalid_handle_value) {printf ("Createtoolhelp32snapshoterror!
\ n ");
return false;
} MODULEENTRY32 module32;
module32.dwsize = sizeof (MODULE32);
BOOL bresult = Module32first (Hmodulesnap, &module32);
int num (0); while (bresult) {std::wcout << ["<< num++ <<"]: "<<" Module: "<< Std::left < < STD::SETW << module32.szmodule << "<< endl <<" Path: "<< module3
2.szExePath << Std::endl;
Bresult = Module32next (Hmodulesnap, &module32);
} closehandle (HMODULESNAP);
return true;
int main () {const std::string program ("Image.exe");
if (!traversemodels (program)) {cout << "Traverse Models error!" << Endl;
return 0; }
Output:
Author: csdn Blog spike_king