Skip to content

Instantly share code, notes, and snippets.

@lapo-luchini
Last active December 4, 2019 16:55
Show Gist options
  • Save lapo-luchini/7c7e6974021d36a44043 to your computer and use it in GitHub Desktop.
Save lapo-luchini/7c7e6974021d36a44043 to your computer and use it in GitHub Desktop.
Decode output from a variety of hex dumps, such as BSD hexdump and Java javax.net.debug=all.
#! /usr/bin/env node
// decode output from a variety of hex dumps, such as
// - BSD hexdump / hd
// 00000000 50 4f 53 54 50 4f 53 54 50 4f 53 54 50 4f 53 54 |POSTPOSTPOSTPOST|
// - od -t x1
// 0000000 50 4f 53 54 50 4f 53 54 50 4f 53 54 50 4f 53 54
// - Java javax.net.debug=all
// 0000: 50 4F 53 54 50 4F 53 54 50 4F 53 54 50 4F 53 54 POSTPOSTPOSTPOST
var readline = require('readline'),
rl = readline.createInterface({
input: process.stdin,
output: null
}),
re = /^[0-9A-F]{4,}:?((?: +[0-9A-F]{2}){1,16})( |$)/i,
spaces = / +/g;
rl.on('line', function (s) {
var m = re.exec(s);
if (m === null)
return;
process.stdout.write(Buffer.from(m[1].replace(spaces, ''), 'hex'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment