From 3c9e80b083820b16986287ffed964c01bfd91647 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 18 Jun 2020 12:47:34 -0700 Subject: [PATCH] Fixed remote desktop recording feature. --- public/scripts/agent-desktop-0.0.2.js | 11 ++++++++++- views/player.handlebars | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/public/scripts/agent-desktop-0.0.2.js b/public/scripts/agent-desktop-0.0.2.js index fbfb49b0..18990ca2 100644 --- a/public/scripts/agent-desktop-0.0.2.js +++ b/public/scripts/agent-desktop-0.0.2.js @@ -198,6 +198,15 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { if ((cmd == 3) || (cmd == 4) || (cmd == 7)) { X = (view[4] << 8) + view[5]; Y = (view[6] << 8) + view[7]; } //console.log('CMD', cmd, cmdsize, X, Y); + // Record the command if needed + if (obj.recordedData != null) { + if (cmdsize > 65000) { + obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdsize) + obj.shortToStr(cmd) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + String.fromCharCode.apply(null, view))); + } else { + obj.recordedData.push(recordingEntry(2, 1, String.fromCharCode.apply(null, view))); + } + } + switch (cmd) { case 3: // Tile if (obj.FirstDraw) obj.onResize(); @@ -756,7 +765,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { obj.recordedData.push(recordingEntry(1, 0, JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, time: new Date().toLocaleString(), protocol: 2 }))); // Metadata (nodeid: obj.nodeid) obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(7) + obj.shortToStr(8) + obj.shortToStr(obj.ScreenWidth) + obj.shortToStr(obj.ScreenHeight))); // Screen width and height // Save a screenshot - var cmdlen = (4 + binary.length); + var cmdlen = (8 + binary.length); if (cmdlen > 65000) { // Jumbo Packet obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdlen) + obj.shortToStr(3) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + binary)); diff --git a/views/player.handlebars b/views/player.handlebars index aa4ceb21..8df587e6 100644 --- a/views/player.handlebars +++ b/views/player.handlebars @@ -310,7 +310,17 @@ agentTerminal.ProcessData(data); } else if (recFileProtocol == 2) { // MeshCentral Remote Desktop - agentDesktop.ProcessData(data); + var view = new Uint8Array(data.length); + for (var i = 0; i < data.length; i++) { view[i] = data.charCodeAt(i); } + + // Accumulator is not active + var cmd = (view[0] << 8) + view[1], cmdsize = (view[2] << 8) + view[3]; + if ((cmd == 27) && (cmdsize == 8)) { cmd = (view[8] << 8) + view[9]; cmdsize = (view[5] << 16) + (view[6] << 8) + view[7]; view = view.slice(8); } + if (cmdsize != view.byteLength) { + console.log('Bad command size', cmd, cmdsize, view.byteLength); + } else { + agentDesktop.ProcessBinaryCommand(cmd, cmdsize, view.slice(0, cmdsize)); + } } else if (recFileProtocol == 101) { // Intel AMT KVM if ((readState == 0) && (rstr2hex(data) == '4100000000000000')) {