Displays the code _c language for any process-loaded DLL file

Source: Internet
Author: User
Copy Code code as follows:

#include <windows.h>
#include <iostream.h>
#include <tlhelp32.h>
#include <stdio.h>
int main (int argc, char* argv[])
{
Char exename[500];
printf ("[ENTER EXE FILE name]\t");
scanf ("%s", exename);
printf ("\n[you enter]\t%s\n", exename);
Sleep (3000);
Elevate the permissions of the current process so that it has permission to manipulate other processes
HANDLE Htoken;
Luid Sedebugnamevalue;
Token_privileges TKP;
if (! OpenProcessToken (GetCurrentProcess (),
Token_adjust_privileges | Token_query, &htoken)) {
WriteToLog ("OpenProcessToken error");
return 1;
}
if (! Lookupprivilegevalue (NULL, Se_debug_name, &sedebugnamevalue)) {
CloseHandle (Htoken);
WriteToLog ("Lookuprivilegevalue error");
return 1;
}
TKP. Privilegecount = 1;
TKP. Privileges[0]. Luid = Sedebugnamevalue;
TKP. Privileges[0]. Attributes = se_privilege_enabled;
if (! AdjustTokenPrivileges (Htoken, FALSE, &AMP;TKP, sizeof TKP, NULL, NULL)) {
CloseHandle (Htoken);
return 1;
}
Get the PID of the target process
DWORD pid;
HANDLE snapshot;
Snapshot=createtoolhelp32snapshot (th32cs_snapprocess,0);
struct TAGPROCESSENTRY32 processsnap;
Processsnap.dwsize=sizeof (TAGPROCESSENTRY32);
For (Process32First (SNAPSHOT,&AMP;PROCESSSNAP); Process32Next (SNAPSHOT,&AMP;PROCESSSNAP);) {
if (!stricmp (processsnap.szexefile,exename))
{
Pid=processsnap.th32processid;
Break
}
}
CloseHandle (snapshot);
////////////////////////////////////////
MODULEENTRY32 pe32;

Before you use this structure, set its size
pe32.dwsize = sizeof (PE32);

Take a snapshot of all the modules in the process
276 for the ID of a process
HANDLE Hprocesssnap = CreateToolhelp32Snapshot (th32cs_snapmodule,pid);

if (Hprocesssnap = = INVALID_HANDLE_VALUE)
{
Failed to establish snapshot
return-1;
printf ("[CreateToolhelp32Snapshot error]\n");
}

Iterate through the process snapshots, displaying information for each process in turn
BOOL bmore = Module32first (Hprocesssnap, &pe32);
while (bmore)
{
printf ("\n[dll name]\t%s\n", pe32.szmodule);
printf ("[DLL path]\t%s\n", Pe32.szexepath);


Bmore = Module32next (Hprocesssnap, &pe32);
}
Don't forget to clear off the snapshot object
CloseHandle (HPROCESSSNAP);


return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.