aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/parsers/usbmon2usbsnoop.pl
blob: c65668731340dca5100a9023d3126c62cb85788f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
#
# This perl script converts output from usbmon to a format (usbsnoop's log format) that is compatible with usbreplay.
# Taken from http://www.linuxtv.org/wiki/index.php/Usbmon2usbsnoop

sub print_bytes{
	my($str) = @_;

	@str_1 = split(/ /, $str);

	foreach(@str_1){
		if (length($_) == 8) {
			print substr($_, 0, 2) . " " . substr($_, 2, 2) . " " . substr($_, 4, 2) . " " . substr($_, 6, 2);
		}elsif(length($_) == 4) {
			print substr($_, 2, 2) . " " . substr($_, 0, 2);
		}elsif(length($_) == 2) {
			print $_;
		}elsif(length($_) == 1) {
			next;
		}
		print " ";
	}
}


$i = 0;
while($line = <STDIN>) {
	$i++;

	if($line =~ m/\S+ \S+ \S+ \S+ \S+ (.+) \S+ </) {
		printf "%06d:  OUT: %06d ms %06d ms ", $i, 1, $i;
		print_bytes($1);
		print "<<< ";
		$line = <STDIN>;
		$i++;
		if($line =~ m/\S+ \S+ \S+ \S+ [a-fA-F0-9 ]+ = ([a-fA-F0-9 ]+)/) {
			print_bytes($1);
			#print "\n";
			#print " $1\n";
		}
		print "\n";
	}elsif($line =~ m/\S+ \S+ \S+ \S+ ([a-fA-F0-9 ]+) [a-fA-F0-9]+ = ([a-fA-F0-9 ]+)/) {
		printf "%06d:  OUT: %06d ms %06d ms ", $i, 1, $i;
		print_bytes($1);
		print ">>> ";
		print_bytes($2);
		print "\n";
	}elsif($line =~ m/\S+ \S+ \S+ \S+ s (.+)/) {
		printf "%06d:  OUT: %06d ms %06d ms ", $i, 1, $i;
		print_bytes($1);
		print ">>>\n";
	}
}

Privacy Policy