【问题标题】:Just want an executable to enumarate processes and enumarate loaded .dlls只需要一个可执行文件来枚举进程并枚举加载的 .dll
【发布时间】:2013-05-27 07:29:33
【问题描述】:

我想制作一个函数,其中包含进程名称的参数stdvector::<std::string> 和 .dll 的 std::vector<std::string>,以便在其中找到并将其输入到函数中并获得类似 PROCESSENTRY32 info std::vector<PROCESSENTRY32> 返回的任何与名字。

你可以用谷歌搜索,但找不到太多,感谢你帮助 winapi 新手,但不是为了弄清楚事情

【问题讨论】:

    标签: winapi dll process proxy


    【解决方案1】:

    有一个完美的例子来做你想做的事on MSDN here。相关代码复制如下。正如样本介绍所说的那样

    要确定哪些进程加载了特定的 DLL,您必须枚举每个进程的模块。以下示例代码使用EnumProcessModules函数枚举系统中当前进程的模块。

    现在是示例代码

    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    #include <psapi.h>
    
    // To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
    // and compile with -DPSAPI_VERSION=1
    
    int PrintModules( DWORD processID )
    {
        HMODULE hMods[1024];
        HANDLE hProcess;
        DWORD cbNeeded;
        unsigned int i;
    
        // Print the process identifier.
        printf( "\nProcess ID: %u\n", processID );
    
        // Get a handle to the process.
        hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
            FALSE, processID );
        if (NULL == hProcess)
            return 1;
    
        // Get a list of all the modules in this process.
        if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
        {
            for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
            {
                TCHAR szModName[MAX_PATH];
    
                // Get the full path to the module's file.
                if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
                    sizeof(szModName) / sizeof(TCHAR)))
                {
                    // Print the module name and handle value.
                    _tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
                }
            }
        }
    
        // Release the handle to the process.
        CloseHandle( hProcess );
    
        return 0;
    }
    
    int main( void )
    {
    
        DWORD aProcesses[1024]; 
        DWORD cbNeeded; 
        DWORD cProcesses;
        unsigned int i;
    
        // Get the list of process identifiers.
        if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
            return 1;
    
        // Calculate how many process identifiers were returned.
        cProcesses = cbNeeded / sizeof(DWORD);
    
        // Print the names of the modules for each process.
        for ( i = 0; i < cProcesses; i++ )
        {
            PrintModules( aProcesses[i] );
        }
    
        return 0;
    }
    

    您需要做的唯一更改是事先将std::vector&lt;std::string&gt; 感兴趣的模块名称更改为std::vector&lt;std::string&gt;,然后使用枚举的模块名称搜索该向量,而不是打印它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多