From: Colin Watson Date: Mon, 24 Nov 2008 19:43:46 +0000 (+0000) Subject: quick-and-dirty script to reverse the output of od X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=commitdiff_plain;h=95155316462b45d7ee3baa64f28abe7b6d1be024;hp=daa61cc1db4ce5df90a0cfc18d22005d02d9f8c8 quick-and-dirty script to reverse the output of od --- diff --git a/revod b/revod new file mode 100755 index 0000000..bca78c7 --- /dev/null +++ b/revod @@ -0,0 +1,33 @@ +#! /usr/bin/perl -w +use strict; + +# Convert the output of 'od -tx1 -Ax' back to binary. The input is expected +# to look like this: +# +# 000000 eb 58 90 4d 41 4b 45 42 4f 4f 54 00 02 08 40 00 +# 000010 01 00 00 00 00 f8 00 00 20 00 40 00 00 00 00 00 +# [...] + +binmode STDOUT; + +my $index = 0; +my $prevblock; +while (<>) { + chomp; + next if $_ eq '*'; + if (s/^([a-z0-9]+)(?:\s+|$)//) { + my $lineindex = hex($1); + while ($lineindex > $index) { + die "no previous block!" unless defined $prevblock; + for my $hex (split ' ', $prevblock) { + print chr(hex($hex)); + ++$index; + } + } + } + for my $hex (split) { + print chr(hex($hex)); + ++$index; + } + $prevblock = $_; +}