- Refactoring stuff into a package.

This commit is contained in:
ccremers 2006-08-08 15:54:00 +00:00
parent 0b21755928
commit 166f618cb9
17 changed files with 81 additions and 63 deletions

View File

@ -1,41 +0,0 @@
#!/usr/bin/python
#---------------------------------------------------------------------------
""" Import externals """
import os
#---------------------------------------------------------------------------
""" Import scyther-gui components """
import Tempfile
#---------------------------------------------------------------------------
class AttackImage:
def __init__(self,dotdata):
self.dotdata = dotdata
self.png = ""
self.MakeImage()
def MakeImage(self):
""" Sets png """
(fd,fpname) = Tempfile.tempcleaned(".dot")
fp = os.fdopen(fd, "w")
fp.write(self.dotdata)
fp.close()
(fd2,fpname2) = Tempfile.tempcleaned(".png")
os.system("dot %s -Tpng >%s" % (fpname, fpname2))
self.png = fpname2
Tempfile.tempcleanearly((fd,fpname))
def GetImage(self):
return self.png
#---------------------------------------------------------------------------

View File

@ -20,13 +20,13 @@ except ImportError:
#---------------------------------------------------------------------------
""" Import scyther components """
import XMLReader
import Scyther.XMLReader as XMLReader
import Scyther.Claim as Claim
import Scyther.Scyther as Scyther
""" Import scyther-gui components """
import Tempfile
import Claim
import Preference
import Scyther
import Attackwindow
import Icon

45
gui/Scyther/Misc.py Normal file
View File

@ -0,0 +1,45 @@
#
# Misc.py
# Various helper functions
#---------------------------------------------------------------------------
""" Import externals """
import os.path
#---------------------------------------------------------------------------
def confirm(question):
answer = ''
while answer not in ('y','n'):
print question,
answer = raw_input().lower()
return answer == 'y'
def exists(func,list):
return len(filter(func,list)) > 0
def forall(func,list):
return len(filter(func,list)) == len(list)
def uniq(li):
result = []
for elem in li:
if (not elem in result):
result.append(elem)
return result
# Return a sorted copy of a list
def sorted(li):
result = li[:]
result.sort()
return result
# path
def mypath(file):
""" Construct a file path relative to the scyther-gui main directory
"""
basedir = os.path.dirname(__file__)
return os.path.join(basedir,file)

View File

@ -34,14 +34,17 @@ class Scyther(object):
""" Non-windows """
self.program = os.path.join("bin","scyther")
# defaults
self.options = ""
# Init
self.spdl = None
self.inputfile = None
self.claims = None
self.errors = None
self.errorcount = 0
self.run = False
self.output = None
# defaults
self.xml = True # this results in a claim end, otherwise we simply get the output
def setInput(self,spdl):
self.spdl = spdl
@ -67,7 +70,10 @@ class Scyther(object):
def verify(self):
# Run Scyther on temp file
self.cmd = "%s --dot-output --xml-output --plain %s" % (self.program,self.options)
self.cmd = self.program
if self.xml:
self.cmd += " --dot-output --xml-output --plain"
self.cmd += " " + self.options
(stdin,stdout,stderr) = os.popen3(self.cmd)
if self.spdl:
@ -80,7 +86,7 @@ class Scyther(object):
# TODO this is annoying: we would like to determine progress
# from the error output (maybe this can also be done by flushing
# the XML at certain points...)
xmlinput = stdout.read()
output = stdout.read()
errlines = stderr.readlines()
# filter out any non-errors (say maybe only claim etc) and count
@ -96,16 +102,21 @@ class Scyther(object):
stdout.close()
stderr.close()
if len(xmlinput) > 0:
xmlfile = StringIO.StringIO(xmlinput)
reader = XMLReader.XMLReader()
self.claims = reader.readXML(xmlfile)
if self.xml:
if len(output) > 0:
xmlfile = StringIO.StringIO(output)
reader = XMLReader.XMLReader()
self.claims = reader.readXML(xmlfile)
else:
# no output...
self.claims = []
result = self.claims
else:
# no output...
self.claims = []
self.output = output
result = self.output
self.run = True
return self.claims
return result
def getClaim(self,claimid):
if self.claims:
@ -119,10 +130,13 @@ class Scyther(object):
if self.errorcount > 0:
return "%i errors:\n%s" % (self.errorcount, "\n".join(self.errors))
else:
s = "Claim results:\n"
for cl in self.claims:
s += str(cl) + "\n"
return s
if self.xml:
s = "Claim results:\n"
for cl in self.claims:
s += str(cl) + "\n"
return s
else:
return self.output
else:
return "Scyther has not been run yet."

View File

@ -6,7 +6,7 @@ Test script to execute multi-protocol attacks on some test set.
"""
import Scyther
import Scyther.Scyther as Scyther
def MyScyther(protocollist,filter=None):
"""

View File

@ -10,9 +10,9 @@ from optparse import OptionParser, SUPPRESS_HELP
#---------------------------------------------------------------------------
""" Import scyther-gui components """
import Preference
import Mainwindow
import Misc
import Gui.Preference as Preference
import Gui.Mainwindow as Mainwindow
import Gui.Misc as Misc
#---------------------------------------------------------------------------