27 |
|
|
28 |
#include <windows.h> |
#include <windows.h> |
29 |
#include <winuser.h> |
#include <winuser.h> |
|
#include <wtsapi32.h> |
|
|
#include <cchannel.h> |
|
30 |
|
|
31 |
#include "hookdll.h" |
#include "../vchannel.h" |
32 |
|
|
33 |
#define DLL_EXPORT __declspec(dllexport) |
#define DLL_EXPORT __declspec(dllexport) |
34 |
|
|
49 |
|
|
50 |
static HANDLE g_mutex = NULL; |
static HANDLE g_mutex = NULL; |
51 |
|
|
|
static HANDLE g_vchannel = NULL; |
|
|
|
|
|
static void |
|
|
debug(char *format, ...) |
|
|
{ |
|
|
va_list argp; |
|
|
char buf[256]; |
|
|
|
|
|
sprintf(buf, "DEBUG1,"); |
|
|
|
|
|
va_start(argp, format); |
|
|
_vsnprintf(buf + sizeof("DEBUG1,") - 1, sizeof(buf) - sizeof("DEBUG1,") + 1, format, argp); |
|
|
va_end(argp); |
|
|
|
|
|
vchannel_write(buf); |
|
|
} |
|
|
|
|
52 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
53 |
wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details) |
wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details) |
54 |
{ |
{ |
200 |
return CallNextHookEx(g_cbt_hook, code, wparam, lparam); |
return CallNextHookEx(g_cbt_hook, code, wparam, lparam); |
201 |
} |
} |
202 |
|
|
|
int |
|
|
vchannel_open() |
|
|
{ |
|
|
g_vchannel = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, |
|
|
WTS_CURRENT_SESSION, CHANNELNAME); |
|
|
|
|
|
if (g_vchannel == NULL) |
|
|
return 0; |
|
|
else |
|
|
return 1; |
|
|
} |
|
|
|
|
|
int |
|
|
vchannel_close() |
|
|
{ |
|
|
BOOL result; |
|
|
|
|
|
result = WTSVirtualChannelClose(g_vchannel); |
|
|
|
|
|
g_vchannel = NULL; |
|
|
|
|
|
if (result) |
|
|
return 1; |
|
|
else |
|
|
return 0; |
|
|
} |
|
|
|
|
|
int |
|
|
vchannel_is_open() |
|
|
{ |
|
|
if (g_vchannel == NULL) |
|
|
return 0; |
|
|
else |
|
|
return 1; |
|
|
} |
|
|
|
|
|
int |
|
|
vchannel_write(char *format, ...) |
|
|
{ |
|
|
BOOL result; |
|
|
va_list argp; |
|
|
char buf[1024]; |
|
|
int size; |
|
|
ULONG bytes_written; |
|
|
|
|
|
if (!vchannel_is_open()) |
|
|
return 1; |
|
|
|
|
|
va_start(argp, format); |
|
|
size = _vsnprintf(buf, sizeof(buf), format, argp); |
|
|
va_end(argp); |
|
|
|
|
|
if (size >= sizeof(buf)) |
|
|
return 0; |
|
|
|
|
|
WaitForSingleObject(g_mutex, INFINITE); |
|
|
result = WTSVirtualChannelWrite(g_vchannel, buf, (ULONG) strlen(buf), &bytes_written); |
|
|
result = WTSVirtualChannelWrite(g_vchannel, "\n", (ULONG) 1, &bytes_written); |
|
|
ReleaseMutex(g_mutex); |
|
|
|
|
|
if (result) |
|
|
return 1; |
|
|
else |
|
|
return 0; |
|
|
} |
|
|
|
|
203 |
DLL_EXPORT void |
DLL_EXPORT void |
204 |
SetHooks(void) |
SetHooks(void) |
205 |
{ |
{ |
235 |
// remember our instance handle |
// remember our instance handle |
236 |
g_instance = hinstDLL; |
g_instance = hinstDLL; |
237 |
|
|
238 |
g_mutex = CreateMutex(NULL, FALSE, "Local\\Seamless"); |
g_mutex = CreateMutex(NULL, FALSE, "Local\\SeamlessDLL"); |
239 |
if (!g_mutex) |
if (!g_mutex) |
240 |
return FALSE; |
return FALSE; |
241 |
|
|