-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_file_struct_funcs.py
48 lines (32 loc) · 1.4 KB
/
test_file_struct_funcs.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
import nose
import angr
import os
import logging
l = logging.getLogger('angr.tests.test_file_struct_funcs')
test_location = os.path.dirname(os.path.realpath(__file__))
def check_state_1(state):
# Need to dump file.txt by path because program closes it
return state.posix.dump_file_by_path('file.txt') == b"testing abcdef" and \
state.posix.dumps(0)[:4] == b"xyz\n" and \
state.posix.dumps(1) == b"good1\n" and \
state.posix.dumps(2) == b""
def check_state_2(state):
return state.posix.dump_file_by_path('file.txt') == b"testing abcdef" and \
state.posix.dumps(0)[:4] == b"wxyz" and \
state.posix.dumps(1) == b"" and \
state.posix.dumps(2) == b"good2\n"
def check_state_3(state):
return state.posix.dump_file_by_path('file.txt') == b"testing abcdef" and \
state.posix.dumps(1) == b"" and \
state.posix.dumps(2) == b""
def test_file_struct_funcs():
test_bin = os.path.join(test_location, '..', '..', 'binaries', 'tests', 'x86_64', 'file_func_test')
b = angr.Project(test_bin)
pg = b.factory.simulation_manager()
pg.active[0].options.discard("LAZY_SOLVES")
pg.explore()
nose.tools.assert_equal(len(pg.deadended), 3)
for p in pg.deadended:
nose.tools.assert_true(check_state_1(p) or check_state_2(p) or check_state_3(p))
if __name__ == "__main__":
test_file_struct_funcs()