1 '''
2 Common functions and classes.
3
4 @author: Michael Eddington
5 @version: $Id$
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
36 '''
37 Holds static stuff
38 '''
39
40 globals = None
41 locals = None
42
44 '''
45 Soft exceptions should end the current test
46 iteration, but not the run. They are "recoverable"
47 or "try again" errors.
48 '''
49 pass
50
52 '''
53 Hard exceptions are non-recoverable and should
54 end the fuzzing run.
55 '''
56 pass
57
59 '''
60 Indicate we should re-run the current test. A recoverable error
61 occured. The main enging loop should only retry the test case 3
62 times before turning this into a hard exception.
63 '''
64 pass
65
67 '''
68 Peach exceptions are specialized hard exceptions. The
69 message contained in a PeachException is presentable to the
70 user w/o any stack trace, etc.
71
72 Examples would be:
73
74 "Error: The DataModel element requires a name attribute."
75
76 '''
77
78 - def __init__(self, msg, module = "Unknown"):
82
89
90
92 '''
93 Eval python code returning result.
94
95 code - String
96 environment - Dictionary, keys are variables to place in local scope
97 '''
98
99 globalScope = {}
100 localScope = {}
101
102 if Holder.globals != None:
103 for k in Holder.globals:
104 globalScope[k] = Holder.globals[k]
105
106 if Holder.locals != None:
107 for k in Holder.locals:
108 localScope[k] = Holder.locals[k]
109
110 for k in environment.keys():
111 globalScope[k] = environment[k]
112 localScope[k] = environment[k]
113
114 ret = eval(code, globalScope, localScope)
115
116 return ret
117
119 """Gets a single character from standard input. Does not echo to the
120 screen."""
126
128
129
133
135 import sys, tty, termios
136 fd = sys.stdin.fileno()
137 old_settings = termios.tcgetattr(fd)
138 try:
139 tty.setraw(sys.stdin.fileno())
140 ch = sys.stdin.read(1)
141 finally:
142 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
143 return ch
144
145
149
151 import msvcrt
152 return msvcrt.getch()
153
154
155 getch = _Getch()
156
157
158