chiark / gitweb /
quick-and-dirty script to reverse the output of od
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Mon, 24 Nov 2008 19:43:46 +0000 (19:43 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Mon, 24 Nov 2008 19:43:46 +0000 (19:43 +0000)
revod [new file with mode: 0755]

diff --git a/revod b/revod
new file mode 100755 (executable)
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 = $_;
+}