Author: fw Date: 2008-12-05 19:10:23 +0000 (Fri, 05 Dec 2008) New Revision: 10628 Added: bin/show-debsecan Log: bin/show-debsecan: new script to debug debsecan data Added: bin/show-debsecan ==================================================================--- bin/show-debsecan (rev 0) +++ bin/show-debsecan 2008-12-05 19:10:23 UTC (rev 10628) @@ -0,0 +1,55 @@ +#!/usr/bin/python + +import sys +import apsw +import base64 +import zlib +from cStringIO import StringIO + +if len(sys.argv) not in (2, 3): + print "usage: show-debsecan DATABASE-PATH [BLOB-NAME]" + sys.exit(1) + +db = apsw.Connection(sys.argv[1]) +c = db.cursor() + +if len(sys.argv) == 2: + for (name,) in c.execute("SELECT name FROM debsecan_data ORDER BY name"): + print name +else: # len(sys.argv) == 3 + name = sys.argv[2] + for (data,) in c.execute("SELECT data FROM debsecan_data WHERE name = ?", + (name,)): + pass + data = base64.b64decode(data) + data = zlib.decompress(data) + + # The following has been taken from a debsecan test case. + data = StringIO(data) + + if data.readline() <> "VERSION 1\n": + sys.stderr.write("error: server sends data in unknown format\n") + sys.exit(1) + + vuln_names = [] + for line in data: + if line[-1:] == ''\n'': + line = line[:-1] + if line == '''': + break + (name, flags, desc) = line.split('','', 2) + vuln_names.append(name) + + for line in data: + if line[-1:] == ''\n'': + line = line[:-1] + if line == '''': + break + (package, vuln, rest) = line.split('','', 2) + vuln = vuln_names[int(vuln)] + print "%s,%s,%s" % (package, vuln, rest) + + for line in data: + print line, + +db.close()