1 |
ossman_ |
1071 |
/* -*- c-basic-offset: 8 -*- |
2 |
|
|
rdesktop: A Remote Desktop Protocol client. |
3 |
|
|
Seamless windows - Remote server executable |
4 |
ossman_ |
1069 |
|
5 |
ossman_ |
1071 |
Based on code copyright (C) 2004-2005 Martin Wickett |
6 |
ossman_ |
1069 |
|
7 |
ossman_ |
1071 |
Copyright (C) Peter Åstrand <astrand@cendio.se> 2005-2006 |
8 |
|
|
Copyright (C) Pierre Ossman <ossman@cendio.se> 2006 |
9 |
ossman_ |
1069 |
|
10 |
ossman_ |
1071 |
This program is free software; you can redistribute it and/or modify |
11 |
|
|
it under the terms of the GNU General Public License as published by |
12 |
|
|
the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
(at your option) any later version. |
14 |
ossman_ |
1069 |
|
15 |
ossman_ |
1071 |
This program is distributed in the hope that it will be useful, |
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
GNU General Public License for more details. |
19 |
ossman_ |
1069 |
|
20 |
ossman_ |
1071 |
You should have received a copy of the GNU General Public License |
21 |
|
|
along with this program; if not, write to the Free Software |
22 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 |
|
|
*/ |
24 |
ossman_ |
1069 |
|
25 |
ossman_ |
1071 |
#include <windows.h> |
26 |
|
|
#include <stdio.h> |
27 |
ossman_ |
1069 |
|
28 |
ossman_ |
1074 |
#include "vchannel.h" |
29 |
|
|
|
30 |
ossman_ |
1071 |
#include "resource.h" |
31 |
ossman_ |
1069 |
|
32 |
ossman_ |
1071 |
#define APP_NAME "SeamlessRDP Shell" |
33 |
ossman_ |
1069 |
|
34 |
ossman_ |
1071 |
/* Global data */ |
35 |
|
|
static HINSTANCE g_instance; |
36 |
ossman_ |
1069 |
|
37 |
ossman_ |
1071 |
typedef void (*set_hooks_proc_t) (); |
38 |
|
|
typedef void (*remove_hooks_proc_t) (); |
39 |
|
|
typedef int (*get_instance_count_proc_t) (); |
40 |
ossman_ |
1069 |
|
41 |
ossman_ |
1071 |
static void |
42 |
|
|
message(const char *text) |
43 |
ossman_ |
1069 |
{ |
44 |
ossman_ |
1071 |
MessageBox(GetDesktopWindow(), text, "SeamlessRDP Shell", MB_OK); |
45 |
ossman_ |
1069 |
} |
46 |
|
|
|
47 |
ossman_ |
1074 |
static void |
48 |
|
|
process_cmds(void) |
49 |
|
|
{ |
50 |
|
|
char line[VCHANNEL_MAX_LINE]; |
51 |
|
|
int size; |
52 |
|
|
|
53 |
|
|
while ((size = vchannel_read(line, sizeof(line))) >= 0) { |
54 |
|
|
debug("Got: %s", line); |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
|
58 |
ossman_ |
1071 |
int WINAPI |
59 |
|
|
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
60 |
ossman_ |
1069 |
{ |
61 |
ossman_ |
1071 |
HMODULE hookdll; |
62 |
ossman_ |
1069 |
|
63 |
ossman_ |
1071 |
set_hooks_proc_t set_hooks_fn; |
64 |
|
|
remove_hooks_proc_t remove_hooks_fn; |
65 |
|
|
get_instance_count_proc_t instance_count_fn; |
66 |
ossman_ |
1069 |
|
67 |
ossman_ |
1071 |
g_instance = instance; |
68 |
ossman_ |
1069 |
|
69 |
ossman_ |
1071 |
hookdll = LoadLibrary("hookdll.dll"); |
70 |
|
|
if (!hookdll) |
71 |
|
|
{ |
72 |
|
|
message("Could not load hook DLL. Unable to continue."); |
73 |
|
|
return -1; |
74 |
|
|
} |
75 |
ossman_ |
1069 |
|
76 |
ossman_ |
1071 |
set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks"); |
77 |
|
|
remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks"); |
78 |
|
|
instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount"); |
79 |
ossman_ |
1069 |
|
80 |
ossman_ |
1071 |
if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn) |
81 |
|
|
{ |
82 |
|
|
FreeLibrary(hookdll); |
83 |
|
|
message("Hook DLL doesn't contain the correct functions. Unable to continue."); |
84 |
|
|
return -1; |
85 |
|
|
} |
86 |
ossman_ |
1069 |
|
87 |
ossman_ |
1071 |
/* Check if the DLL is already loaded */ |
88 |
|
|
if (instance_count_fn() != 1) |
89 |
|
|
{ |
90 |
|
|
FreeLibrary(hookdll); |
91 |
|
|
message("Another running instance of Seamless RDP detected."); |
92 |
|
|
return -1; |
93 |
|
|
} |
94 |
ossman_ |
1069 |
|
95 |
ossman_ |
1074 |
vchannel_open(); |
96 |
|
|
|
97 |
ossman_ |
1071 |
set_hooks_fn(); |
98 |
ossman_ |
1069 |
|
99 |
ossman_ |
1071 |
if (strlen(cmdline) == 0) |
100 |
|
|
{ |
101 |
|
|
message("No command line specified."); |
102 |
|
|
return -1; |
103 |
|
|
} |
104 |
|
|
else |
105 |
|
|
{ |
106 |
|
|
BOOL result; |
107 |
|
|
DWORD exitcode; |
108 |
|
|
PROCESS_INFORMATION proc_info; |
109 |
|
|
STARTUPINFO startup_info; |
110 |
ossman_ |
1069 |
|
111 |
ossman_ |
1071 |
memset(&startup_info, 0, sizeof(STARTUPINFO)); |
112 |
|
|
startup_info.cb = sizeof(STARTUPINFO); |
113 |
ossman_ |
1069 |
|
114 |
ossman_ |
1071 |
result = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, |
115 |
|
|
NULL, NULL, &startup_info, &proc_info); |
116 |
ossman_ |
1069 |
|
117 |
ossman_ |
1071 |
if (result) |
118 |
|
|
{ |
119 |
|
|
do |
120 |
|
|
{ |
121 |
ossman_ |
1074 |
process_cmds(); |
122 |
|
|
Sleep(100); |
123 |
ossman_ |
1071 |
GetExitCodeProcess(proc_info.hProcess, &exitcode); |
124 |
|
|
} |
125 |
|
|
while (exitcode == STILL_ACTIVE); |
126 |
ossman_ |
1069 |
|
127 |
ossman_ |
1071 |
// Release handles |
128 |
|
|
CloseHandle(proc_info.hProcess); |
129 |
|
|
CloseHandle(proc_info.hThread); |
130 |
|
|
} |
131 |
|
|
else |
132 |
|
|
{ |
133 |
|
|
// CreateProcess failed. |
134 |
|
|
char msg[256]; |
135 |
|
|
_snprintf(msg, sizeof(msg), |
136 |
|
|
"Unable to launch the requested application:\n%s", cmdline); |
137 |
|
|
message(msg); |
138 |
|
|
} |
139 |
|
|
} |
140 |
ossman_ |
1069 |
|
141 |
ossman_ |
1071 |
remove_hooks_fn(); |
142 |
ossman_ |
1069 |
|
143 |
ossman_ |
1071 |
FreeLibrary(hookdll); |
144 |
ossman_ |
1069 |
|
145 |
ossman_ |
1074 |
vchannel_close(); |
146 |
|
|
|
147 |
ossman_ |
1071 |
return 1; |
148 |
ossman_ |
1069 |
} |