summaryrefslogtreecommitdiff
path: root/v4l2-apps/util/parse-sniffusb2.pl
blob: 34406b0ea0f77b40416db43d68c9cddc5b61dcf6 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl
#
# Author: Franklin Meng <fmeng2002@yahoo.com>
# Parser for USB snoops captured from SniffUSB 2.0.
#

use strict;
use warnings;
use Data::Dumper;

foreach my $curfile (@ARGV) {
	parsefile($curfile);
	#we can only process 1 file
	exit;
}

sub parsefile {
	my $curfile = shift;
	my $SetupPacket ='';
	my $preS = '';
	my $TransferBuffer ='';
	my $preT = '';
	my $Direction ='';
	my $preD = '';
	my @tmpsplit;
	my $t=0;
	my $s=0;

	open(FD, $curfile) || die("Error: $!\n");

	while(<FD>) {
		chomp;
		if($t==1 && /^\s+\d{8}/) {
#			print $_ . "\n";
			@tmpsplit = split(/\:\s/,$_);
			$TransferBuffer = $TransferBuffer . $tmpsplit[1] . " ";
		} elsif($s==1 && /^\s+\d{8}/) {
#			print $_ . "\n";
			@tmpsplit = split(/\:\s/,$_);
			$SetupPacket = $SetupPacket . $tmpsplit[1] ;
		} else {
			$t=0;
			$s=0;
		}
		if(/[<>]{3}/){
			#print out last packet if valid
			if($SetupPacket) {
				if($preT) {
					print "$SetupPacket $preD $preT\n";

				} else {
					print "$SetupPacket $Direction $TransferBuffer\n";
				}
			}
#			print "$SetupPacket $Direction $TransferBuffer\n";
			#clear variables
			$preT = $TransferBuffer;
			$TransferBuffer = '';
			$preS = $SetupPacket;
			$SetupPacket = '';
			$preD = $Direction;
			$t = 0;
			$s = 0;
			# get direction
			@tmpsplit = split(/\s+/, $_);
			$Direction = $tmpsplit[2];
#			print $_ . "\n";
		} elsif(/TransferBufferMDL/) {
			$t = 1
		} elsif(/SetupPacket/) {
			$s = 1;
		}
	}
	#print last packet
#	print "$SetupPacket $Direction $TransferBuffer\n";
	if($SetupPacket) {
		if($preT) {
			print "$SetupPacket $preD $preT\n";
		} else {
			print "$SetupPacket $Direction $TransferBuffer\n";
		}
	}
}