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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

     
  • 相关阅读:
    JavaScript日期处理类库momentjs
    sublime text 2 学习
    node.js代理设置
    使用nodejs将html5 canvas base64编码图片保存为文件
    Sublime Text 2 常用插件介绍
    把silverlight treeview 节点前面的小三角换成自定义的图片
    文件监控
    linux内核中的红黑树代码解析
    static关键字
    红黑树的实现(二)
  • 原文地址:https://www.cnblogs.com/GnagWang/p/1796416.html
Copyright © 2011-2022 走看看