Fix escape/de-escaping for zmodem & friends

This commit is contained in:
Bryan Ashby 2018-07-16 22:43:19 -06:00
parent e3c197c3e1
commit 1f396e198e
1 changed files with 15 additions and 5 deletions

View File

@ -52,10 +52,13 @@ exports.getModule = class ArchaicNETModule extends MenuModule {
let pipeRestored = false; let pipeRestored = false;
let pipedStream; let pipedStream;
const restorePipe = function() { const restorePipe = function() {
if(pipedStream && !pipeRestored && !clientTerminated) { if(!pipeRestored) {
if(pipedStream && !clientTerminated) {
self.client.term.output.unpipe(pipedStream); self.client.term.output.unpipe(pipedStream);
self.client.term.output.resume(); self.client.term.output.resume();
} }
self.client.restoreDataHandler();
}
}; };
sshClient.on('ready', () => { sshClient.on('ready', () => {
@ -82,8 +85,15 @@ exports.getModule = class ArchaicNETModule extends MenuModule {
pipedStream = stream; pipedStream = stream;
self.client.term.output.pipe(stream); self.client.term.output.pipe(stream);
stream.on('data', d => { // we need to filter I/O for escape/de-escaping zmodem and the like
return self.client.term.rawWrite(d); 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', () => { stream.on('close', () => {