프로그래밍 팁

사용중인 DLL 주소 출력

바보 악마 2014. 9. 5. 15:12
#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;
}



출처 : http://del4u.tistory.com/39

[1] http://msdn.microsoft.com/en-us/library/ms682623(v=vs.85).aspx


'프로그래밍 팁' 카테고리의 다른 글

책그림 컴퓨터사이언스 부트캠프 with 파이썬  (0) 2018.03.09
그래프 그려주는 사이트  (0) 2015.03.16
IME Test   (0) 2013.12.13
liboauth  (0) 2013.07.29
openssl  (0) 2013.07.25