From 1f396e198ee04158a2a42fd8de85626d9df069f3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 16 Jul 2018 22:43:19 -0600 Subject: [PATCH] Fix escape/de-escaping for zmodem & friends --- core/archaicnet.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/archaicnet.js b/core/archaicnet.js index bc3528d6..b407c97d 100644 --- a/core/archaicnet.js +++ b/core/archaicnet.js @@ -52,9 +52,12 @@ exports.getModule = class ArchaicNETModule extends MenuModule { let pipeRestored = false; let pipedStream; const restorePipe = function() { - if(pipedStream && !pipeRestored && !clientTerminated) { - self.client.term.output.unpipe(pipedStream); - self.client.term.output.resume(); + if(!pipeRestored) { + if(pipedStream && !clientTerminated) { + self.client.term.output.unpipe(pipedStream); + self.client.term.output.resume(); + } + self.client.restoreDataHandler(); } }; @@ -82,8 +85,15 @@ exports.getModule = class ArchaicNETModule extends MenuModule { pipedStream = stream; self.client.term.output.pipe(stream); - stream.on('data', d => { - return self.client.term.rawWrite(d); + // we need to filter I/O for escape/de-escaping zmodem and the like + self.client.setTemporaryDirectDataHandler(data => { + const tmp = data.toString('binary').replace(/\xff{2}/g, '\xff'); // de-escape + stream.write(Buffer.from(tmp, 'binary')); + }); + + stream.on('data', data => { + const tmp = data.toString('binary').replace(/\xff/g, '\xff\xff'); // escape + self.client.term.rawWrite(Buffer.from(tmp, 'binary')); }); stream.on('close', () => {