forked from angr/angr-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
155 lines (142 loc) · 6.26 KB
/
test.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# pylint: disable=exec-used
import os
import sys
import itertools
import traceback
from nose.plugins.attrib import attr
import claripy
def _path(d):
return os.path.join(os.path.dirname(__file__), d)
md_files = filter(lambda s: s.endswith('.md'), [
os.path.join(_path('docs'), t) for t in os.listdir(_path('docs'))
])
md_files += filter(lambda s: s.endswith('.md'), [
os.path.join(_path('docs/analyses'), t) for t in os.listdir(_path('docs/analyses'))
])
md_files += filter(lambda s: s.endswith('.md'), [
os.path.join(_path('docs/courses'), t) for t in os.listdir(_path('docs/courses'))
])
example_dirs = filter(lambda s: '.' not in s, os.listdir(_path('examples')))
sys.path.append('.')
def exampletest_single(example_dir):
os.chdir(_path('examples/') + example_dir)
print os.getcwd()
try:
s = __import__('solve')
s = reload(s)
s.test()
finally:
os.chdir('../..')
def doctest_single(md_file):
claripy.ast.base.var_counter = itertools.count()
lines = open(md_file).read().split('\n')
test_enabled = False
multiline_enabled = False
multiline_stuff = ''
env = {}
def try_running(line, i):
try:
exec line in env
except Exception as e:
print 'Error on line %d of %s: %s' % (i+1, md_file, e)
traceback.print_exc()
raise Exception('Error on line %d of %s: %s' % (i+1, md_file, e))
for i, line in enumerate(lines):
if test_enabled:
if line == '```':
test_enabled = False
else:
if not multiline_enabled:
if line.startswith('>>> '):
line = line[4:]
if lines[i+1].startswith('... '):
multiline_enabled = True
multiline_stuff = line + '\n'
else:
try_running(line, i)
else:
assert line.startswith('... ')
line = line[4:]
multiline_stuff += line + '\n'
if not lines[i+1].startswith('... '):
multiline_enabled = False
try_running(multiline_stuff, i)
else:
if line == '```python':
test_enabled = True
def test_docs():
os.chdir(_path('.'))
for md_file in md_files:
yield doctest_single, md_file
#def test_9447_nobranch(): exampletest_single('9447_nobranch')
def test_0ctf_trace(): exampletest_single('0ctf_trace')
def test_ais3_crackme(): exampletest_single('ais3_crackme')
def test_asisctffinals2015_fake(): exampletest_single('asisctffinals2015_fake')
def test_asisctffinals2015_license(): exampletest_single('asisctffinals2015_license')
def test_CADET_00001(): exampletest_single('CADET_00001')
@attr(speed='slow')
def test_cmu_binary_bomb(): exampletest_single('cmu_binary_bomb')
#def test_csaw_wyvern(): exampletest_single('csaw_wyvern')
def test_defcamp_r100(): exampletest_single('defcamp_r100')
#def test_defcamp_r200(): exampletest_single('defcamp_r200')
def test_ekopartyctf2015_rev100(): exampletest_single('ekopartyctf2015_rev100')
def test_ekopartyctf2016_rev250(): exampletest_single('ekopartyctf2016_rev250')
def test_ekopartyctf2016_sokohashv2(): exampletest_single('ekopartyctf2016_sokohashv2')
def test_fauxware(): exampletest_single('fauxware')
def test_flareon2015_10(): exampletest_single('flareon2015_10')
def test_flareon2015_2(): exampletest_single('flareon2015_2')
def test_flareon2015_5(): exampletest_single('flareon2015_5')
def test_google2016_unbreakable_0(): exampletest_single('google2016_unbreakable_0')
def test_google2016_unbreakable_1(): exampletest_single('google2016_unbreakable_1')
def test_grub(): exampletest_single('grub')
#def test_layer7_onlyone(): exampletest_single('layer7_onlyone')
def test_mma_howtouse(): exampletest_single('mma_howtouse')
#def test_mma_simplehash(): exampletest_single('mma_simplehash')
def test_securityfest_fairlight(): exampletest_single('securityfest_fairlight')
def test_strcpy_find(): exampletest_single('strcpy_find')
def test_whitehat_crypto400(): exampletest_single('whitehat_crypto400')
def test_whitehatvn2015_re400(): exampletest_single('whitehatvn2015_re400')
def test_secconquals2016_ropsynth(): exampletest_single('secconquals2016_ropsynth')
#def test_0ctf_momo_3(): exampletest_single('0ctf_momo_3')
#def test_defcon2016quals_baby_re_0(): exampletest_single('defcon2016quals_baby-re_0')
def test_defcon2016quals_baby_re_1(): exampletest_single('defcon2016quals_baby-re_1')
def test_sharif7_rev50(): exampletest_single(os.path.join('sharif7', 'rev50'))
def test_simple_heap_overflow(): exampletest_single('simple_heap_overflow')
if __name__ == '__main__':
for tester, arg in test_docs():
tester(arg)
init_pwd = os.getcwd()
exampletest_single('0ctf_trace')
exampletest_single('ais3_crackme')
exampletest_single('asisctffinals2015_fake')
exampletest_single('asisctffinals2015_license')
exampletest_single('CADET_00001')
exampletest_single('cmu_binary_bomb')
exampletest_single('codegate_2017-angrybird')
exampletest_single('csaw_wyvern')
csci = os.path.join('CSCI-4968-MBE', 'challenges')
for crackme in os.listdir('examples/CSCI-4968-MBE/challenges'):
exampletest_single(os.path.join(csci, crackme))
os.chdir(init_pwd)
exampletest_single('defcamp_r100')
exampletest_single('defcon2016quals_baby-re_1')
exampletest_single('ekopartyctf2015_rev100')
exampletest_single('ekopartyctf2016_rev250')
# exampletest_single('ekopartyctf2016_sokohashv2')
exampletest_single('fauxware')
# exampletest_single('flareon2015_10')
exampletest_single('flareon2015_2')
# exampletest_single('flareon2015_5')
exampletest_single('google2016_unbreakable_0')
exampletest_single('google2016_unbreakable_1')
exampletest_single('grub')
# exampletest_single('mma_howtouse')
exampletest_single('secuinside2016mbrainfuzz')
exampletest_single('securityfest_fairlight')
exampletest_single('sharif7/rev50')
os.chdir(init_pwd)
# exampletest_single('simple_heap_overflow')
exampletest_single('strcpy_find')
exampletest_single('sym-write')
exampletest_single('whitehat_crypto400')
# exampletest_single('whitehatvn2015_re400')