From ce02d914a3dd35501c460a1c3d3a166d3ed1a0b2 Mon Sep 17 00:00:00 2001 From: Zjmainstay Date: Tue, 3 Dec 2024 08:07:37 +0800 Subject: [PATCH 1/2] add option -b/--binary for communicate with WebSocket server by binary data --- bin/wscat | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/wscat b/bin/wscat index 729a2b3..d85f65e 100755 --- a/bin/wscat +++ b/bin/wscat @@ -138,6 +138,7 @@ program 'enable slash commands for control frames (/ping [data], /pong [data], ' + '/close [code [, reason]]) (--connect only)' ) + .option('-b, --binary', 'communicate with WebSocket server by binary data') .option('-c, --connect ', 'connect to a WebSocket server') .option( '-H, --header ', @@ -198,6 +199,7 @@ if (programOptions.listen) { wsConsole.on('line', (data) => { if (ws) { + if (programOptions.binary) data = Buffer.from(data, 'hex'); ws.send(data); wsConsole.prompt(); } @@ -231,6 +233,7 @@ if (programOptions.listen) { }); ws.on('message', (data) => { + if (programOptions.binary) data = data.toString('hex'); wsConsole.print(Console.Types.Incoming, data, Console.Colors.Blue); }); }); @@ -338,6 +341,7 @@ if (programOptions.listen) { ); } } else { + if (programOptions.binary) data = Buffer.from(data, 'hex'); ws.send(data); } wsConsole.prompt(); @@ -363,6 +367,7 @@ if (programOptions.listen) { }); ws.on('message', (data) => { + if (programOptions.binary) data = data.toString('hex'); wsConsole.print(Console.Types.Incoming, data, Console.Colors.Blue); }); From 6b4c7023769b27472acb6442f1e671d197d2d8aa Mon Sep 17 00:00:00 2001 From: Zjmainstay Date: Tue, 3 Dec 2024 08:38:32 +0800 Subject: [PATCH 2/2] add binary support for execute command --- bin/wscat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/wscat b/bin/wscat index d85f65e..d862097 100755 --- a/bin/wscat +++ b/bin/wscat @@ -285,7 +285,11 @@ if (programOptions.listen) { ws.on('open', () => { if (programOptions.execute) { - ws.send(programOptions.execute); + if (programOptions.binary) { + ws.send(Buffer.from(programOptions.execute, 'hex')); + } else { + ws.send(programOptions.execute); + } setTimeout( () => { ws.close();