mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-27 05:33:31 +00:00
Added ability to dispatch method invocations on remote stream
This commit is contained in:
@@ -24,7 +24,10 @@ function dispatch(options)
|
||||
require('events').EventEmitter.call(ret, true).createEvent('connection');
|
||||
|
||||
ret._ipc = require('net').createServer(); ret._ipc.parent = ret;
|
||||
ret._ipc.on('close', function () { console.log('server closed'); });
|
||||
ret._ipc2 = require('net').createServer(); ret._ipc2.parent = ret;
|
||||
ret._ipc.on('close', function () { });
|
||||
ret._ipc2.on('close', function () { });
|
||||
|
||||
while (true)
|
||||
{
|
||||
ipcInteger = require('tls').generateRandomInteger('1000', '9999');
|
||||
@@ -33,6 +36,7 @@ function dispatch(options)
|
||||
try
|
||||
{
|
||||
ret._ipc.listen({ path: ret._ipcPath, writableAll: true });
|
||||
ret._ipc2.listen({ path: ret._ipcPath + 'C', writableAll: true });
|
||||
break;
|
||||
}
|
||||
catch (x)
|
||||
@@ -40,7 +44,20 @@ function dispatch(options)
|
||||
}
|
||||
}
|
||||
var str = Buffer.from("require('win-console').hide();require('win-dispatcher').connect('" + ipcInteger + "');").toString('base64');
|
||||
|
||||
ret._ipc2.once('connection', function onConnect(s)
|
||||
{
|
||||
this.parent._control = s;
|
||||
this.parent._control._parent = this;
|
||||
this.parent.invoke = function (method, args)
|
||||
{
|
||||
var d, h = Buffer.alloc(4);
|
||||
d = Buffer.from(JSON.stringify({ command: 'invoke', value: { method: method, args: args } }));
|
||||
h.writeUInt32LE(d.length + 4);
|
||||
this._control.write(h);
|
||||
this._control.write(d);
|
||||
};
|
||||
s.once('end', function () { this._parent.close(); });
|
||||
});
|
||||
ret._ipc.once('connection', function onConnect(s)
|
||||
{
|
||||
this.parent._client = s;
|
||||
@@ -96,7 +113,28 @@ function dispatch(options)
|
||||
function connect(ipc)
|
||||
{
|
||||
var ipcPath = '\\\\.\\pipe\\taskRedirection-' + ipc;
|
||||
global.ipc2Client = require('net').createConnection({ path: ipcPath + 'C' }, function ()
|
||||
{
|
||||
this.on('data', function (c)
|
||||
{
|
||||
var cLen = c.readUInt32LE(0);
|
||||
if (cLen > c.length)
|
||||
{
|
||||
this.unshift(c);
|
||||
return;
|
||||
}
|
||||
|
||||
var cmd = JSON.parse(c.slice(4, cLen).toString());
|
||||
switch (cmd.command)
|
||||
{
|
||||
case 'invoke':
|
||||
global._proxyStream[cmd.value.method].apply(global._proxyStream, cmd.value.args);
|
||||
break;
|
||||
}
|
||||
|
||||
if (cLen < c.length) { this.unshift(c.slice(cLen)); }
|
||||
});
|
||||
});
|
||||
global.ipcClient = require('net').createConnection({ path: ipcPath }, function ()
|
||||
{
|
||||
this.on('data', function (c)
|
||||
|
||||
Reference in New Issue
Block a user