From 67ae73df158509160e32015255017ca73a6d27c0 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 16 Dec 2018 00:17:26 -0800 Subject: [PATCH] MeshMessenger will now try to switch to a WebRTC data channel. --- MeshCentralServer.njsproj | 2 + agents/modules_meshcmd/promise.js | 207 ------------------------ agents/modules_meshcore/win-terminal.js | 12 +- package.json | 2 +- public/messenger.htm | 155 ++++++++++++++---- 5 files changed, 135 insertions(+), 243 deletions(-) delete mode 100644 agents/modules_meshcmd/promise.js diff --git a/MeshCentralServer.njsproj b/MeshCentralServer.njsproj index dc3e18c8..395682c9 100644 --- a/MeshCentralServer.njsproj +++ b/MeshCentralServer.njsproj @@ -31,6 +31,8 @@ + + diff --git a/agents/modules_meshcmd/promise.js b/agents/modules_meshcmd/promise.js deleted file mode 100644 index 227b23ac..00000000 --- a/agents/modules_meshcmd/promise.js +++ /dev/null @@ -1,207 +0,0 @@ -/* -Copyright 2018 Intel Corporation - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -var refTable = {}; - -function event_switcher_helper(desired_callee, target) -{ - this._ObjectID = 'event_switcher'; - this.func = function func() - { - var args = []; - for(var i in arguments) - { - args.push(arguments[i]); - } - return (func.target.apply(func.desired, args)); - }; - this.func.desired = desired_callee; - this.func.target = target; - this.func.self = this; -} -function event_switcher(desired_callee, target) -{ - return (new event_switcher_helper(desired_callee, target)); -} - -function Promise(promiseFunc) -{ - this._ObjectID = 'promise'; - this.promise = this; - this._internal = { _ObjectID: 'promise.internal', promise: this, func: promiseFunc, completed: false, errors: false, completedArgs: [] }; - require('events').EventEmitter.call(this._internal); - this._internal.on('_eventHook', function (eventName, eventCallback) - { - //console.log('hook', eventName, 'errors/' + this.errors + ' completed/' + this.completed); - var r = null; - - if (eventName == 'resolved' && !this.errors && this.completed) - { - r = eventCallback.apply(this, this.completedArgs); - if(r!=null) - { - this.emit_returnValue('resolved', r); - } - } - if (eventName == 'rejected' && this.errors && this.completed) - { - eventCallback.apply(this, this.completedArgs); - } - if (eventName == 'settled' && this.completed) - { - eventCallback.apply(this, []); - } - }); - this._internal.resolver = function _resolver() - { - _resolver._self.errors = false; - _resolver._self.completed = true; - _resolver._self.completedArgs = []; - var args = ['resolved']; - if (this.emit_returnValue && this.emit_returnValue('resolved') != null) - { - _resolver._self.completedArgs.push(this.emit_returnValue('resolved')); - args.push(this.emit_returnValue('resolved')); - } - else - { - for (var a in arguments) - { - _resolver._self.completedArgs.push(arguments[a]); - args.push(arguments[a]); - } - } - _resolver._self.emit.apply(_resolver._self, args); - _resolver._self.emit('settled'); - }; - this._internal.rejector = function _rejector() - { - _rejector._self.errors = true; - _rejector._self.completed = true; - _rejector._self.completedArgs = []; - var args = ['rejected']; - for (var a in arguments) - { - _rejector._self.completedArgs.push(arguments[a]); - args.push(arguments[a]); - } - - _rejector._self.emit.apply(_rejector._self, args); - _rejector._self.emit('settled'); - }; - this.catch = function(func) - { - this._internal.once('rejected', event_switcher(this, func).func); - } - this.finally = function (func) - { - this._internal.once('settled', event_switcher(this, func).func); - }; - this.then = function (resolved, rejected) - { - if (resolved) { this._internal.once('resolved', event_switcher(this, resolved).func); } - if (rejected) { this._internal.once('rejected', event_switcher(this, rejected).func); } - - var retVal = new Promise(function (r, j) { }); - this._internal.once('resolved', retVal._internal.resolver); - this._internal.once('rejected', retVal._internal.rejector); - retVal.parentPromise = this; - return (retVal); - }; - - this._internal.resolver._self = this._internal; - this._internal.rejector._self = this._internal;; - - try - { - promiseFunc.call(this, this._internal.resolver, this._internal.rejector); - } - catch(e) - { - this._internal.errors = true; - this._internal.completed = true; - this._internal.completedArgs = [e]; - this._internal.emit('rejected', e); - this._internal.emit('settled'); - } - - if(!this._internal.completed) - { - // Save reference of this object - refTable[this._internal._hashCode()] = this._internal; - this._internal.once('settled', function () { refTable[this._hashCode()] = null; }); - } -} - -Promise.resolve = function resolve() -{ - var retVal = new Promise(function (r, j) { }); - var args = []; - for (var i in arguments) - { - args.push(arguments[i]); - } - retVal._internal.resolver.apply(retVal._internal, args); - return (retVal); -}; -Promise.reject = function reject() { - var retVal = new Promise(function (r, j) { }); - var args = []; - for (var i in arguments) { - args.push(arguments[i]); - } - retVal._internal.rejector.apply(retVal._internal, args); - return (retVal); -}; -Promise.all = function all(promiseList) -{ - var ret = new Promise(function (res, rej) - { - this.__rejector = rej; - this.__resolver = res; - this.__promiseList = promiseList; - this.__done = false; - this.__count = 0; - }); - - for (var i in promiseList) - { - promiseList[i].then(function () - { - // Success - if(++ret.__count == ret.__promiseList.length) - { - ret.__done = true; - ret.__resolver(ret.__promiseList); - } - }, function (arg) - { - // Failure - if(!ret.__done) - { - ret.__done = true; - ret.__rejector(arg); - } - }); - } - if (promiseList.length == 0) - { - ret.__resolver(promiseList); - } - return (ret); -}; - -module.exports = Promise; \ No newline at end of file diff --git a/agents/modules_meshcore/win-terminal.js b/agents/modules_meshcore/win-terminal.js index 541c6954..64319702 100644 --- a/agents/modules_meshcore/win-terminal.js +++ b/agents/modules_meshcore/win-terminal.js @@ -249,7 +249,7 @@ function windows_terminal() { break; case EVENT_CONSOLE_UPDATE_SIMPLE: //console.log('UPDATE SIMPLE: [X: ' + LOWORD(idObject.Val) + ' Y: ' + HIWORD(idObject.Val) + ' Char: ' + LOWORD(idChild.Val) + ' Attr: ' + HIWORD(idChild.Val) + ']'); - var simplebuffer = { data: [Buffer.alloc(1, LOWORD(idChild.Val))], attributes: [HIWORD(idChild.Val)], width: 1, height: 1, x: LOWORD(idObject.Val) + 1, y: HIWORD(idObject.Val) }; + var simplebuffer = { data: [ Buffer.alloc(1, LOWORD(idChild.Val)) ], attributes: [ HIWORD(idChild.Val) ], width: 1, height: 1, x: LOWORD(idObject.Val), y: HIWORD(idObject.Val) }; this.terminal._SendDataBuffer(simplebuffer); break; case EVENT_CONSOLE_UPDATE_SCROLL: @@ -330,8 +330,8 @@ function windows_terminal() { } this._WriteCharacter = function (key, bControlKey) { var rec = GM.CreateVariable(20); - rec.Deref(0, 2).toBuffer().writeUInt16LE(KEY_EVENT); // rec.EventType - rec.Deref(4, 4).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.bKeyDown + rec.Deref(0, 2).toBuffer().writeUInt16LE(KEY_EVENT); // rec.EventType + rec.Deref(4, 4).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.bKeyDown rec.Deref(16, 4).toBuffer().writeUInt32LE(bControlKey); // rec.Event.KeyEvent.dwControlKeyState rec.Deref(14, 1).toBuffer()[0] = key; // rec.Event.KeyEvent.uChar.AsciiChar rec.Deref(8, 2).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.wRepeatCount @@ -345,9 +345,8 @@ function windows_terminal() { return (this._kernel32.WriteConsoleInputA(this._stdinput, rec, 1, dwWritten).Val != 0); } + // Get the current visible screen buffer this._GetScreenBuffer = function (sx, sy, ex, ey) { - // get the current visible screen buffer - var info = GM.CreateVariable(22); if (this._kernel32.GetConsoleScreenBufferInfo(this._stdoutput, info).Val == 0) { throw ('Error getting screen buffer info'); } @@ -366,7 +365,6 @@ function windows_terminal() { this._scrx = this._scry = 0; } - var nBuffer = GM.CreateVariable((ex - sx + 1) * (ey - sy + 1) * 4); var size = GM.CreateVariable(4); size.Deref(0, 2).toBuffer().writeUInt16LE(ex - sx + 1, 0); @@ -418,7 +416,7 @@ function windows_terminal() { //line = data.data.slice(data.width * dy, (data.width * dy) + data.width); //attr = data.attributes.slice(data.width * dy, (data.width * dy) + data.width); - this._stream.push(TranslateLine(data.x, data.y + dy + 1, line, attr)); + this._stream.push(TranslateLine(data.x + 1, data.y + dy + 1, line, attr)); } } diff --git a/package.json b/package.json index 125ebc3a..88b86ad3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.2.4-p", + "version": "0.2.4-q", "keywords": [ "Remote Management", "Intel AMT", diff --git a/public/messenger.htm b/public/messenger.htm index 3ed66a14..4a39e3f0 100644 --- a/public/messenger.htm +++ b/public/messenger.htm @@ -16,14 +16,18 @@
- +