mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-19 04:49:25 +08:00
9a231073a5
The default PSAPI_VERSION is controlled by WIN32_WINNT, which we set to 0x0a00 when building utils since 48a76190 (and is the default in w32api >= 9.0.0) In order for the built executables to run on Windows Vista, we must also define PSAPI_VERSION as 1 (otherwise '#define GetModuleFileNameExA K32GetModuleFileNameExA' causes a 'The procedure entry point K32GetModuleFilenameExA could not be located in the dynamic link library kernel32.dll' error at run time). Also drop uneeded psapi.h from dlfcn.cc (31ddf45d), resource.cc (34a6eeab) and ps.cc (1def2148).
72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
/* module_info.cc
|
|
|
|
Written by Egor Duda <deo@logos-m.ru>
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#include <stdlib.h>
|
|
#include <windows.h>
|
|
#define PSAPI_VERSION 1
|
|
#include <psapi.h>
|
|
#include "loadlib.h"
|
|
|
|
/* Returns full name of Dll, which is loaded by hProcess at BaseAddress.
|
|
Uses psapi.dll. */
|
|
|
|
char *
|
|
psapi_get_module_name (HANDLE hProcess, LPVOID BaseAddress)
|
|
{
|
|
DWORD len;
|
|
MODULEINFO mi;
|
|
unsigned int i;
|
|
HMODULE dh_buf[1];
|
|
HMODULE *DllHandle = dh_buf;
|
|
DWORD cbNeeded;
|
|
BOOL ok;
|
|
|
|
char name_buf[MAX_PATH + 1];
|
|
|
|
ok = EnumProcessModules (hProcess, DllHandle, sizeof (HMODULE), &cbNeeded);
|
|
|
|
if (!ok || !cbNeeded)
|
|
goto failed;
|
|
DllHandle = (HMODULE *) malloc (cbNeeded);
|
|
if (!DllHandle)
|
|
goto failed;
|
|
ok = EnumProcessModules (hProcess, DllHandle, cbNeeded, &cbNeeded);
|
|
if (!ok)
|
|
{
|
|
free (DllHandle);
|
|
goto failed;
|
|
}
|
|
|
|
for (i = 0; i < cbNeeded / sizeof (HMODULE); i++)
|
|
{
|
|
if (!GetModuleInformation (hProcess, DllHandle[i], &mi, sizeof (mi)))
|
|
{
|
|
free (DllHandle);
|
|
goto failed;
|
|
}
|
|
|
|
len = GetModuleFileNameExA (hProcess, DllHandle[i], name_buf, MAX_PATH);
|
|
if (len == 0)
|
|
{
|
|
free (DllHandle);
|
|
goto failed;
|
|
}
|
|
|
|
if (mi.lpBaseOfDll == BaseAddress)
|
|
{
|
|
free (DllHandle);
|
|
return strdup (name_buf);
|
|
}
|
|
}
|
|
|
|
failed:
|
|
return NULL;
|
|
}
|