Last active
December 4, 2019 16:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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