5 |
#include "hookdll.h" |
#include "hookdll.h" |
6 |
#include <windows.h> |
#include <windows.h> |
7 |
#include <winuser.h> |
#include <winuser.h> |
8 |
|
#include <stdio.h> |
9 |
|
#include <stdarg.h> |
10 |
|
|
11 |
#include "wtsapi32.h" |
#include "wtsapi32.h" |
12 |
#include "Cchannel.h" |
#include "Cchannel.h" |
13 |
|
|
14 |
#define DLL_EXPORT extern "C" __declspec(dllexport) |
#define DLL_EXPORT extern "C" __declspec(dllexport) |
15 |
|
|
16 |
// Shared DATA |
// Shared DATA |
17 |
#pragma data_seg ( "SHAREDDATA" ) |
#pragma data_seg ( "SHAREDDATA" ) |
24 |
|
|
25 |
#pragma comment(linker, "/section:SHAREDDATA,rws") |
#pragma comment(linker, "/section:SHAREDDATA,rws") |
26 |
|
|
27 |
|
#define snprintf _snprintf |
28 |
|
|
29 |
bool bHooked = false; |
bool bHooked = false; |
30 |
bool bHooked2 = false; |
bool bHooked2 = false; |
31 |
bool bHooked3 = false; |
bool bHooked3 = false; |
32 |
HHOOK hhook = 0; //cbt |
HHOOK hhook = 0; //cbt |
33 |
HHOOK hhook2 = 0; //shell |
HHOOK hhook2 = 0; //shell |
34 |
HHOOK hhook3 = 0; //wnd proc |
HHOOK hhook3 = 0; //wnd proc |
35 |
HINSTANCE hInst = 0; |
HINSTANCE hInst = 0; |
36 |
HANDLE m_vcHandle = 0; |
HANDLE m_vcHandle = 0; |
37 |
|
|
38 |
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, |
|
39 |
LPVOID lpReserved) |
void SendDebug( char *format, ... ) |
40 |
{ |
{ |
41 |
switch (ul_reason_for_call) { |
va_list argp; |
42 |
case DLL_PROCESS_ATTACH: { |
char buf [ 256 ]; |
43 |
|
|
44 |
|
va_start( argp, format ); |
45 |
|
vsprintf( buf, format, argp ); |
46 |
|
va_end( argp ); |
47 |
|
|
48 |
|
if ( ChannelIsOpen() ) { |
49 |
|
WriteToChannel( "DEBUG1," ); |
50 |
|
WriteToChannel( buf ); |
51 |
|
WriteToChannel( "\n" ); |
52 |
|
} |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved ) |
58 |
|
{ |
59 |
|
switch ( ul_reason_for_call ) { |
60 |
|
case DLL_PROCESS_ATTACH: { |
61 |
// remember our instance handle |
// remember our instance handle |
62 |
hInst = hinstDLL; |
hInst = hinstDLL; |
63 |
++iInstanceCount; |
++iInstanceCount; |
64 |
OpenVirtualChannel(); |
OpenVirtualChannel(); |
65 |
break; |
break; |
66 |
} |
} |
67 |
|
|
68 |
case DLL_THREAD_ATTACH: |
case DLL_THREAD_ATTACH: |
69 |
break; |
break; |
70 |
case DLL_THREAD_DETACH: |
case DLL_THREAD_DETACH: |
71 |
break; |
break; |
72 |
case DLL_PROCESS_DETACH: { |
case DLL_PROCESS_DETACH: { |
73 |
--iInstanceCount; |
--iInstanceCount; |
74 |
CloseVirtualChannel(); |
CloseVirtualChannel(); |
75 |
} |
} |
76 |
break; |
break; |
77 |
} |
} |
78 |
|
|
79 |
return TRUE; |
return TRUE; |
80 |
} |
} |
81 |
|
|
82 |
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK CallWndProc( int nCode, WPARAM wParam, LPARAM lParam ) |
83 |
{ |
{ |
84 |
if (nCode < 0) { |
if ( nCode < 0 ) { |
85 |
return CallNextHookEx(hhook3, nCode, wParam, lParam); |
return CallNextHookEx( hhook3, nCode, wParam, lParam ); |
86 |
} |
} |
87 |
|
|
88 |
PCHAR buffer = NULL; |
PCHAR buffer = NULL; |
89 |
char windowTitle[150] = { "" }; |
char windowTitle[ 150 ] = { "" |
90 |
|
}; |
91 |
HWND windowHandle = NULL; |
HWND windowHandle = NULL; |
92 |
char result[255] = { "" }; |
HWND windowHandle2 = NULL; |
93 |
char strWindowId[25]; |
char result[ 255 ] = { "" |
94 |
char type[25]; |
}; |
95 |
|
CWPSTRUCT *details = ( CWPSTRUCT * ) lParam; |
96 |
LONG b, t, l, r; |
CREATESTRUCT *cs = ( CREATESTRUCT * ) details->lParam; |
97 |
char strB[5]; |
LONG dwStyle = GetWindowLong( details->hwnd, GWL_STYLE ); |
98 |
char strT[5]; |
WINDOWPOS *wp = ( WINDOWPOS * ) details->lParam; |
99 |
char strL[5]; |
RECT *rect = ( RECT * ) details->lParam; |
100 |
char strR[5]; |
|
101 |
RECT rect; |
switch ( details->message ) { |
102 |
|
|
103 |
CWPSTRUCT *details = (CWPSTRUCT *) lParam; |
case WM_SIZING: |
104 |
|
case WM_MOVING: |
105 |
switch (details->message) { |
if ( !( dwStyle & WS_VISIBLE ) ) |
106 |
case WM_SIZING: |
break; |
107 |
case WM_MOVING: |
|
108 |
|
if ( !( dwStyle & WS_DLGFRAME ) ) |
109 |
windowHandle = details->hwnd; |
break; |
110 |
//get win name |
|
111 |
GetWindowText(windowHandle, windowTitle, 150); |
snprintf( result, sizeof( result ), |
112 |
|
"POSITION1,0x%p,%d,%d,%d,%d,0x%x", |
113 |
//get an id for it |
details->hwnd, |
114 |
itoa((int) windowHandle, strWindowId, 10); |
rect->left, rect->top, |
115 |
|
rect->right - rect->left, |
116 |
//get coords |
rect->bottom - rect->top, |
117 |
GetWindowRect(windowHandle, &rect); |
0 ); |
118 |
b = rect.bottom; |
result[ sizeof( result ) - 1 ] = '\0'; |
|
t = rect.top; |
|
|
l = rect.left; |
|
|
r = rect.right; |
|
|
ltoa(b, strB, 10); |
|
|
ltoa(t, strT, 10); |
|
|
ltoa(r, strR, 10); |
|
|
ltoa(l, strL, 10); |
|
|
|
|
|
////setup return string |
|
|
strcat(result, "MSG=CALLWNDPROC_WM_MOVING;"); |
|
|
strcat(result, "ID="); |
|
|
strcat(result, strWindowId); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "TITLE="); |
|
|
strcat(result, windowTitle); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "POS="); |
|
|
strcat(result, strL); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strT); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strR); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strB); |
|
|
strcat(result, ";"); |
|
|
|
|
119 |
buffer = result; |
buffer = result; |
|
|
|
120 |
break; |
break; |
121 |
|
|
122 |
default: |
|
123 |
|
/* Note: WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED are |
124 |
|
strange. Sometimes, for example when bringing up the |
125 |
|
Notepad About dialog, only an WM_WINDOWPOSCHANGING is |
126 |
|
sent. In some other cases, for exmaple when opening |
127 |
|
Format->Text in Notepad, both events are sent. Also, for |
128 |
|
some reason, when closing the Notepad About dialog, an |
129 |
|
WM_WINDOWPOSCHANGING event is sent which looks just like |
130 |
|
the event that was sent when the About dialog was opened... */ |
131 |
|
case WM_WINDOWPOSCHANGING: |
132 |
|
|
133 |
|
if ( !( dwStyle & WS_VISIBLE ) ) |
134 |
|
break; |
135 |
|
|
136 |
|
if ( !( dwStyle & WS_DLGFRAME ) ) |
137 |
|
break; |
138 |
|
|
139 |
|
if ( !( wp->flags & SWP_NOZORDER ) ) { |
140 |
|
snprintf( result, sizeof( result ), |
141 |
|
"ZCHANGE1,0x%p,0x%p,0x%x\n", |
142 |
|
details->hwnd, |
143 |
|
wp->flags & SWP_NOACTIVATE ? wp->hwndInsertAfter : 0, |
144 |
|
0 ); |
145 |
|
result[ sizeof( result ) - 1 ] = '\0'; |
146 |
|
buffer = result; |
147 |
|
} |
148 |
|
break; |
149 |
|
|
150 |
|
|
151 |
|
case WM_CREATE: |
152 |
|
if ( cs->style & WS_DLGFRAME ) { |
153 |
|
snprintf( result, sizeof( result ), |
154 |
|
"CREATE1,0x%p,0x%x\n", |
155 |
|
details->hwnd, 0 ); |
156 |
|
buffer = result; |
157 |
|
} |
158 |
|
break; |
159 |
|
|
160 |
|
|
161 |
|
case WM_DESTROY: |
162 |
|
if ( dwStyle & WS_DLGFRAME ) { |
163 |
|
snprintf( result, sizeof( result ), |
164 |
|
"DESTROY1,0x%p,0x%x\n", |
165 |
|
details->hwnd, 0 ); |
166 |
|
buffer = result; |
167 |
|
} |
168 |
|
|
169 |
|
break; |
170 |
|
|
171 |
|
|
172 |
|
default: |
173 |
break; |
break; |
174 |
} |
} |
175 |
|
|
176 |
if (ChannelIsOpen()) { |
if ( ChannelIsOpen() ) { |
177 |
if (buffer != NULL) { |
if ( buffer != NULL ) { |
178 |
WriteToChannel(buffer); |
WriteToChannel( buffer ); |
179 |
} |
} |
180 |
} |
} |
181 |
|
|
182 |
return CallNextHookEx(hhook3, nCode, wParam, lParam); |
return CallNextHookEx( hhook3, nCode, wParam, lParam ); |
183 |
} |
} |
184 |
|
|
185 |
LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam ) |
186 |
{ |
{ |
187 |
if (nCode < 0) { |
if ( nCode < 0 ) { |
188 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
189 |
} |
} |
190 |
|
|
191 |
|
|
192 |
PCHAR buffer = NULL; |
PCHAR buffer = NULL; |
193 |
|
|
194 |
|
|
195 |
char windowTitle[150] = { "" }; |
char windowTitle[ 150 ] = { "" |
196 |
|
}; |
197 |
HWND windowHandle = NULL; |
HWND windowHandle = NULL; |
198 |
char result[255] = { "" }; |
char result[ 255 ] = { "" |
199 |
char strWindowId[25]; |
}; |
200 |
char type[25]; |
switch ( nCode ) { |
201 |
|
case HCBT_MINMAX: |
202 |
|
|
203 |
LONG b, t, l, r; |
if ( ( LOWORD( lParam ) == SW_SHOWMINIMIZED ) |
204 |
char strB[5]; |
|| ( LOWORD( lParam ) == SW_MINIMIZE ) ) { |
205 |
char strT[5]; |
MessageBox( 0, "Minimizing windows is not allowed in this version. Sorry!", "SeamlessRDP", MB_OK ); |
|
char strL[5]; |
|
|
char strR[5]; |
|
|
RECT rect; |
|
|
|
|
|
int i = 0; //tmp |
|
|
|
|
|
switch (nCode) { |
|
|
case HCBT_MINMAX: |
|
|
|
|
|
windowHandle = (HWND) wParam; |
|
|
//get win name |
|
|
GetWindowText(windowHandle, windowTitle, 150); |
|
|
|
|
|
//get an id for it |
|
|
itoa((int) windowHandle, strWindowId, 10); |
|
|
|
|
|
//get operation type(min,max). if max, do not clip at all,if min use window's previous coords |
|
|
//codes are: |
|
|
|
|
|
// SW_HIDE= 0 SW_SHOWNORMAL=1 SW_NORMAL=1 SW_SHOWMINIMIZED=2 SW_SHOWMAXIMIZED=3 SW_MAXIMIZE=3 |
|
|
// SW_SHOWNOACTIVATE=4 SW_SHOW=5 SW_MINIMIZE=6 SW_SHOWMINNOACTIVE=7 SW_SHOWNA=8 SW_RESTORE=9 |
|
|
// SW_SHOWDEFAULT=10 SW_FORCEMINIMIZE=11 SW_MAX=11 |
|
|
|
|
|
itoa((int) lParam, type, 10); |
|
|
|
|
|
//get coords |
|
|
GetWindowRect(windowHandle, &rect); |
|
|
b = rect.bottom; |
|
|
t = rect.top; |
|
|
l = rect.left; |
|
|
r = rect.right; |
|
|
ltoa(b, strB, 10); |
|
|
ltoa(t, strT, 10); |
|
|
ltoa(r, strR, 10); |
|
|
ltoa(l, strL, 10); |
|
|
|
|
|
//get name |
|
|
GetWindowText(windowHandle, windowTitle, 150); |
|
|
|
|
|
////setup return string |
|
|
strcat(result, "MSG=HCBT_MINMAX;"); |
|
|
strcat(result, "ID="); |
|
|
strcat(result, strWindowId); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "TITLE="); |
|
|
strcat(result, windowTitle); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "POS="); |
|
|
strcat(result, strL); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strT); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strR); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strB); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "TYPE="); |
|
|
strcat(result, type); |
|
|
strcat(result, ";"); |
|
|
|
|
|
//------------------------------------------------------------------------------------------------- |
|
|
// code to prevent minimising windows (can be removed once minimise has been implemented) |
|
|
i = (int) lParam; |
|
|
//if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11) |
|
|
if (i == 2 || i == 6) { |
|
|
MessageBox(0, |
|
|
"Minimising windows is not allowed in this version. Sorry!", |
|
|
"TS Window Clipper", MB_OK); |
|
|
return 1; |
|
|
} |
|
|
//----------------------------------------------------------------------------------------- |
|
|
|
|
|
//------------------------------------------------------------------------------------------------- |
|
|
// code to prevent maximising windows (can be removed once maximise has been implemented) |
|
|
i = (int) lParam; |
|
|
//if (i==3 || i==9 || i==11) |
|
|
if (i == 3 || i == 11) { |
|
|
MessageBox(0, |
|
|
"Maximising windows is not allowed in this version. Sorry!", |
|
|
"TS Window Clipper", MB_OK); |
|
206 |
return 1; |
return 1; |
207 |
} |
} |
208 |
//----------------------------------------------------------------------------------------- |
|
209 |
|
GetWindowText( ( HWND ) wParam, windowTitle, 150 ); |
210 |
|
|
211 |
|
snprintf( result, sizeof( result ), |
212 |
|
"SETSTATE1,0x%p,%s,0x%x,0x%x\n", |
213 |
|
( HWND ) wParam, |
214 |
|
windowTitle, |
215 |
|
LOWORD( lParam ), |
216 |
|
0 ); |
217 |
buffer = result; |
buffer = result; |
|
|
|
218 |
break; |
break; |
219 |
|
|
220 |
case HCBT_MOVESIZE: |
|
221 |
|
default: |
|
windowHandle = (HWND) wParam; |
|
|
//get win name |
|
|
GetWindowText(windowHandle, windowTitle, 150); |
|
|
|
|
|
//get an id for it |
|
|
itoa((int) windowHandle, strWindowId, 10); |
|
|
|
|
|
//get coords |
|
|
GetWindowRect(windowHandle, &rect); |
|
|
b = rect.bottom; |
|
|
t = rect.top; |
|
|
l = rect.left; |
|
|
r = rect.right; |
|
|
ltoa(b, strB, 10); |
|
|
ltoa(t, strT, 10); |
|
|
ltoa(r, strR, 10); |
|
|
ltoa(l, strL, 10); |
|
|
|
|
|
//get name |
|
|
GetWindowText(windowHandle, windowTitle, 150); |
|
|
|
|
|
////setup return string |
|
|
strcat(result, "MSG=HCBT_MOVESIZE;"); |
|
|
strcat(result, "ID="); |
|
|
strcat(result, strWindowId); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "TITLE="); |
|
|
strcat(result, windowTitle); |
|
|
strcat(result, ";"); |
|
|
strcat(result, "POS="); |
|
|
strcat(result, strL); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strT); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strR); |
|
|
strcat(result, "~"); |
|
|
strcat(result, strB); |
|
|
strcat(result, ";"); |
|
|
|
|
|
buffer = result; |
|
|
|
|
|
break; |
|
|
case HCBT_SETFOCUS: |
|
|
//buffer = "HCBT_SETFOCUS"; |
|
|
//not needed yet |
|
|
break; |
|
|
default: |
|
222 |
break; |
break; |
223 |
} |
} |
224 |
|
|
225 |
if (ChannelIsOpen()) { |
if ( ChannelIsOpen() ) { |
226 |
if (buffer != NULL) { |
if ( buffer != NULL ) { |
227 |
WriteToChannel(buffer); |
WriteToChannel( buffer ); |
228 |
} |
} |
229 |
} |
} |
230 |
|
|
231 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
232 |
} |
} |
233 |
|
|
234 |
|
|
235 |
LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam ) |
236 |
{ |
{ |
237 |
if (nCode < 0) { |
if ( nCode < 0 ) { |
238 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
239 |
} |
} |
240 |
|
|
241 |
if (ChannelIsOpen()) { |
if ( ChannelIsOpen() ) { |
242 |
PCHAR buffer = NULL; |
PCHAR buffer = NULL; |
243 |
|
|
244 |
char windowTitle[150] = { "" }; |
char windowTitle[ 150 ] = { "" |
245 |
|
}; |
246 |
HWND windowHandle = NULL; |
HWND windowHandle = NULL; |
247 |
char result[255] = { "" }; |
char result[ 255 ] = { "" |
248 |
char strWindowId[25]; |
}; |
249 |
|
char strWindowId[ 25 ]; |
250 |
LONG b, t, l, r; |
LONG b, t, l, r; |
251 |
char strB[5]; |
char strW[ 5 ]; |
252 |
char strT[5]; |
char strY[ 5 ]; |
253 |
char strL[5]; |
char strX[ 5 ]; |
254 |
char strR[5]; |
char strH[ 5 ]; |
255 |
RECT rect; |
RECT rect; |
256 |
|
|
257 |
switch (nCode) { |
switch ( nCode ) { |
258 |
case HSHELL_WINDOWCREATED: |
case HSHELL_WINDOWCREATED: |
259 |
|
|
260 |
//get window id |
//get window id |
261 |
windowHandle = (HWND) wParam; |
windowHandle = ( HWND ) wParam; |
262 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
263 |
|
|
264 |
//get coords |
//get coords |
265 |
GetWindowRect(windowHandle, &rect); |
GetWindowRect( windowHandle, &rect ); |
266 |
b = rect.bottom; |
b = rect.bottom; |
267 |
t = rect.top; |
t = rect.top; |
268 |
l = rect.left; |
l = rect.left; |
269 |
r = rect.right; |
r = rect.right; |
270 |
ltoa(b, strB, 10); |
ltoa( b - t, strH, 10 ); |
271 |
ltoa(t, strT, 10); |
ltoa( t, strY, 10 ); |
272 |
ltoa(r, strR, 10); |
ltoa( r - l, strW, 10 ); |
273 |
ltoa(l, strL, 10); |
ltoa( l, strX, 10 ); |
274 |
|
|
275 |
//get name |
//get name |
276 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
277 |
|
|
278 |
////setup return string |
////setup return string |
279 |
strcat(result, "MSG=HSHELL_WINDOWCREATED;"); |
strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" ); |
280 |
strcat(result, "ID="); |
strcat( result, "ID=" ); |
281 |
strcat(result, strWindowId); |
strcat( result, strWindowId ); |
282 |
strcat(result, ";"); |
strcat( result, ";" ); |
283 |
strcat(result, "TITLE="); |
strcat( result, "TITLE=" ); |
284 |
strcat(result, windowTitle); |
strcat( result, windowTitle ); |
285 |
strcat(result, ";"); |
strcat( result, ";" ); |
286 |
strcat(result, "POS="); |
strcat( result, "X=" ); |
287 |
strcat(result, strL); |
strcat( result, strX ); |
288 |
strcat(result, "~"); |
strcat( result, ";" ); |
289 |
strcat(result, strT); |
strcat( result, "Y=" ); |
290 |
strcat(result, "~"); |
strcat( result, strY ); |
291 |
strcat(result, strR); |
strcat( result, ";" ); |
292 |
strcat(result, "~"); |
strcat( result, "H=" ); |
293 |
strcat(result, strB); |
strcat( result, strH ); |
294 |
strcat(result, ";"); |
strcat( result, ";" ); |
295 |
|
strcat( result, "W=" ); |
296 |
|
strcat( result, strW ); |
297 |
|
strcat( result, "." ); |
298 |
|
|
299 |
buffer = result; |
buffer = result; |
300 |
|
|
301 |
break; |
break; |
302 |
|
|
303 |
case HSHELL_WINDOWDESTROYED: |
case HSHELL_WINDOWDESTROYED: |
304 |
|
|
305 |
//get window id |
//get window id |
306 |
windowHandle = (HWND) wParam; |
windowHandle = ( HWND ) wParam; |
307 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
308 |
|
|
309 |
|
//get coords |
310 |
|
GetWindowRect( windowHandle, &rect ); |
311 |
|
b = rect.bottom; |
312 |
|
t = rect.top; |
313 |
|
l = rect.left; |
314 |
|
r = rect.right; |
315 |
|
ltoa( b - t, strH, 10 ); |
316 |
|
ltoa( t, strY, 10 ); |
317 |
|
ltoa( r - l, strW, 10 ); |
318 |
|
ltoa( l, strX, 10 ); |
319 |
|
|
320 |
//get name |
//get name |
321 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
322 |
|
|
323 |
////setup return string |
////setup return string |
324 |
strcat(result, "MSG=HSHELL_WINDOWDESTROYED;"); |
strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" ); |
325 |
strcat(result, "ID="); |
strcat( result, "ID=" ); |
326 |
strcat(result, strWindowId); |
strcat( result, strWindowId ); |
327 |
strcat(result, ";"); |
strcat( result, ";" ); |
328 |
strcat(result, "TITLE="); |
strcat( result, "TITLE=" ); |
329 |
strcat(result, windowTitle); |
strcat( result, windowTitle ); |
330 |
strcat(result, ";"); |
strcat( result, ";" ); |
331 |
|
strcat( result, "X=" ); |
332 |
|
strcat( result, strX ); |
333 |
|
strcat( result, ";" ); |
334 |
|
strcat( result, "Y=" ); |
335 |
|
strcat( result, strY ); |
336 |
|
strcat( result, ";" ); |
337 |
|
strcat( result, "H=" ); |
338 |
|
strcat( result, strH ); |
339 |
|
strcat( result, ";" ); |
340 |
|
strcat( result, "W=" ); |
341 |
|
strcat( result, strW ); |
342 |
|
strcat( result, "." ); |
343 |
|
|
344 |
buffer = result; |
buffer = result; |
345 |
|
|
346 |
break; |
break; |
347 |
default: |
default: |
348 |
break; |
break; |
349 |
} |
} |
350 |
|
|
351 |
if (buffer != NULL) { |
if ( buffer != NULL ) { |
352 |
WriteToChannel(buffer); |
WriteToChannel( buffer ); |
353 |
} |
} |
354 |
} |
} |
355 |
|
|
356 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
357 |
} |
} |
358 |
|
|
359 |
DLL_EXPORT void SetCbtHook(void) |
DLL_EXPORT void SetCbtHook( void ) |
360 |
{ |
{ |
361 |
if (!bHooked) { |
if ( !bHooked ) { |
362 |
hhook = |
hhook = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL ); |
|
SetWindowsHookEx(WH_CBT, (HOOKPROC) CbtProc, hInst, (DWORD) NULL); |
|
363 |
bHooked = true; |
bHooked = true; |
364 |
} |
} |
365 |
|
|
366 |
if (!bHooked2) { |
if ( !bHooked2 ) { |
367 |
hhook2 = |
hhook2 = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL ); |
|
SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInst, |
|
|
(DWORD) NULL); |
|
368 |
bHooked2 = true; |
bHooked2 = true; |
369 |
} |
} |
370 |
|
|
371 |
if (!bHooked3) { |
if ( !bHooked3 ) { |
372 |
hhook3 = |
hhook3 = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL ); |
|
SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInst, |
|
|
(DWORD) NULL); |
|
373 |
bHooked3 = true; |
bHooked3 = true; |
374 |
} |
} |
375 |
} |
} |
376 |
|
|
377 |
DLL_EXPORT void RemoveCbtHook(void) |
DLL_EXPORT void RemoveCbtHook( void ) |
378 |
{ |
{ |
379 |
if (bHooked) { |
if ( bHooked ) { |
380 |
UnhookWindowsHookEx(hhook); |
UnhookWindowsHookEx( hhook ); |
381 |
bHooked = false; |
bHooked = false; |
382 |
} |
} |
383 |
|
|
384 |
if (bHooked2) { |
if ( bHooked2 ) { |
385 |
UnhookWindowsHookEx(hhook2); |
UnhookWindowsHookEx( hhook2 ); |
386 |
bHooked2 = false; |
bHooked2 = false; |
387 |
} |
} |
388 |
|
|
389 |
if (bHooked3) { |
if ( bHooked3 ) { |
390 |
UnhookWindowsHookEx(hhook3); |
UnhookWindowsHookEx( hhook3 ); |
391 |
bHooked3 = false; |
bHooked3 = false; |
392 |
} |
} |
393 |
} |
} |
399 |
|
|
400 |
int OpenVirtualChannel() |
int OpenVirtualChannel() |
401 |
{ |
{ |
402 |
m_vcHandle = |
m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME ); |
403 |
WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, |
|
404 |
CHANNELNAME); |
if ( m_vcHandle == NULL ) { |
|
|
|
|
if (m_vcHandle == NULL) { |
|
405 |
return 0; |
return 0; |
406 |
} else { |
} else { |
407 |
return 1; |
return 1; |
410 |
|
|
411 |
int CloseVirtualChannel() |
int CloseVirtualChannel() |
412 |
{ |
{ |
413 |
BOOL result = WTSVirtualChannelClose(m_vcHandle); |
BOOL result = WTSVirtualChannelClose( m_vcHandle ); |
414 |
|
|
415 |
m_vcHandle = NULL; |
m_vcHandle = NULL; |
416 |
|
|
417 |
if (result) { |
if ( result ) { |
418 |
return 1; |
return 1; |
419 |
} else { |
} else { |
420 |
return 0; |
return 0; |
423 |
|
|
424 |
int ChannelIsOpen() |
int ChannelIsOpen() |
425 |
{ |
{ |
426 |
if (m_vcHandle == NULL) { |
if ( m_vcHandle == NULL ) { |
427 |
return 0; |
return 0; |
428 |
} else { |
} else { |
429 |
return 1; |
return 1; |
430 |
} |
} |
431 |
} |
} |
432 |
|
|
433 |
int WriteToChannel(PCHAR buffer) |
int WriteToChannel( PCHAR buffer ) |
434 |
{ |
{ |
435 |
PULONG bytesRead = 0; |
PULONG bytesRead = 0; |
436 |
PULONG pBytesWritten = 0; |
PULONG pBytesWritten = 0; |
437 |
|
|
438 |
BOOL result = |
BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten ); |
439 |
WTSVirtualChannelWrite(m_vcHandle, buffer, (ULONG) strlen(buffer), |
|
440 |
pBytesWritten); |
if ( result ) { |
|
|
|
|
if (result) { |
|
441 |
return 1; |
return 1; |
442 |
} else { |
} else { |
443 |
return 0; |
return 0; |