zoukankan      html  css  js  c++  java
  • Enumerating All Modules For a Process

    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    #include <psapi.h>
    
    void 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 list of all the modules in this process.
    
        hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                                PROCESS_VM_READ,
                                FALSE, processID );
        if (NULL == hProcess)
            return;
    
        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] );
                }
            }
        }
    
        CloseHandle( hProcess );
    }
    
    void main( )
    {
        // Get the list of process identifiers.
    
        DWORD aProcesses[1024], cbNeeded, cProcesses;
        unsigned int i;
    
        if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
            return;
    
        // Calculate how many process identifiers were returned.
    
        cProcesses = cbNeeded / sizeof(DWORD);
    
        // Print the name of the modules for each process.
    
        for ( i = 0; i < cProcesses; i++ )
            PrintModules( aProcesses[i] );
    }
     


    作者:GangWang
    出处:http://www.cnblogs.com/GnagWang/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

     
  • 相关阅读:
    Json -- 语法和示例,javascript 解析Json
    平衡二叉树的实现原理
    递归:汉诺塔
    递归:这帮坑爹的小兔崽子
    函数:递归是神马
    函数:lambda表达式
    函数:内嵌函数和闭包
    函数:我的地盘听我的
    函数:灵活即强大
    函数:Python的乐高积木
  • 原文地址:https://www.cnblogs.com/GnagWang/p/1796416.html
Copyright © 2011-2022 走看看