-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoolsd.c
More file actions
200 lines (176 loc) · 6.22 KB
/
toolsd.c
File metadata and controls
200 lines (176 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* VMSMOUNT - A network redirector for mounting VMware's Shared Folders in DOS
* Copyright (C) 2022 Eduardo Casino
*
* toolsd.c: Minimal VMWare tools daemon
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <dos.h>
#include <stdint.h>
#include "debug.h"
#include "globals.h"
#include "miniclib.h"
#include "vmtool.h"
#define HEARTBEAT_INTERVAL 18 // (1 sec)
#define TCLO_PING "ping"
#define TCLO_RESET "reset"
#define TCLO_VIX_CMD "Vix_1_"
#define TCLO_VIX_MOUNT TCLO_VIX_CMD "Mount_Volumes"
#define TCLO_SUCCESS "OK "
#define TCLO_ERROR "ERROR "
#define TCLO_RST_SUCCESS TCLO_SUCCESS "ATR toolbox"
#define TCLO_UNKNOWN_CMD TCLO_ERROR "Unknown command"
#define TCLO_VIX_SUCCESS TCLO_SUCCESS "0 0"
#define TCLO_VIX_UNSUPPORTED TCLO_ERROR "6 0"
#define TCLO_CMD_MAX_LEN 160
typedef union {
struct
{
uint8_t command[TCLO_CMD_MAX_LEN + 1];
uint32_t commandLen;
} c;
struct
{
uint8_t reply[TCLO_CMD_MAX_LEN + 1];
uint32_t replyLen;
} r;
} TCLOMsg;
#ifdef DEBUG
#define DEB_STACK_SIZE 256
uint8_t debStack[DEB_STACK_SIZE] = {
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC,
0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC, 0xEC};
static uint16_t dosSS;
static uint16_t dosSP;
#endif
rpc_t tclo = {
0, // channel
0, // cookie1
0 // cookie2
};
void(__interrupt __far *fpPrevInt1cHandler)();
static void Int1cToolsd(union INTPACK regset)
#pragma aux Int1cToolsd "*" __parm __caller [] __modify [__ax __bx __cx __dx __si __di __es __gs __fs]
{
// Do not use stack (see how to fix it -zu)
static TCLOMsg msg = {0};
static ticks = HEARTBEAT_INTERVAL;
static uint16_t id;
static int ret;
#ifdef DEBUG
__asm
{
mov dosSS, ss
mov dosSP, sp
mov ax, ds
mov ss, ax
mov sp, (offset debStack) + DEB_STACK_SIZE
}
#endif
if (msg.r.replyLen || ++ticks > HEARTBEAT_INTERVAL)
{
ticks = 0; // Reset heartbeat counter
ret = VMRpcSend(&tclo, &msg.r.reply, msg.r.replyLen);
msg.r.replyLen = 0; // This also sets msg.c.commandLen to 0
if (ret)
{
goto chain;
}
ret = VMRpcRecvLen(&tclo, &msg.c.commandLen, &id);
if (ret || msg.c.commandLen == 0)
{
goto chain;
}
if (msg.c.commandLen > TCLO_CMD_MAX_LEN)
msg.c.commandLen = TCLO_CMD_MAX_LEN;
if (VMRpcRecvDat(&tclo, &msg.c.command, msg.c.commandLen, id) == 0)
{
if (!strncmp_local(msg.c.command, TCLO_RESET, sizeof(TCLO_RESET) - 1))
{
msg.r.replyLen = sizeof(TCLO_RST_SUCCESS) - 1;
memcpy_local(&msg.r.reply, TCLO_RST_SUCCESS, msg.r.replyLen);
}
else if (!strncmp_local(msg.c.command, TCLO_PING, sizeof(TCLO_PING) - 1))
{
msg.r.replyLen = sizeof(TCLO_SUCCESS) - 1;
memcpy_local(&msg.r.reply, TCLO_SUCCESS, msg.r.replyLen);
}
else if (!strncmp_local(msg.c.command, TCLO_VIX_MOUNT, sizeof(TCLO_VIX_MOUNT) - 1))
{
msg.r.replyLen = sizeof(TCLO_VIX_SUCCESS) - 1;
DPRINTF("Received TCLO Vix command: %s", msg.c.command);
memcpy_local(&msg.r.reply, TCLO_VIX_SUCCESS, msg.r.replyLen);
}
else if (!strncmp_local(msg.c.command, TCLO_VIX_CMD, sizeof(TCLO_VIX_CMD) - 1))
{
msg.r.replyLen = sizeof(TCLO_VIX_UNSUPPORTED) - 1;
DPRINTF("Received unsupported TCLO Vix command: %s", msg.c.command);
memcpy_local(&msg.r.reply, TCLO_VIX_UNSUPPORTED, msg.r.replyLen);
}
else
{
#ifdef DEBUG
msg.c.command[msg.c.commandLen] = '\0';
DPRINTF("Received unsupported TCLO command: %s", msg.c.command);
#endif
msg.r.replyLen = sizeof(TCLO_UNKNOWN_CMD) - 1;
memcpy_local(&msg.r.reply, TCLO_UNKNOWN_CMD, msg.r.replyLen);
}
}
}
chain:
#ifdef DEBUG
__asm
{
mov ss, dosSS
mov sp, dosSP
}
#endif
return;
}
void __declspec(naked) __far Int1cHandler(void)
{
__asm
{
pusha
push ds
push es
push fs
push gs
mov bp, sp
push cs
pop ds
call Int1cToolsd
mov bx, word ptr [bp+28] ; restore flags
and bx, 0fcffh ; except for IF and TF
push bx
popf
pop gs
pop fs
pop es
pop ds
popa
jmp dword ptr cs:fpPrevInt1cHandler
}
}