#!/usr/bin/perl -w # Author: Daniel Kahn Gillmor # this script is intended to parse the output of one side of a socat # dump, when generated with socat -x, filtered through djb's multilog. # a typical expected chunk of input looks like this (minus the # leading perl comment characters, of course): # @40000000448e0fe6280bde84 > 44 65 62 69 61 6e 20 47 # @40000000448e0fe6281bcca4 > 4e 55 2f 4c 69 6e 75 78 20 33 2e 31 20 63 72 75 # @40000000448e0fe628291314 > 73 74 79 20 74 74 79 53 # @40000000448e0fe62838a374 > 30 0d 0a 0d 0a # @40000000448e0fe6286679d4 > 63 72 75 73 74 79 20 6c 6f 67 69 6e 3a 20 # which should correspond to the following data having appeared on the # console: # Debian GNU/Linux 3.1 crusty ttyS0 # # crusty login: # readttylog is intended to be used to log data coming through a # serial line, hopefully, as part of the ttylog project. # a typical invocation with ttylog would look like: # readttylog --with-timestamps < /etc/ttylogs/crusty/log/main/current | tai64nlocal # About this implementation: don't hurt me! i don't really know perl, # and i just put this together from what i read on the 'net (and from # Joey Hess' ts util). Please send me any suggestions for # improvement. # License: GPLv2 or later use warnings; use strict; # FIXME: make the below a command-line argument --flush-immediately ## immediate flushing: this is not appropriate for this script, i ## think, because it is run after-the-fact (usually), rather than ## interactively. If you run it interactively, you might want to ## uncomment the following line: # $|=1; my $linestart = 1; my $printts = 0; if (defined($ARGV[0]) && $ARGV[0] eq '--with-timestamps' ) { shift; $printts = 1; } while (<>) { # gets rid of any trailing newlines: chomp; # breaks out the expected timestamp and leading caret: my ($ts, $caret, @hexs) = split(/ /); my $char; # FIXME: we should test the $ts and $caret to make sure they # are legitimate before processing this line. # alternately, we could decide which lines to print based on the # directionality of the caret, if we were to let multilog record # the entire transaction. # currently, we're configuring multilog to cover only one # direction of the interaction. foreach $char (@hexs) { if ($char =~ m/^[a-f0-9]{2}$/ ) { # only print isolated hex chars: if ($linestart) { if ($printts) { print($ts." "); } $linestart = 0; } print(chr(hex($char))); if ("\n" eq chr(hex($char))) { $linestart = 1; } } } } # add a trailing newline for cleanliness. print("\n");