EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
data.js
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2015 Sylvain Peyrefitte
3 *
4 * This file is part of node-rdpjs.
5 *
6 * node-rdpjs is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20var caps = require('./caps');
21var type = require('../../core').type;
22var log = require('../../core').log;
23
24/**
25 * @see http://msdn.microsoft.com/en-us/library/cc240576.aspx
26 */
27var PDUType = {
28 PDUTYPE_DEMANDACTIVEPDU : 0x11,
29 PDUTYPE_CONFIRMACTIVEPDU : 0x13,
30 PDUTYPE_DEACTIVATEALLPDU : 0x16,
31 PDUTYPE_DATAPDU : 0x17,
32 PDUTYPE_SERVER_REDIR_PKT : 0x1A
33};
34
35/**
36 * @see http://msdn.microsoft.com/en-us/library/cc240577.aspx
37 */
38var PDUType2 = {
39 PDUTYPE2_UPDATE : 0x02,
40 PDUTYPE2_CONTROL : 0x14,
41 PDUTYPE2_POINTER : 0x1B,
42 PDUTYPE2_INPUT : 0x1C,
43 PDUTYPE2_SYNCHRONIZE : 0x1F,
44 PDUTYPE2_REFRESH_RECT : 0x21,
45 PDUTYPE2_PLAY_SOUND : 0x22,
46 PDUTYPE2_SUPPRESS_OUTPUT : 0x23,
47 PDUTYPE2_SHUTDOWN_REQUEST : 0x24,
48 PDUTYPE2_SHUTDOWN_DENIED : 0x25,
49 PDUTYPE2_SAVE_SESSION_INFO : 0x26,
50 PDUTYPE2_FONTLIST : 0x27,
51 PDUTYPE2_FONTMAP : 0x28,
52 PDUTYPE2_SET_KEYBOARD_INDICATORS : 0x29,
53 PDUTYPE2_BITMAPCACHE_PERSISTENT_LIST : 0x2B,
54 PDUTYPE2_BITMAPCACHE_ERROR_PDU : 0x2C,
55 PDUTYPE2_SET_KEYBOARD_IME_STATUS : 0x2D,
56 PDUTYPE2_OFFSCRCACHE_ERROR_PDU : 0x2E,
57 PDUTYPE2_SET_ERROR_INFO_PDU : 0x2F,
58 PDUTYPE2_DRAWNINEGRID_ERROR_PDU : 0x30,
59 PDUTYPE2_DRAWGDIPLUS_ERROR_PDU : 0x31,
60 PDUTYPE2_ARC_STATUS_PDU : 0x32,
61 PDUTYPE2_STATUS_INFO_PDU : 0x36,
62 PDUTYPE2_MONITOR_LAYOUT_PDU : 0x37
63};
64
65/**
66 * @see http://msdn.microsoft.com/en-us/library/cc240577.aspx
67 */
68var StreamId = {
69 STREAM_UNDEFINED : 0x00,
70 STREAM_LOW : 0x01,
71 STREAM_MED : 0x02,
72 STREAM_HI : 0x04
73};
74
75/**
76 * @see http://msdn.microsoft.com/en-us/library/cc240577.aspx
77 */
78var CompressionOrder = {
79 CompressionTypeMask : 0x0F,
80 PACKET_COMPRESSED : 0x20,
81 PACKET_AT_FRONT : 0x40,
82 PACKET_FLUSHED : 0x80
83};
84
85/**
86 * @see http://msdn.microsoft.com/en-us/library/cc240577.aspx
87 */
88var CompressionType = {
89 PACKET_COMPR_TYPE_8K : 0x0,
90 PACKET_COMPR_TYPE_64K : 0x1,
91 PACKET_COMPR_TYPE_RDP6 : 0x2,
92 PACKET_COMPR_TYPE_RDP61 : 0x3,
93};
94
95/**
96 * @see http://msdn.microsoft.com/en-us/library/cc240492.aspx
97 */
98var Action = {
99 CTRLACTION_REQUEST_CONTROL : 0x0001,
100 CTRLACTION_GRANTED_CONTROL : 0x0002,
101 CTRLACTION_DETACH : 0x0003,
102 CTRLACTION_COOPERATE : 0x0004
103};
104
105/**
106 * @see http://msdn.microsoft.com/en-us/library/cc240495.aspx
107 */
108var PersistentKeyListFlag = {
109 PERSIST_FIRST_PDU : 0x01,
110 PERSIST_LAST_PDU : 0x02
111};
112
113/**
114 * @see http://msdn.microsoft.com/en-us/library/cc240612.aspx
115 */
116var BitmapFlag = {
117 BITMAP_COMPRESSION : 0x0001,
118 NO_BITMAP_COMPRESSION_HDR : 0x0400
119};
120
121/**
122 * @see http://msdn.microsoft.com/en-us/library/cc240608.aspx
123 */
124var UpdateType = {
125 UPDATETYPE_ORDERS : 0x0000,
126 UPDATETYPE_BITMAP : 0x0001,
127 UPDATETYPE_PALETTE : 0x0002,
128 UPDATETYPE_SYNCHRONIZE : 0x0003
129};
130
131/**
132 * @see http://msdn.microsoft.com/en-us/library/cc240608.aspx
133 */
134var UpdateType = {
135 UPDATETYPE_ORDERS : 0x0000,
136 UPDATETYPE_BITMAP : 0x0001,
137 UPDATETYPE_PALETTE : 0x0002,
138 UPDATETYPE_SYNCHRONIZE : 0x0003
139};
140
141/**
142 * @see http://msdn.microsoft.com/en-us/library/cc240583.aspx
143 */
144var InputMessageType = {
145 INPUT_EVENT_SYNC : 0x0000,
146 INPUT_EVENT_UNUSED : 0x0002,
147 INPUT_EVENT_SCANCODE : 0x0004,
148 INPUT_EVENT_UNICODE : 0x0005,
149 INPUT_EVENT_MOUSE : 0x8001,
150 INPUT_EVENT_MOUSEX : 0x8002
151};
152
153/**
154 * @see http://msdn.microsoft.com/en-us/library/cc240586.aspx
155 */
156var PointerFlag = {
157 PTRFLAGS_HWHEEL : 0x0400,
158 PTRFLAGS_WHEEL : 0x0200,
159 PTRFLAGS_WHEEL_NEGATIVE : 0x0100,
160 WheelRotationMask : 0x01FF,
161 PTRFLAGS_MOVE : 0x0800,
162 PTRFLAGS_DOWN : 0x8000,
163 PTRFLAGS_BUTTON1 : 0x1000,
164 PTRFLAGS_BUTTON2 : 0x2000,
165 PTRFLAGS_BUTTON3 : 0x4000
166};
167
168/**
169 * @see http://msdn.microsoft.com/en-us/library/cc240584.aspx
170 */
171var KeyboardFlag = {
172 KBDFLAGS_EXTENDED : 0x0100,
173 KBDFLAGS_DOWN : 0x4000,
174 KBDFLAGS_RELEASE : 0x8000
175};
176
177/**
178 * @see http://msdn.microsoft.com/en-us/library/cc240622.aspx
179 */
180var FastPathUpdateType = {
181 FASTPATH_UPDATETYPE_ORDERS : 0x0,
182 FASTPATH_UPDATETYPE_BITMAP : 0x1,
183 FASTPATH_UPDATETYPE_PALETTE : 0x2,
184 FASTPATH_UPDATETYPE_SYNCHRONIZE : 0x3,
185 FASTPATH_UPDATETYPE_SURFCMDS : 0x4,
186 FASTPATH_UPDATETYPE_PTR_NULL : 0x5,
187 FASTPATH_UPDATETYPE_PTR_DEFAULT : 0x6,
188 FASTPATH_UPDATETYPE_PTR_POSITION : 0x8,
189 FASTPATH_UPDATETYPE_COLOR : 0x9, // Mouse cursor
190 FASTPATH_UPDATETYPE_CACHED : 0xA,
191 FASTPATH_UPDATETYPE_POINTER : 0xB
192};
193
194/**
195 * @see http://msdn.microsoft.com/en-us/library/cc240622.aspx
196 */
197var FastPathOutputCompression = {
198 FASTPATH_OUTPUT_COMPRESSION_USED : 0x2
199};
200
201/**
202 * @see http://msdn.microsoft.com/en-us/library/cc240648.aspx
203 */
204var Display = {
205 SUPPRESS_DISPLAY_UPDATES : 0x00,
206 ALLOW_DISPLAY_UPDATES : 0x01
207};
208
209/**
210 * @see https://msdn.microsoft.com/en-us/library/cc240588.aspx
211 */
212var ToogleFlag = {
213 TS_SYNC_SCROLL_LOCK : 0x00000001,
214 TS_SYNC_NUM_LOCK : 0x00000002,
215 TS_SYNC_CAPS_LOCK : 0x00000004,
216 TS_SYNC_KANA_LOCK : 0x00000008
217};
218
219/**
220 * @see http://msdn.microsoft.com/en-us/library/cc240544.aspx
221 */
222var ErrorInfo = {
223 ERRINFO_RPC_INITIATED_DISCONNECT : 0x00000001,
224 ERRINFO_RPC_INITIATED_LOGOFF : 0x00000002,
225 ERRINFO_IDLE_TIMEOUT : 0x00000003,
226 ERRINFO_LOGON_TIMEOUT : 0x00000004,
227 ERRINFO_DISCONNECTED_BY_OTHERCONNECTION : 0x00000005,
228 ERRINFO_OUT_OF_MEMORY : 0x00000006,
229 ERRINFO_SERVER_DENIED_CONNECTION : 0x00000007,
230 ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES : 0x00000009,
231 ERRINFO_SERVER_FRESH_CREDENTIALS_REQUIRED : 0x0000000A,
232 ERRINFO_RPC_INITIATED_DISCONNECT_BYUSER : 0x0000000B,
233 ERRINFO_LOGOFF_BY_USER : 0x0000000C,
234 ERRINFO_LICENSE_INTERNAL : 0x00000100,
235 ERRINFO_LICENSE_NO_LICENSE_SERVER : 0x00000101,
236 ERRINFO_LICENSE_NO_LICENSE : 0x00000102,
237 ERRINFO_LICENSE_BAD_CLIENT_MSG : 0x00000103,
238 ERRINFO_LICENSE_HWID_DOESNT_MATCH_LICENSE : 0x00000104,
239 ERRINFO_LICENSE_BAD_CLIENT_LICENSE : 0x00000105,
240 ERRINFO_LICENSE_CANT_FINISH_PROTOCOL : 0x00000106,
241 ERRINFO_LICENSE_CLIENT_ENDED_PROTOCOL : 0x00000107,
242 ERRINFO_LICENSE_BAD_CLIENT_ENCRYPTION : 0x00000108,
243 ERRINFO_LICENSE_CANT_UPGRADE_LICENSE : 0x00000109,
244 ERRINFO_LICENSE_NO_REMOTE_CONNECTIONS : 0x0000010A,
245 ERRINFO_CB_DESTINATION_NOT_FOUND : 0x0000400,
246 ERRINFO_CB_LOADING_DESTINATION : 0x0000402,
247 ERRINFO_CB_REDIRECTING_TO_DESTINATION : 0x0000404,
248 ERRINFO_CB_SESSION_ONLINE_VM_WAKE : 0x0000405,
249 ERRINFO_CB_SESSION_ONLINE_VM_BOOT : 0x0000406,
250 ERRINFO_CB_SESSION_ONLINE_VM_NO_DNS : 0x0000407,
251 ERRINFO_CB_DESTINATION_POOL_NOT_FREE : 0x0000408,
252 ERRINFO_CB_CONNECTION_CANCELLED : 0x0000409,
253 ERRINFO_CB_CONNECTION_ERROR_INVALID_SETTINGS : 0x0000410,
254 ERRINFO_CB_SESSION_ONLINE_VM_BOOT_TIMEOUT : 0x0000411,
255 ERRINFO_CB_SESSION_ONLINE_VM_SESSMON_FAILED : 0x0000412,
256 ERRINFO_UNKNOWNPDUTYPE2 : 0x000010C9,
257 ERRINFO_UNKNOWNPDUTYPE : 0x000010CA,
258 ERRINFO_DATAPDUSEQUENCE : 0x000010CB,
259 ERRINFO_CONTROLPDUSEQUENCE : 0x000010CD,
260 ERRINFO_INVALIDCONTROLPDUACTION : 0x000010CE,
261 ERRINFO_INVALIDINPUTPDUTYPE : 0x000010CF,
262 ERRINFO_INVALIDINPUTPDUMOUSE : 0x000010D0,
263 ERRINFO_INVALIDREFRESHRECTPDU : 0x000010D1,
264 ERRINFO_CREATEUSERDATAFAILED : 0x000010D2,
265 ERRINFO_CONNECTFAILED : 0x000010D3,
266 ERRINFO_CONFIRMACTIVEWRONGSHAREID : 0x000010D4,
267 ERRINFO_CONFIRMACTIVEWRONGORIGINATOR : 0x000010D5,
268 ERRINFO_PERSISTENTKEYPDUBADLENGTH : 0x000010DA,
269 ERRINFO_PERSISTENTKEYPDUILLEGALFIRST : 0x000010DB,
270 ERRINFO_PERSISTENTKEYPDUTOOMANYTOTALKEYS : 0x000010DC,
271 ERRINFO_PERSISTENTKEYPDUTOOMANYCACHEKEYS : 0x000010DD,
272 ERRINFO_INPUTPDUBADLENGTH : 0x000010DE,
273 ERRINFO_BITMAPCACHEERRORPDUBADLENGTH : 0x000010DF,
274 ERRINFO_SECURITYDATATOOSHORT : 0x000010E0,
275 ERRINFO_VCHANNELDATATOOSHORT : 0x000010E1,
276 ERRINFO_SHAREDATATOOSHORT : 0x000010E2,
277 ERRINFO_BADSUPRESSOUTPUTPDU : 0x000010E3,
278 ERRINFO_CONFIRMACTIVEPDUTOOSHORT : 0x000010E5,
279 ERRINFO_CAPABILITYSETTOOSMALL : 0x000010E7,
280 ERRINFO_CAPABILITYSETTOOLARGE : 0x000010E8,
281 ERRINFO_NOCURSORCACHE : 0x000010E9,
282 ERRINFO_BADCAPABILITIES : 0x000010EA,
283 ERRINFO_VIRTUALCHANNELDECOMPRESSIONERR : 0x000010EC,
284 ERRINFO_INVALIDVCCOMPRESSIONTYPE : 0x000010ED,
285 ERRINFO_INVALIDCHANNELID : 0x000010EF,
286 ERRINFO_VCHANNELSTOOMANY : 0x000010F0,
287 ERRINFO_REMOTEAPPSNOTENABLED : 0x000010F3,
288 ERRINFO_CACHECAPNOTSET : 0x000010F4,
289 ERRINFO_BITMAPCACHEERRORPDUBADLENGTH2 : 0x000010F5,
290 ERRINFO_OFFSCRCACHEERRORPDUBADLENGTH : 0x000010F6,
291 ERRINFO_DNGCACHEERRORPDUBADLENGTH : 0x000010F7,
292 ERRINFO_GDIPLUSPDUBADLENGTH : 0x000010F8,
293 ERRINFO_SECURITYDATATOOSHORT2 : 0x00001111,
294 ERRINFO_SECURITYDATATOOSHORT3 : 0x00001112,
295 ERRINFO_SECURITYDATATOOSHORT4 : 0x00001113,
296 ERRINFO_SECURITYDATATOOSHORT5 : 0x00001114,
297 ERRINFO_SECURITYDATATOOSHORT6 : 0x00001115,
298 ERRINFO_SECURITYDATATOOSHORT7 : 0x00001116,
299 ERRINFO_SECURITYDATATOOSHORT8 : 0x00001117,
300 ERRINFO_SECURITYDATATOOSHORT9 : 0x00001118,
301 ERRINFO_SECURITYDATATOOSHORT10 : 0x00001119,
302 ERRINFO_SECURITYDATATOOSHORT11 : 0x0000111A,
303 ERRINFO_SECURITYDATATOOSHORT12 : 0x0000111B,
304 ERRINFO_SECURITYDATATOOSHORT13 : 0x0000111C,
305 ERRINFO_SECURITYDATATOOSHORT14 : 0x0000111D,
306 ERRINFO_SECURITYDATATOOSHORT15 : 0x0000111E,
307 ERRINFO_SECURITYDATATOOSHORT16 : 0x0000111F,
308 ERRINFO_SECURITYDATATOOSHORT17 : 0x00001120,
309 ERRINFO_SECURITYDATATOOSHORT18 : 0x00001121,
310 ERRINFO_SECURITYDATATOOSHORT19 : 0x00001122,
311 ERRINFO_SECURITYDATATOOSHORT20 : 0x00001123,
312 ERRINFO_SECURITYDATATOOSHORT21 : 0x00001124,
313 ERRINFO_SECURITYDATATOOSHORT22 : 0x00001125,
314 ERRINFO_SECURITYDATATOOSHORT23 : 0x00001126,
315 ERRINFO_BADMONITORDATA : 0x00001129,
316 ERRINFO_VCDECOMPRESSEDREASSEMBLEFAILED : 0x0000112A,
317 ERRINFO_VCDATATOOLONG : 0x0000112B,
318 ERRINFO_BAD_FRAME_ACK_DATA : 0x0000112C,
319 ERRINFO_GRAPHICSMODENOTSUPPORTED : 0x0000112D,
320 ERRINFO_GRAPHICSSUBSYSTEMRESETFAILED : 0x0000112E,
321 ERRINFO_GRAPHICSSUBSYSTEMFAILED : 0x0000112F,
322 ERRINFO_TIMEZONEKEYNAMELENGTHTOOSHORT : 0x00001130,
323 ERRINFO_TIMEZONEKEYNAMELENGTHTOOLONG : 0x00001131,
324 ERRINFO_DYNAMICDSTDISABLEDFIELDMISSING : 0x00001132,
325 ERRINFO_VCDECODINGERROR : 0x00001133,
326 ERRINFO_UPDATESESSIONKEYFAILED : 0x00001191,
327 ERRINFO_DECRYPTFAILED : 0x00001192,
328 ERRINFO_ENCRYPTFAILED : 0x00001193,
329 ERRINFO_ENCPKGMISMATCH : 0x00001194,
330 ERRINFO_DECRYPTFAILED2 : 0x00001195
331};
332
333/**
334 * @see http://msdn.microsoft.com/en-us/library/cc240576.aspx
335 * @param length {integer} length of entire pdu packet
336 * @param pduType {PDUType.*} type of pdu packet
337 * @param userId {integer}
338 * @param opt {object} type option
339 * @returns {type.Component}
340 */
341function shareControlHeader(length, pduType, userId, opt) {
342 var self = {
343 totalLength : new type.UInt16Le(length),
344 pduType : new type.UInt16Le(pduType),
345 // for xp sp3 and deactiveallpdu PDUSource may not be present
346 PDUSource : new type.UInt16Le(userId, { optional : true })
347 };
348
349 return new type.Component(self, opt);
350}
351
352/**
353 * @see http://msdn.microsoft.com/en-us/library/cc240577.aspx
354 * @param length {integer} lezngth of entire packet
355 * @param pduType2 {PDUType2.*} sub PDU type
356 * @param shareId {integer} global layer id
357 * @param opt {object} type option
358 * @returns {type.Component}
359 */
360function shareDataHeader(length, pduType2, shareId, opt) {
361 var self = {
362 shareId : new type.UInt32Le(shareId),
363 pad1 : new type.UInt8(),
364 streamId : new type.UInt8(StreamId.STREAM_LOW),
365 uncompressedLength : new type.UInt16Le(function() {
366 return length.value - 8;
367 }),
368 pduType2 : new type.UInt8(pduType2),
369 compressedType : new type.UInt8(),
370 compressedLength : new type.UInt16Le()
371 };
372
373 return new type.Component(self, opt);
374}
375
376/**
377 * @see http://msdn.microsoft.com/en-us/library/cc240485.aspx
378 * @param capabilities {type.Component} capabilities array
379 * @param opt {object} type option
380 * @returns {type.Component}
381 */
382function demandActivePDU(capabilities, opt) {
383 var self = {
384 __PDUTYPE__ : PDUType.PDUTYPE_DEMANDACTIVEPDU,
385 shareId : new type.UInt32Le(),
386 lengthSourceDescriptor : new type.UInt16Le(function() {
387 return self.sourceDescriptor.size();
388 }),
389 lengthCombinedCapabilities : new type.UInt16Le(function() {
390 return self.numberCapabilities.size() + self.pad2Octets.size() + self.capabilitySets.size();
391 }),
392 sourceDescriptor : new type.BinaryString(Buffer.from('node-rdpjs', 'binary'), { readLength : new type.CallableValue(function() {
393 return self.lengthSourceDescriptor.value
394 }) }),
395 numberCapabilities : new type.UInt16Le(function() {
396 return self.capabilitySets.obj.length;
397 }),
398 pad2Octets : new type.UInt16Le(),
399 capabilitySets : capabilities || new type.Factory(function(s) {
400 self.capabilitySets = new type.Component([]);
401 for(var i = 0; i < self.numberCapabilities.value; i++) {
402 self.capabilitySets.obj.push(caps.capability().read(s))
403 }
404 }),
405 sessionId : new type.UInt32Le()
406 };
407
408 return new type.Component(self, opt);
409}
410
411/**
412 * @see http://msdn.microsoft.com/en-us/library/cc240488.aspx
413 * @param capabilities {type.Component} capabilities array
414 * @param shareId {integer} session id
415 * @param opt {object} type option
416 * @returns {type.Component}
417 */
418function confirmActivePDU(capabilities, shareId, opt) {
419 var self = {
420 __PDUTYPE__ : PDUType.PDUTYPE_CONFIRMACTIVEPDU,
421 shareId : new type.UInt32Le(shareId),
422 originatorId : new type.UInt16Le(0x03EA, { constant : true }),
423 lengthSourceDescriptor : new type.UInt16Le(function() {
424 return self.sourceDescriptor.size();
425 }),
426 lengthCombinedCapabilities : new type.UInt16Le(function() {
427 return self.numberCapabilities.size() + self.pad2Octets.size() + self.capabilitySets.size();
428 }),
429 sourceDescriptor : new type.BinaryString(Buffer.from('rdpy', 'binary'), { readLength : new type.CallableValue(function() {
430 return self.lengthSourceDescriptor.value
431 }) }),
432 numberCapabilities : new type.UInt16Le(function() {
433 return self.capabilitySets.obj.length;
434 }),
435 pad2Octets : new type.UInt16Le(),
436 capabilitySets : capabilities || new type.Factory(function(s) {
437 self.capabilitySets = new type.Component([]);
438 for(var i = 0; i < self.numberCapabilities.value; i++) {
439 self.capabilitySets.obj.push(caps.capability().read(s))
440 }
441 })
442 };
443
444 return new type.Component(self, opt);
445}
446
447/**
448 * @see http://msdn.microsoft.com/en-us/library/cc240536.aspx
449 * @param opt {object} type option
450 * @returns {type.Component}
451 */
452function deactiveAllPDU(opt) {
453 var self = {
454 __PDUTYPE__ : PDUType.PDUTYPE_DEACTIVATEALLPDU,
455 shareId : new type.UInt32Le(),
456 lengthSourceDescriptor : new type.UInt16Le(function() {
457 return self.sourceDescriptor.size();
458 }),
459 sourceDescriptor : new type.BinaryString(Buffer.from('rdpy', 'binary'), { readLength : new type.CallableValue(function() {
460 self.lengthSourceDescriptor
461 }) })
462 };
463
464 return new type.Component(self, opt);
465}
466
467/**
468 * @see http://msdn.microsoft.com/en-us/library/cc240490.aspx
469 * @param opt {object} type option
470 * @returns {type.Component}
471 */
472function synchronizeDataPDU(targetUser, opt) {
473 var self = {
474 __PDUTYPE2__ : PDUType2.PDUTYPE2_SYNCHRONIZE,
475 messageType : new type.UInt16Le(1, { constant : true }),
476 targetUser : new type.UInt16Le(targetUser)
477 };
478
479 return new type.Component(self, opt);
480}
481
482/**
483 * @see http://msdn.microsoft.com/en-us/library/cc240492.aspx
484 * @param action {integer}
485 * @param opt {object} type option
486 * @returns {type.Component}
487 */
488function controlDataPDU(action, opt) {
489 var self = {
490 __PDUTYPE2__ : PDUType2.PDUTYPE2_CONTROL,
491 action : new type.UInt16Le(action),
492 grantId : new type.UInt16Le(),
493 controlId : new type.UInt32Le()
494 };
495
496 return new type.Component(self, opt);
497}
498
499/**
500 * @see http://msdn.microsoft.com/en-us/library/cc240544.aspx
501 * @param errorInfo {integer}
502 * @param opt {object} type option
503 * @returns {type.Component}
504 */
505function errorInfoDataPDU(errorInfo, opt) {
506 var self = {
507 __PDUTYPE2__ : PDUType2.PDUTYPE2_SET_ERROR_INFO_PDU,
508 errorInfo : new type.UInt32Le(errorInfo)
509 };
510
511 return new type.Component(self, opt);
512}
513
514/**
515 * @see http://msdn.microsoft.com/en-us/library/cc240498.aspx
516 * @param opt {object} type option
517 * @returns {type.Component}
518 */
519function fontListDataPDU(opt) {
520 var self = {
521 __PDUTYPE2__ : PDUType2.PDUTYPE2_FONTLIST,
522 numberFonts : new type.UInt16Le(),
523 totalNumFonts : new type.UInt16Le(),
524 listFlags : new type.UInt16Le(0x0003),
525 entrySize : new type.UInt16Le(0x0032)
526 };
527
528 return new type.Component(self, opt);
529}
530
531/**
532 * @see http://msdn.microsoft.com/en-us/library/cc240498.aspx
533 * @param opt {object} type option
534 * @returns {type.Component}
535 */
536function fontMapDataPDU(opt) {
537 var self = {
538 __PDUTYPE2__ : PDUType2.PDUTYPE2_FONTMAP,
539 numberEntries : new type.UInt16Le(),
540 totalNumEntries : new type.UInt16Le(),
541 mapFlags : new type.UInt16Le(0x0003),
542 entrySize : new type.UInt16Le(0x0004)
543 };
544
545 return new type.Component(self, opt);
546}
547
548/**
549 * @see http://msdn.microsoft.com/en-us/library/cc240496.aspx
550 * @param opt {object} type option
551 * @returns {type.Component}
552 */
553function persistentListEntry(opt) {
554 var self = {
555 key1 : new type.UInt32Le(),
556 key2 : new type.UInt32Le()
557 };
558
559 return new type.Component(self, opt);
560}
561
562/**
563 * @see http://msdn.microsoft.com/en-us/library/cc240495.aspx
564 * @param entries {type.Component}
565 * @param opt {object} type option
566 * @returns {type.Component}
567 */
568function persistentListPDU(entries, opt) {
569 var self = {
570 __PDUTYPE2__ : PDUType2.PDUTYPE2_BITMAPCACHE_PERSISTENT_LIST,
571 numEntriesCache0 : new type.UInt16Le(),
572 numEntriesCache1 : new type.UInt16Le(),
573 numEntriesCache2 : new type.UInt16Le(),
574 numEntriesCache3 : new type.UInt16Le(),
575 numEntriesCache4 : new type.UInt16Le(),
576 totalEntriesCache0 : new type.UInt16Le(),
577 totalEntriesCache1 : new type.UInt16Le(),
578 totalEntriesCache2 : new type.UInt16Le(),
579 totalEntriesCache3 : new type.UInt16Le(),
580 totalEntriesCache4 : new type.UInt16Le(),
581 bitMask : new type.UInt8(),
582 pad2 : new type.UInt8(),
583 pad3 : new type.UInt16Le(),
584 entries : entries || new type.Factory(function(s) {
585 var numEntries = self.numEntriesCache0.value + self.numEntriesCache1.value + self.numEntriesCache2.value + self.numEntriesCache3.value + self.numEntriesCache4.value;
586 self.entries = new type.Component([]);
587 for(var i = 0; i < numEntries; i++) {
588 self.entries.obj.push(persistentListEntry().read(s));
589 }
590 })
591 };
592
593 return new type.Component(self, opt);
594}
595
596/**
597 * @see https://msdn.microsoft.com/en-us/library/cc240588.aspx
598 * @param opt {object} type option
599 * @returns {type.Component}
600 */
601function synchronizeEvent(opt) {
602 var self = {
603 __INPUT_MESSAGE_TYPE__ : InputMessageType.INPUT_EVENT_SYNC,
604 pad2Octets : new type.UInt16Le(),
605 toggleFlags : new type.UInt32Le()
606 };
607
608 return new type.Component(self, opt);
609}
610
611/**
612 * @see http://msdn.microsoft.com/en-us/library/cc240586.aspx
613 * @param opt {object} type option
614 * @returns {type.Component}
615 */
616function pointerEvent(opt) {
617 var self = {
618 __INPUT_MESSAGE_TYPE__ : InputMessageType.INPUT_EVENT_MOUSE,
619 pointerFlags : new type.UInt16Le(),
620 xPos : new type.UInt16Le(),
621 yPos : new type.UInt16Le()
622 };
623
624 return new type.Component(self, opt);
625}
626
627/**
628 * @see http://msdn.microsoft.com/en-us/library/cc240584.aspx
629 * @param opt {object} type option
630 * @returns {type.Component}
631 */
632function scancodeKeyEvent(opt) {
633 var self = {
634 __INPUT_MESSAGE_TYPE__ : InputMessageType.INPUT_EVENT_SCANCODE,
635 keyboardFlags : new type.UInt16Le(),
636 keyCode : new type.UInt16Le(),
637 pad2Octets : new type.UInt16Le()
638 };
639
640 return new type.Component(self, opt);
641}
642
643/**
644 * @see http://msdn.microsoft.com/en-us/library/cc240585.aspx
645 * @param opt {object} type option
646 * @returns {type.Component}
647 */
648function unicodeKeyEvent(opt) {
649 var self = {
650 __INPUT_MESSAGE_TYPE__ : InputMessageType.INPUT_EVENT_UNICODE,
651 keyboardFlags : new type.UInt16Le(),
652 unicode : new type.UInt16Le(),
653 pad2Octets : new type.UInt16Le()
654 };
655
656 return new type.Component(self, opt);
657}
658
659/**
660 * @see http://msdn.microsoft.com/en-us/library/cc240583.aspx
661 * @param slowPathInputData {type.Component} message generate for slow path input event
662 * @param opt {object} type option
663 * @returns {type.Component}
664 */
665function slowPathInputEvent(slowPathInputData, opt) {
666 var self = {
667 eventTime : new type.UInt32Le(),
668 messageType : new type.UInt16Le(function() {
669 return self.slowPathInputData.obj.__INPUT_MESSAGE_TYPE__;
670 }),
671 slowPathInputData : slowPathInputData || new type.Factory(function(s) {
672 switch(self.messageType.value) {
673 case InputMessageType.INPUT_EVENT_SYNC:
674 self.slowPathInputData = synchronizeEvent().read(s);
675 break;
676 case InputMessageType.INPUT_EVENT_MOUSE:
677 self.slowPathInputData = pointerEvent().read(s);
678 break;
679 case InputMessageType.INPUT_EVENT_SCANCODE:
680 self.slowPathInputData = scancodeKeyEvent().read(s);
681 break;
682 case InputMessageType.INPUT_EVENT_UNICODE:
683 self.slowPathInputData = unicodeKeyEvent().read(s);
684 break;
685 default:
686 log.error('unknown slowPathInputEvent ' + self.messageType.value);
687 }
688 })
689 };
690
691 return new type.Component(self, opt);
692}
693
694/**
695 * @see http://msdn.microsoft.com/en-us/library/cc746160.aspx
696 * @param inputs {type.Component} list of inputs
697 * @param opt {object} type option
698 * @returns {type.Component}
699 */
700function clientInputEventPDU(inputs, opt) {
701 var self = {
702 __PDUTYPE2__ : PDUType2.PDUTYPE2_INPUT,
703 numEvents : new type.UInt16Le(function() {
704 return self.slowPathInputEvents.obj.length;
705 }),
706 pad2Octets : new type.UInt16Le(),
707 slowPathInputEvents : inputs || new type.Factory(function(s) {
708 self.slowPathInputEvents = new type.Component([]);
709 for(var i = 0; i < self.numEvents.value; i++) {
710 self.slowPathInputEvents.obj.push(slowPathInputEvent().read(s));
711 }
712 })
713 };
714
715 return new type.Component(self, opt);
716}
717
718/**
719 * @param opt {object} type option
720 * @returns {type.Component}
721 */
722function shutdownRequestPDU(opt) {
723 var self = {
724 __PDUTYPE2__ : PDUType2.PDUTYPE2_SHUTDOWN_REQUEST
725 };
726
727 return new type.Component(self, opt);
728}
729
730/**
731 * @param opt {object} type option
732 * @returns {type.Component}
733 */
734function shutdownDeniedPDU(opt) {
735 var self = {
736 __PDUTYPE2__ : PDUType2.PDUTYPE2_SHUTDOWN_DENIED
737 };
738
739 return new type.Component(self, opt);
740}
741
742/**
743 * @see http://msdn.microsoft.com/en-us/library/cc240643.aspx
744 * @param opt {object} type option
745 * @returns {type.Component}
746 */
747function inclusiveRectangle(opt) {
748 var self = {
749 left : new type.UInt16Le(),
750 top : new type.UInt16Le(),
751 right : new type.UInt16Le(),
752 bottom : new type.UInt16Le()
753 };
754
755 return new type.Component(self, opt);
756}
757
758/**
759 * @see http://msdn.microsoft.com/en-us/library/cc240648.aspx
760 * @param opt {object} type option
761 * @returns {type.Component}
762 */
763function supressOutputDataPDU(opt) {
764 var self = {
765 __PDUTYPE2__ : PDUType2.PDUTYPE2_SUPPRESS_OUTPUT,
766 allowDisplayUpdates : new type.UInt8(),
767 pad3Octets : new type.Component([new type.UInt8(), new type.UInt8(), new type.UInt8()]),
768 desktopRect : inclusiveRectangle({ conditional : function() {
769 return self.allowDisplayUpdates.value === Display.ALLOW_DISPLAY_UPDATES;
770 } })
771 };
772
773 return new type.Component(self, opt);
774}
775
776/**
777 * @see http://msdn.microsoft.com/en-us/library/cc240646.aspx
778 * @param rectangles {type.Component} list of inclusive rectangles
779 * @param opt {object} type option
780 * @returns {type.Component}
781 */
782function refreshRectPDU(rectangles, opt) {
783 var self = {
784 __PDUTYPE2__ : PDUType2.PDUTYPE2_REFRESH_RECT,
785 numberOfAreas : UInt8(function() {
786 return self.areasToRefresh.obj.length;
787 }),
788 pad3Octets : new type.Component([new type.UInt8(), new type.UInt8(), new type.UInt8()]),
789 areasToRefresh : rectangles || new type.Factory(function(s) {
790 self.areasToRefresh = new type.Component([]);
791 for(var i = 0; i < self.numberOfAreas.value; i++) {
792 self.areasToRefresh.obj.push(inclusiveRectangle().read(s));
793 }
794 })
795 };
796
797 return new type.Component(self, opt);
798}
799
800/**
801 * @see http://msdn.microsoft.com/en-us/library/cc240644.aspx
802 * @param opt {object} type option
803 * @returns {type.Component}
804 */
805function bitmapCompressedDataHeader(opt) {
806 var self = {
807 cbCompFirstRowSize : new type.UInt16Le(0x0000, { constant : true }),
808 // compressed data size
809 cbCompMainBodySize : new type.UInt16Le(),
810 cbScanWidth : new type.UInt16Le(),
811 // uncompressed data size
812 cbUncompressedSize : new type.UInt16Le()
813 };
814
815 return new type.Component(self, opt);
816}
817
818/**
819 * @see
820 * @param coord {object}
821 * .destLeft {integer}
822 * .destTop {integer}
823 * .destRight {integer}
824 * .destBottom {integer}
825 * .width {integer}
826 * .height {integer}
827 * .bitsPerPixel {integer}
828 * .data {Buffer}
829 * @param opt {object} type option
830 * @returns {type.Component}
831 */
832function bitmapData(coord, opt) {
833 coord = coord || {};
834 var self = {
835 destLeft : new type.UInt16Le(coord.destLeft),
836 destTop : new type.UInt16Le(coord.destTop),
837 destRight : new type.UInt16Le(coord.destRight),
838 destBottom : new type.UInt16Le(coord.destBottom),
839 width : new type.UInt16Le(coord.width),
840 height : new type.UInt16Le(coord.height),
841 bitsPerPixel : new type.UInt16Le(coord.bitsPerPixel),
842 flags : new type.UInt16Le(),
843 bitmapLength : new type.UInt16Le(function() {
844 return self.bitmapComprHdr.size() + self.bitmapDataStream.size();
845 }),
846 bitmapComprHdr : bitmapCompressedDataHeader( { conditional : function() {
847 return (self.flags.value & BitmapFlag.BITMAP_COMPRESSION) && !(self.flags.value & BitmapFlag.NO_BITMAP_COMPRESSION_HDR);
848 } }),
849 bitmapDataStream : new type.BinaryString(coord.data, { readLength : new type.CallableValue(function() {
850 if(!self.flags.value & BitmapFlag.BITMAP_COMPRESSION || (self.flags.value & BitmapFlag.NO_BITMAP_COMPRESSION_HDR)) {
851 return self.bitmapLength.value;
852 }
853 else {
854 return self.bitmapComprHdr.cbCompMainBodySize.value;
855 }
856 }) })
857 };
858
859 return new type.Component(self, opt);
860}
861
862/**
863 * @see http://msdn.microsoft.com/en-us/library/dd306368.aspx
864 * @param data {type.Component} list of bitmap data type
865 * @param opt {object} type option
866 * @returns {type.Component}
867 */
868function bitmapUpdateDataPDU(data, opt) {
869 var self = {
870 __UPDATE_TYPE__ : UpdateType.UPDATETYPE_BITMAP,
871 numberRectangles : new type.UInt16Le(function() {
872 return self.rectangles.obj.length;
873 }),
874 rectangles : data || new type.Factory(function(s) {
875 self.rectangles = new type.Component([]);
876 for(var i = 0; i < self.numberRectangles.value; i++) {
877 self.rectangles.obj.push(bitmapData().read(s));
878 }
879 })
880 };
881
882 return new type.Component(self, opt);
883}
884
885/**
886 * @see https://msdn.microsoft.com/en-us/library/cc240613.aspx
887 * @param opt {object} type option
888 * @returns {type.Component}
889 */
890function synchronizeUpdateDataPDU(opt) {
891 var self = {
892 pad2Octets : new type.UInt16Le()
893 };
894
895 return new type.Component(self, opt);
896}
897
898/**
899 * @see http://msdn.microsoft.com/en-us/library/cc240608.aspx
900 * @param updateData {type.Component} update data (ex: bitmapUpdateDataPDU)
901 * @param opt {object} type option
902 * @returns {type.Component}
903 */
904function updateDataPDU(updateData, opt) {
905 var self = {
906 __PDUTYPE2_ : PDUType2.PDUTYPE2_UPDATE__,
907 updateType : new type.UInt16Le(function() {
908 return self.updateData.obj.__UPDATE_TYPE__;
909 }),
910 updateData : updateData || new type.Factory(function(s) {
911 var options = { readLength : new type.CallableValue(function() {
912 return opt.readLength.value - 2;
913 })};
914 switch(self.updateType.value) {
915 case UpdateType.UPDATETYPE_BITMAP:
916 self.updateData = bitmapUpdateDataPDU(null, options).read(s);
917 break;
918 case UpdateType.UPDATETYPE_SYNCHRONIZE:
919 // do nothing artefact of protocol
920 self.updateData = synchronizeUpdateDataPDU(null, options).read(s);
921 break;
922 default:
923 self.updateData = new type.BinaryString(null, options).read(s);
924 log.debug('unknown updateDataPDU ' + self.updateType.value);
925 }
926 })
927 };
928
929 return new type.Component(self, opt);
930}
931
932/**
933 * @param pduData {type.Component}
934 * @param shareId {integer}
935 * @param opt {object} type option
936 * @returns {type.Component}
937 */
938function dataPDU(pduData, shareId, opt) {
939 var self = {
940 __PDUTYPE__ : PDUType.PDUTYPE_DATAPDU,
941 shareDataHeader : shareDataHeader(new type.CallableValue(function() {
942 return new type.Component(self).size();
943 }), function() {
944 return self.pduData.obj.__PDUTYPE2__;
945 }, shareId),
946 pduData : pduData || new type.Factory(function(s) {
947
948 //compute local readLength
949 var options = { readLength : new type.CallableValue(function() {
950 return opt.readLength.value - self.shareDataHeader.size();
951 }) };
952
953 switch(self.shareDataHeader.obj.pduType2.value) {
954 case PDUType2.PDUTYPE2_SYNCHRONIZE:
955 self.pduData = synchronizeDataPDU(null, options).read(s)
956 break;
957 case PDUType2.PDUTYPE2_CONTROL:
958 self.pduData = controlDataPDU(null, options).read(s);
959 break;
960 case PDUType2.PDUTYPE2_SET_ERROR_INFO_PDU:
961 self.pduData = errorInfoDataPDU(null, options).read(s);
962 break;
963 case PDUType2.PDUTYPE2_FONTLIST:
964 self.pduData = fontListDataPDU(options).read(s);
965 break;
966 case PDUType2.PDUTYPE2_FONTMAP:
967 self.pduData = fontMapDataPDU(options).read(s);
968 break;
969 case PDUType2.PDUTYPE2_BITMAPCACHE_PERSISTENT_LIST:
970 self.pduData = persistentListPDU(null, options).read(s);
971 break;
972 case PDUType2.PDUTYPE2_INPUT:
973 self.pduData = clientInputEventPDU(null, options).read(s);
974 break;
975 case PDUType2.PDUTYPE2_SHUTDOWN_REQUEST:
976 self.pduData = shutdownRequestPDU(options).read(s);
977 break;
978 case PDUType2.PDUTYPE2_SHUTDOWN_DENIED:
979 self.pduData = shutdownDeniedPDU(options).read(s);
980 break;
981 case PDUType2.PDUTYPE2_SUPPRESS_OUTPUT:
982 self.pduData = supressOutputDataPDU(options).read(s);
983 break;
984 case PDUType2.PDUTYPE2_REFRESH_RECT:
985 self.pduData = refreshRectPDU(null, options).read(s);
986 break;
987 case PDUType2.PDUTYPE2_UPDATE:
988 self.pduData = updateDataPDU(null, options).read(s);
989 break;
990 default:
991 self.pduData = new type.BinaryString(null, options).read(s);
992 log.debug('unknown PDUType2 ' + self.shareDataHeader.obj.pduType2.value);
993 }
994 })
995 };
996
997 return new type.Component(self, opt);
998}
999
1000/**
1001 * @param userId {integer}
1002 * @param pduMessage {type.Component} pdu message
1003 * @param opt {object} type option
1004 * @returns {type.Component}
1005 */
1006function pdu(userId, pduMessage, opt) {
1007 var self = {
1008 shareControlHeader : shareControlHeader(function() {
1009 return new type.Component(self).size();
1010 }, function() {
1011 return pduMessage.obj.__PDUTYPE__;
1012 }, userId),
1013 pduMessage : pduMessage || new type.Factory(function(s) {
1014
1015 // compute local common options
1016 var options = { readLength : new type.CallableValue(function() {
1017 return self.shareControlHeader.obj.totalLength.value - self.shareControlHeader.size();
1018 }) };
1019
1020 switch(self.shareControlHeader.obj.pduType.value) {
1021 case PDUType.PDUTYPE_DEMANDACTIVEPDU:
1022 self.pduMessage = demandActivePDU(null, options).read(s);
1023 break;
1024 case PDUType.PDUTYPE_CONFIRMACTIVEPDU:
1025 self.pduMessage = confirmActivePDU(null, options).read(s);
1026 break;
1027 case PDUType.PDUTYPE_DEACTIVATEALLPDU:
1028 self.pduMessage = deactiveAllPDU(options).read(s);
1029 break;
1030 case PDUType.PDUTYPE_DATAPDU:
1031 self.pduMessage = dataPDU(null, null, options).read(s);
1032 break;
1033 default:
1034 self.pduMessage = new type.BinaryString(null, options).read(s);
1035 log.debug('unknown pdu type ' + self.shareControlHeader.obj.pduType.value);
1036 }
1037 })
1038 };
1039
1040 return new type.Component(self, opt);
1041}
1042
1043
1044const ClipPDUMsgType = {
1045 CB_MONITOR_READY: 0x0001,
1046 CB_FORMAT_LIST: 0x0002,
1047 CB_FORMAT_LIST_RESPONSE: 0x0003,
1048 CB_FORMAT_DATA_REQUEST: 0x0004,
1049 CB_FORMAT_DATA_RESPONSE: 0x0005,
1050 CB_TEMP_DIRECTORY: 0x0006,
1051 CB_CLIP_CAPS: 0x0007,
1052 CB_FILECONTENTS_REQUEST: 0x0008
1053}
1054
1055/**
1056 * @returns {type.Component}
1057 */
1058function clipPDU() {
1059 const self = {
1060 header: new type.Factory(function (s) {
1061 self.header = new type.Component({
1062 msgType: new type.UInt16Le().read(s),
1063 msgFlags: new type.UInt16Le().read(s),
1064 dataLen: new type.UInt32Le().read(s)
1065 })
1066 })
1067
1068 }
1069 return new type.Component(self);
1070}
1071
1072
1073/**
1074 * @see http://msdn.microsoft.com/en-us/library/dd306368.aspx
1075 * @param opt {object} type option
1076 * @returns {type.Component}
1077 */
1078function fastPathBitmapUpdateDataPDU(opt) {
1079 var self = {
1080 __FASTPATH_UPDATE_TYPE__ : FastPathUpdateType.FASTPATH_UPDATETYPE_BITMAP,
1081 header : new type.UInt16Le(FastPathUpdateType.FASTPATH_UPDATETYPE_BITMAP, { constant : true }),
1082 numberRectangles : new type.UInt16Le( function () {
1083 return self.rectangles.obj.length;
1084 }),
1085 rectangles : new type.Factory( function (s) {
1086 self.rectangles = new type.Component([]);
1087 for(var i = 0; i < self.numberRectangles.value; i++) {
1088 self.rectangles.obj.push(bitmapData().read(s));
1089 }
1090 })
1091 };
1092
1093 return new type.Component(self, opt);
1094}
1095
1096// This is a table of cursorid to cursor name.
1097// Created by movering the mouse over this page: https://www.w3schools.com/csSref/tryit.asp?filename=trycss_cursor
1098const cursorIdTable = {
1099 // Normal style mouse cursor
1100 903013897: 'alias',
1101 370524792: 'all-scroll',
1102 853046751: 'cell',
1103 2101250798: 'col-resize',
1104 703681364: 'copy',
1105 992638936: 'crosshair',
1106 1539083673: 'ew-resize',
1107 1919796298: 'grab',
1108 1010243511: 'grabbing',
1109 1247283057: 'help',
1110 1390892051: 'none',
1111 885751489: 'not-allowed',
1112 1732952247: 'row-resize',
1113 747144997: 'url',
1114 2018345610: 'zoom-in',
1115 347367048: 'zoom-out',
1116 1872942890: 'default',
1117 1737852989: 'text',
1118 1932827019: 'ns-resize',
1119 1884471290: 'nesw-resize',
1120 1204065391: 'nwse-resize',
1121 2030531519: 'progress',
1122 1050842114: 'pointer',
1123
1124 // Black style cursors
1125 1258195498: 'default',
1126 219484254: 'all-scroll',
1127 399295089: 'text',
1128 1912613597: 'wait',
1129 864127801: 'ew-resize',
1130 23245044: 'nesw-resize',
1131 1966995494: 'not-allowed',
1132 1873216615: 'help',
1133 255126408: 'nesw-resize',
1134 157191894: 'ns-resize',
1135 1768446509: 'pointer',
1136 1032011501: 'crosshair'
1137}
1138
1139function fastPathPointerUpdateDataPDU(opt, cursorId, cursorStr) {
1140 var self = {
1141 __FASTPATH_UPDATE_TYPE__: FastPathUpdateType.FASTPATH_UPDATETYPE_COLOR,
1142 header: new type.UInt16Le(FastPathUpdateType.FASTPATH_UPDATETYPE_COLOR, { constant: true }),
1143 cursorId: cursorId,
1144 cursorStr: cursorStr
1145 };
1146
1147 return new type.Component(self, opt);
1148}
1149
1150/**
1151 * @see http://msdn.microsoft.com/en-us/library/cc240622.aspx
1152 * @param updateData {type.Component}
1153 * @param opt {object} type option
1154 * @returns {type.Component}
1155 */
1156function fastPathUpdatePDU(updateData, opt) {
1157 var self = {
1158 updateHeader : new type.UInt8( function () {
1159 return self.updateData.obj.__FASTPATH_UPDATE_TYPE__;
1160 }),
1161 compressionFlags : new type.UInt8(null, { conditional : function () {
1162 return (self.updateHeader.value >> 4) & FastPathOutputCompression.FASTPATH_OUTPUT_COMPRESSION_USED;
1163 }}),
1164 size : new type.UInt16Le( function () {
1165 return self.updateData.size();
1166 }),
1167 updateData : updateData || new type.Factory( function (s) {
1168 var options = { readLength : new type.CallableValue( function () {
1169 return self.size.value;
1170 }) };
1171
1172 switch (self.updateHeader.value & 0xf) {
1173 case FastPathUpdateType.FASTPATH_UPDATETYPE_BITMAP: {
1174 self.updateData = fastPathBitmapUpdateDataPDU(options).read(s);
1175 break;
1176 }
1177 case FastPathUpdateType.FASTPATH_UPDATETYPE_COLOR: {
1178 var data = new type.BinaryString(null, options).read(s);
1179
1180 // Hash the data to get a cursor id.
1181 // This is a hack since the cursor bitmap is sent but we can't use that, we has hash the bitmap and use that as a hint as to what cursor we need to display
1182 const hasher = require('crypto').createHash('sha384');
1183 hasher.update(data.value);
1184 const cursorid = Math.abs(hasher.digest().readInt32BE(0));
1185 const cursorStr = cursorIdTable[cursorid];
1186 //if (cursorStr == null) { console.log('Unknown cursorId: ' + cursorid); }
1187 self.updateData = fastPathPointerUpdateDataPDU(options, cursorid, cursorStr);
1188 break;
1189 }
1190 default: {
1191 self.updateData = new type.BinaryString(null, options).read(s);
1192 log.debug('unknown fast path pdu type ' + (self.updateHeader.value & 0xf));
1193 }
1194 }
1195 })
1196 };
1197
1198 return new type.Component(self, opt);
1199}
1200
1201/**
1202 * Module exports
1203 */
1204module.exports = {
1205 PDUType : PDUType,
1206 PDUType2 : PDUType2,
1207 StreamId : StreamId,
1208 CompressionOrder : CompressionOrder,
1209 CompressionType : CompressionType,
1210 Action : Action,
1211 PersistentKeyListFlag : PersistentKeyListFlag,
1212 BitmapFlag : BitmapFlag,
1213 UpdateType : UpdateType,
1214 InputMessageType : InputMessageType,
1215 PointerFlag : PointerFlag,
1216 KeyboardFlag : KeyboardFlag,
1217 FastPathOutputCompression : FastPathOutputCompression,
1218 Display : Display,
1219 ToogleFlag : ToogleFlag,
1220 ErrorInfo : ErrorInfo,
1221 FastPathUpdateType : FastPathUpdateType,
1222 shareControlHeader : shareControlHeader,
1223 shareDataHeader : shareDataHeader,
1224 demandActivePDU : demandActivePDU,
1225 confirmActivePDU : confirmActivePDU,
1226 deactiveAllPDU : deactiveAllPDU,
1227 pdu : pdu,
1228 synchronizeDataPDU : synchronizeDataPDU,
1229 controlDataPDU : controlDataPDU,
1230 errorInfoDataPDU : errorInfoDataPDU,
1231 fontListDataPDU : fontListDataPDU,
1232 fontMapDataPDU : fontMapDataPDU,
1233 persistentListPDU : persistentListPDU,
1234 synchronizeEvent : synchronizeEvent,
1235 pointerEvent : pointerEvent,
1236 scancodeKeyEvent : scancodeKeyEvent,
1237 unicodeKeyEvent : unicodeKeyEvent,
1238 slowPathInputEvent : slowPathInputEvent,
1239 clientInputEventPDU : clientInputEventPDU,
1240 shutdownRequestPDU : shutdownRequestPDU,
1241 shutdownDeniedPDU : shutdownDeniedPDU,
1242 supressOutputDataPDU : supressOutputDataPDU,
1243 refreshRectPDU : refreshRectPDU,
1244 bitmapData : bitmapData,
1245 bitmapUpdateDataPDU : bitmapUpdateDataPDU,
1246 updateDataPDU : updateDataPDU,
1247 dataPDU : dataPDU,
1248 fastPathBitmapUpdateDataPDU : fastPathBitmapUpdateDataPDU,
1249 fastPathUpdatePDU: fastPathUpdatePDU,
1250 clipPDU: clipPDU,
1251 ClipPDUMsgType: ClipPDUMsgType
1252};