1import nose 2import angr 3 4import os 5import logging 6 7l = logging.getLogger('angr.tests.test_file_struct_funcs') 8 9test_location = os.path.dirname(os.path.realpath(__file__)) 10 11 12def check_state_1(state): 13 # Need to dump file.txt by path because program closes it 14 return state.posix.dump_file_by_path('file.txt') == b"testing abcdef" and \ 15 state.posix.dumps(0)[:4] == b"xyz\n" and \ 16 state.posix.dumps(1) == b"good1\n" and \ 17 state.posix.dumps(2) == b"" 18 19 20def check_state_2(state): 21 return state.posix.dump_file_by_path('file.txt') == b"testing abcdef" and \ 22 state.posix.dumps(0)[:4] == b"wxyz" and \ 23 state.posix.dumps(1) == b"" and \ 24 state.posix.dumps(2) == b"good2\n" 25 26 27def check_state_3(state): 28 return state.posix.dump_file_by_path('file.txt') == b"testing abcdef" and \ 29 state.posix.dumps(1) == b"" and \ 30 state.posix.dumps(2) == b"" 31 32 33def test_file_struct_funcs(): 34 test_bin = os.path.join(test_location, '..', '..', 'binaries', 'tests', 'x86_64', 'file_func_test') 35 b = angr.Project(test_bin) 36 37 pg = b.factory.simulation_manager() 38 pg.active[0].options.discard("LAZY_SOLVES") 39 pg.explore() 40 41 nose.tools.assert_equal(len(pg.deadended), 3) 42 43 for p in pg.deadended: 44 nose.tools.assert_true(check_state_1(p) or check_state_2(p) or check_state_3(p)) 45 46 47if __name__ == "__main__": 48 test_file_struct_funcs() 49