File: analysedir.py

package info (click to toggle)
galileo 0.5.1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 392 kB
  • ctags: 578
  • sloc: python: 3,462; xml: 23; makefile: 14
file content (45 lines) | stat: -rwxr-xr-x 999 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

import os
import re

from analysedump import readdump
from analysedump import analyse as longanalyse

TYPES = {0xF4: 'Zip', 0x26: 'One', 0x28: 'Flex'}


def analyse(filename):
    s = []
    with open(filename, 'rt') as dump:
        data, response = readdump(dump)
    s.append(TYPES[data[0]])
    s.append(str(len(data)))
    s.append(str(len(response)))
    print ' '.join(s)
    try:
        longanalyse(data)
    except:
        print filename
        raise


def main(dirname):
    for root, dirs, files in os.walk(dirname):
        for dump in sorted(files):
            if not re.match('dump-\d{10}.txt', dump):
                continue
            filename = os.path.join(root, dump)
            print dump
            analyse(filename)

if __name__ == "__main__":
    import sys
    try:
        os.path.exists(sys.argv[1])
        filename = sys.argv[1]
        print "Single file mode: ", filename
        analyse(filename) 

    except:
        main(sys.argv[1])