File: snoopyanalyse.py

package info (click to toggle)
bitpim 1.0.7%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 31,384 kB
  • sloc: python: 267,746; cpp: 2,076; perl: 600; ansic: 409; sh: 226; makefile: 152; sed: 1
file content (52 lines) | stat: -rw-r--r-- 1,344 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python

# Analyse a log file

import sys


def dolines(f):
    state=None
    last=None

    for line in f:
        if line[0]=='[':
            if state is not None:
                dumpstate(state)
                state=None
            if line.find('<<<  URB')>0:
                state={'dir': 'in', 'data': []}
                continue
            elif line.find('>>>  URB')>0:
                state={'dir': 'out', 'data': []}
                continue
            else:
                if line.find('UsbSnoop')>0:
                    continue
                print "ignoring",line
                continue
        if state is None:
            print "what is",line
            continue
        if line.find('-- ')==0:
            state['urb']=line[3:-2]
            continue
        if line.startswith('    '):
            state['data'].append(line[4:])
            continue
        if line.startswith('  '):
            eq=line.find('=')
            state[line[:eq].strip()]=line[eq+1:].strip()
            continue

def dumpstate(state):
    if state['urb']=='URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER':
        if state['dir']=='out' and state['TransferFlags'].find('DIRECTION_IN')>0:
            if state['TransferBufferLength']!='00000040':
                print state
    
        

dolines(open(sys.argv[1], "r"))