Skip to content

Commit bcadb62

Browse files
committed
process update events
1 parent 0d62ed6 commit bcadb62

File tree

9 files changed

+124
-17
lines changed

9 files changed

+124
-17
lines changed

lib/core/layer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ var tls = require('tls');
2525
var crypto = require('crypto');
2626
var events = require('events');
2727

28-
var hexy = require('hexy');
29-
30-
3128
/**
3229
* Buffer data from socket to present
3330
* well formed packets
@@ -95,7 +92,6 @@ BufferLayer.prototype.recv = function(data) {
9592
BufferLayer.prototype.send = function(data) {
9693
var s = new type.Stream(data.size());
9794
data.write(s);
98-
console.log('\n' + hexy.hexy(s.buffer) + '\n');
9995
if(this.cleartext) {
10096
this.cleartext.write(s.buffer);
10197
}
@@ -134,6 +130,13 @@ BufferLayer.prototype.startTLS = function(isServer, callback) {
134130
});
135131
};
136132

133+
/**
134+
* close stack
135+
*/
136+
BufferLayer.prototype.close = function() {
137+
this.socket.close();
138+
};
139+
137140
/**
138141
* Module exports
139142
*/

lib/protocol/pdu/data.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,12 @@ function refreshRectPDU(rectangles, opt) {
803803
*/
804804
function bitmapCompressedDataHeader(opt) {
805805
var self = {
806-
cbCompFirstRowSize : UInt16Le(0x0000, { constant : true }),
806+
cbCompFirstRowSize : new type.UInt16Le(0x0000, { constant : true }),
807807
// compressed data size
808-
cbCompMainBodySize : UInt16Le(),
809-
cbScanWidth : UInt16Le(),
808+
cbCompMainBodySize : new type.UInt16Le(),
809+
cbScanWidth : new type.UInt16Le(),
810810
// uncompressed data size
811-
cbUncompressedSize : UInt16Le()
811+
cbUncompressedSize : new type.UInt16Le()
812812
};
813813

814814
return new type.Component(self, opt);
@@ -860,17 +860,17 @@ function bitmapData(coord, opt) {
860860

861861
/**
862862
* @see http://msdn.microsoft.com/en-us/library/dd306368.aspx
863-
* @param bitmapData {type.Component} list of bitmap data type
863+
* @param data {type.Component} list of bitmap data type
864864
* @param opt {object} type option
865865
* @returns {type.Component}
866866
*/
867-
function bitmapUpdateDataPDU(bitmapData, opt) {
867+
function bitmapUpdateDataPDU(data, opt) {
868868
var self = {
869869
__UPDATE_TYPE__ : UpdateType.UPDATETYPE_BITMAP,
870-
numberRectangles : UInt16Le(function() {
870+
numberRectangles : new type.UInt16Le(function() {
871871
return self.rectangles.obj.length;
872872
}),
873-
rectangles : bitmapData || new type.Factory(function(s) {
873+
rectangles : data || new type.Factory(function(s) {
874874
self.rectangles = new type.Component([]);
875875
for(var i = 0; i < self.numberRectangles.value; i++) {
876876
self.rectangles.obj.push(bitmapData().read(s));
@@ -900,6 +900,9 @@ function updateDataPDU(updateData, opt) {
900900
return opt.readLength.value - 2;
901901
}) }).read(s);
902902
break;
903+
case UpdateType.UPDATETYPE_SYNCHRONIZE:
904+
// do nothing artefact of protocol
905+
break;
903906
default:
904907
log.error('unknown updateDataPDU ' + self.updateType.value);
905908
throw new Error('NODE_RDP_PROTOCOL_PDU_DATA_UNKNOWN_UPDATE_DATA_PDU');
@@ -969,8 +972,7 @@ function dataPDU(pduData, shareId, opt) {
969972
self.pduData = updateDataPDU(null, options).read(s);
970973
break;
971974
default:
972-
log.error('unknown PDUType2 ' + self.shareDataHeader.obj.pduType2.value);
973-
throw new Error('NODE_RDP_PROTOCOL_PDU_DATA_UNKNOWN_PDUTYPE2');
975+
log.debug('unknown PDUType2 ' + self.shareDataHeader.obj.pduType2.value);
974976
}
975977
})
976978
};

lib/protocol/pdu/global.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ Client.prototype.connect = function(gccCore, userId, channelId) {
107107
});
108108
};
109109

110+
/**
111+
* close stack
112+
*/
113+
Client.prototype.close = function() {
114+
this.transport.close();
115+
};
116+
110117
/**
111118
* Receive capabilities from server
112119
* @param s {type.Stream}
@@ -249,14 +256,55 @@ Client.prototype.recvServerFontMapPDU = function(s) {
249256
Client.prototype.recvPDU = function(s) {
250257
while (s.availableLength() > 0) {
251258
var pdu = data.pdu().read(s);
252-
259+
switch(pdu.obj.shareControlHeader.obj.pduType.value) {
260+
case data.PDUType.PDUTYPE_DEACTIVATEALLPDU:
261+
var self = this;
262+
this.transport.removeAllListener('data');
263+
this.transport.once('data', function(s) {
264+
self.recvDemandActivePDU(s);
265+
});
266+
break;
267+
case data.PDUType.PDUTYPE_DATAPDU:
268+
this.readDataPDU(pdu.obj.pduMessage)
269+
break;
270+
default:
271+
log.debug('ignore pdu type ' + pdu.obj.shareControlHeader.obj.pduType.value);
272+
}
273+
}
274+
};
275+
276+
/**
277+
* main receive for data PDU packet
278+
* @param dataPDU {data.dataPDU}
279+
*/
280+
Client.prototype.readDataPDU = function (dataPDU) {
281+
switch(dataPDU.obj.shareDataHeader.obj.pduType2.value) {
282+
case data.PDUType2.PDUTYPE2_SET_ERROR_INFO_PDU:
283+
break;
284+
case data.PDUType2.PDUTYPE2_SHUTDOWN_DENIED:
285+
this.transport.close();
286+
break;
287+
case data.PDUType2.PDUTYPE2_SAVE_SESSION_INFO:
288+
this.emit('session');
289+
break;
290+
case data.PDUType2.PDUTYPE2_UPDATE:
291+
this.readUpdateDataPDU(dataPDU.obj.pduData)
292+
break;
293+
}
294+
};
295+
296+
Client.prototype.readUpdateDataPDU = function (updateDataPDU) {
297+
switch(updateDataPDU.obj.updateType.value) {
298+
case data.UpdateType.UPDATETYPE_BITMAP:
299+
this.emit('bitmap', updateDataPDU.obj.updateData.obj.rectangles.obj)
300+
break;
253301
}
254302
};
255303

256304
/**
257305
* send all client capabilities
258306
*/
259-
Client.prototype.sendConfirmActivePDU = function() {
307+
Client.prototype.sendConfirmActivePDU = function () {
260308
var generalCapability = this.clientCapabilities[caps.CapsType.CAPSTYPE_GENERAL].obj;
261309
generalCapability.osMajorType.value = caps.MajorType.OSMAJORTYPE_WINDOWS;
262310
generalCapability.osMinorType.value = caps.MinorType.OSMINORTYPE_WINDOWS_NT;

lib/protocol/pdu/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
var lic = require('./lic');
2121
var sec = require('./sec');
2222
var global = require('./global');
23+
var data = require('./data');
2324

2425
module.exports = {
2526
lic : lic,
2627
sec : sec,
27-
global : global
28+
global : global,
29+
data : data
2830
};

lib/protocol/pdu/sec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ Client.prototype.connect = function(gccClient, gccServer, userId, channels) {
357357
this.sendInfoPkt();
358358
};
359359

360+
/**
361+
* close stack
362+
*/
363+
Client.prototype.close = function() {
364+
this.transport.close();
365+
};
366+
360367
/**
361368
* Send main information packet
362369
* VIP (very important packet) because contain credentials

lib/protocol/rdp.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ function RdpClient(config) {
4949
if(config.password) {
5050
this.sec.infos.obj.password.value = new Buffer(config.password + '\x00', 'ucs2');
5151
}
52+
53+
//bind all events
54+
var self = this;
55+
this.global.on('connect', function() {
56+
self.emit('connect');
57+
});
58+
this.global.on('session', function() {
59+
self.emit('session');
60+
});
61+
this.global.on('bitmap', function(bitmaps) {
62+
for(var bitmap in bitmaps) {
63+
self.emit('bitmap', {
64+
destTop : bitmaps[bitmap].obj.destTop.value,
65+
destLeft : bitmaps[bitmap].obj.destLeft.value,
66+
destBottom : bitmaps[bitmap].obj.destBottom.value,
67+
destRight : bitmaps[bitmap].obj.destRight.value,
68+
width : bitmaps[bitmap].obj.width.value,
69+
height : bitmaps[bitmap].obj.height.value,
70+
bitsPerPixel : bitmaps[bitmap].obj.bitsPerPixel.value,
71+
isCompress : bitmaps[bitmap].obj.flags.value & pdu.data.BitmapFlag.BITMAP_COMPRESSION,
72+
data : bitmaps[bitmap].obj.bitmapDataStream.value
73+
});
74+
}
75+
});
5276
}
5377

5478
//inherit from Layer

lib/protocol/t125/mcs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ Client.prototype.connect = function(selectedProtocol) {
220220
this.sendConnectInitial();
221221
};
222222

223+
/**
224+
* close stack
225+
*/
226+
Client.prototype.close = function() {
227+
this.transport.close();
228+
};
229+
223230
/**
224231
* MCS connect response (server->client)
225232
* @param s {type.Stream}

lib/protocol/tpkt.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ TPKT.prototype.send = function(message) {
111111
]));
112112
};
113113

114+
/**
115+
* close stack
116+
*/
117+
TPKT.prototype.close = function() {
118+
this.transport.close();
119+
};
120+
114121
/**
115122
* Module exports
116123
*/

lib/protocol/x224.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ Client.prototype.connect = function() {
179179
});
180180
};
181181

182+
/**
183+
* close stack
184+
*/
185+
Client.prototype.close = function() {
186+
this.transport.close();
187+
};
188+
182189
/**
183190
* Receive connection from server
184191
* @param s {Stream}

0 commit comments

Comments
 (0)