#!/usr/bin/perl
#
# arbor2text.pl
#
# converts arbor text export ASCII Files to text2pcap readable input format  
#
# Version 0.4
# date 30.12.2009
# (c) by packetlevel.ch
#
######################################################################
#
# Usage:  arbor2test.pl arbor_txt.txt > arbor_hex.txt
# 
# create PCAP File with text2pcap  (included in wireshark / tshark)
#         text2pcap -l 1 -e 0x0800 arbor_hex.txt arbor.pcap
#
######################################################################
#

@packets = ();
$i = 1;

while (<>) {
        $line = $_;
	
        if ( $line =~ /^[0-9A-Fa-f]{2} / ) {
        	$hex_part = substr($line, 0, 47);
		$hex_part =~ s/\s//g;
        	$packets[$i] .= $hex_part;
		}
	else {
		$i++;
		}
	     
}

for ($i = 1; $i <= @packets; $i++) {

        if ( exists $packets[$i] ) {

                for ( $j = 0; $j < length($packets[$i]); $j += 2 ) {
                        if ( $j == 0 )  {
                                printf "# Packet \n%08X";
                        } elsif ( $j % 32 == 0 ) {
				printf "\n%08X", $j/2;
                        }
                        print " ".substr($packets[$i], $j, 2);
                }
                print "\n";
        }
}


