data.js 39 KB

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