Службы удаленного рабочего стола

Я пытаюсь получить 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;
}

0 ответов

Другие вопросы по тегам