#include <windows.h>
#include <psapi.h>
#include <tchar.h>
#include <stdio.h>
// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1
#define ARRAY_SIZE 1024
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.
int len = lstrlenW(szModName);
if (len > 5)
{
for (int h = 0; h < len - lstrlenW(L"user32"); h++)
{
if (memcmp(&szModName[h], L"USER32", lstrlenW(L"USER32")) == 0 || memcmp(&szModName[h], L"user32", lstrlenW(L"user32")) == 0)
{
printf("\n USER32 detect");
char *TPTP = (char*)hMods[i];
if (FreeLibrary(hMods[i]))
{
printf("\n unload complited.");
}
else
{
DWORD Err = GetLastError();
printf("\n can't unload");
}
break;
}
}
}
_tprintf(TEXT("\t%s (0x%08X)\n"), szModName, hMods[i]);
}
}
}
// Release the handle to the process.
CloseHandle(hProcess);
return 0;
}
int main(void)
{
bool ppp = LoadLibrary(L"aecache.dll");
PrintModules(GetCurrentProcessId());
printf("\n\n\n\n\n");
PrintModules(GetCurrentProcessId());
Доброго времени суток. Подскажите , почему я не могу выгрузить user32.dll из памяти процесса, хотя FreeLibrary возвращает true????
Не понимаю.