我正在尝试获取远程桌面IP地址,因为我正在挂钩API WTSQuerysessionInformation。但是此功能没有挂钩,请任何人帮我。我的代码如下。检查任何参数不匹配并建议我我做了什么。
#include "stdafx.h"
#include "MinHook.h"
#include <Wtsapi32.h>
#if defined _M_X64
#pragma comment(lib, "libMinHook.x64.lib")
#elif defined _M_IX86
#pragma comment(lib, "libMinHook.x86.lib")
#endif
typedef BOOL(WINAPI *WTSQuerySessionInformationWNext)(IN HANDLE hServer,
IN DWORD SessionId, IN WTS_INFO_CLASS WTSInfoClass, __deref_out_bcount(*pBytesReturned) LPWSTR * ppBuffer, __out DWORD * pBytesReturned);
WTSQuerySessionInformationWNext Real_WTSQuerySessionInformationW = NULL;
BOOL WINAPI WTSQuerySessionInformationWCallback(IN HANDLE hServer,IN DWORD SessionId, IN WTS_INFO_CLASS WTSInfoClass, __deref_out_bcount(*pBytesReturned) LPWSTR * ppBuffer, __out DWORD * pBytesReturned)
{
BOOL ret = Real_WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned);
if(ret != NULL)
{
MessageBoxA(NULL, "WTSQuerySessionInformationW Called", "Info", MB_OK);
return ret;
}
else
{
MessageBoxA(NULL, "WTSQuerySessionInformationW fails", "Info", MB_OK);
return ret;
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
if (MH_Initialize() != MH_OK)
{
MessageBoxW(NULL, L"Failed Initialize", L"Info!", MB_ICONWARNING|MB_OK);
}
if (MH_CreateHook(&WTSQuerySessionInformationW, &WTSQuerySessionInformationWCallback, reinterpret_cast<void**>(&Real_WTSQuerySessionInformationW)) != MH_OK)
{
MessageBoxW(NULL, L"Failed CreateHook WTSQuerySessionInformationW", L"Info!",MB_ICONWARNING|MB_OK);
}
if (MH_EnableHook(&WTSQuerySessionInformationW) != MH_OK)
{
MessageBoxW(NULL, L"Failed EnableHook WTSQuerySessionInformationW", L"Info!",MB_ICONWARNING|MB_OK);
}
break;
case DLL_PROCESS_DETACH:
if (MH_Uninitialize() != MH_OK)
{
}
if(MH_DisableHook(&ProcessIdToSessionId) != MH_OK)
{
}
break;
}
return TRUE;
}