-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroken_orwc.py
75 lines (59 loc) · 1.86 KB
/
broken_orwc.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
#!/usr/bin/env python
"""
This is the first of many syscall tests
"""
import logging
l = logging.getLogger("angr.tests")
import angr
import nose
# load the tests
import os
test_location = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'binaries', 'tests')
p_rw = None
p = None
def setup_rw():
global p_rw
p_rw = angr.Project(os.path.join(test_location, 'x86_64', 'rw'), use_sim_procedures=False)
def setup_orwc():
global p
p = angr.Project(os.path.join(test_location, 'x86_64', 'orwc'), use_sim_procedures=False)
def setup_module():
setup_rw()
setup_orwc()
def test_rw():
explore = angr.surveyors.Explorer(p_rw, find=[0x400100]).run()
path = explore.found[0]
state = path.state
system = state.get_plugin('posix')
w_len = system.get_file(1).pos
r_len = system.get_file(0).pos
r_len = state.solver.eval(r_len)
nose.tools.assert_equal(r_len, w_len)
nose.tools.assert_equal(32, r_len)
def test_orwc():
four_files = angr.surveyors.Explorer(p, find=[0x400120]).run()
path = four_files.found[0]
state = path.state
system = state.get_plugin('posix')
num_files = len(system.files)
w_len = system.get_file(3).pos
r_len = system.get_file(0).pos
r_len = state.solver.eval(r_len)
after_close = angr.surveyors.Explorer(p, find=[0x400124]).run()
path = after_close.found[0]
state = path.state
system = state.get_plugin('posix')
files_ac = len(system.files) #files after close...so we expect one less file :)
nose.tools.assert_equal(4, num_files)
nose.tools.assert_equal(3, files_ac)
nose.tools.assert_equal(r_len, w_len)
nose.tools.assert_equal(32, r_len)
if __name__ == '__main__':
try:
__import__('standard_logging')
__import__('angr_debug')
except ImportError:
pass
setup_module()
test_rw()
test_orwc()