// ==================================
// filename: ListModules2.cpp
// compiler: vs2008
// author  : EdisonX (Edison.Shih.)
//   
//   **** all rights reserve ****
// ==================================
#include <windows.h>
#include <stdio.h>
#include <Psapi.h>
#pragma comment(lib, "psapi.lib")

BOOL ListModule(DWORD PID)
{
        HMODULE hModule[1000];
        HANDLE hProcess;
        DWORD Bytes, cnt, i;
        char BaseName[MAX_PATH];
        char FileName[MAX_PATH];

        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ ,FALSE, PID);

        if(hProcess==NULL){
                printf("Open Process fail.\n");
                return FALSE;
        }
        if(!EnumProcessModules(hProcess,hModule,sizeof(hModule),&Bytes)) {
                printf("Enum process Modules fail.\n");
                CloseHandle(hProcess);
                return FALSE;
        }

        cnt = Bytes / sizeof(HMODULE);

        for(i=0; i<cnt; i++){
               
                // 取得相關訊息
                GetModuleBaseName(hProcess, hModule[i], BaseName, MAX_PATH); // 縮名
                GetModuleFileNameEx(hProcess, hModule[i], FileName, MAX_PATH); // 全名

                MODULEINFO modinfo;
                GetModuleInformation(hProcess, hModule[i],&modinfo, Bytes);
               
                // 顯示相關訊息
                printf("\n=================================\n");
                printf("BaseName:%s\n", BaseName);
                printf("FileName:%s\n", FileName);
        }
        CloseHandle(hProcess);
        return TRUE;
}

int main()
{
        DWORD pid = GetCurrentProcessId();
        ListModule(pid);
        return 0;
}

 

edisonx 發表在 痞客邦 PIXNET 留言(0) 人氣()