angr 9.2.87__py3-none-manylinux2014_x86_64.whl → 9.2.89__py3-none-manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of angr might be problematic. Click here for more details.
- angr/__init__.py +4 -1
- angr/analyses/decompiler/clinic.py +16 -0
- angr/analyses/decompiler/decompiler.py +3 -0
- angr/analyses/decompiler/optimization_passes/__init__.py +5 -0
- angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +108 -0
- angr/analyses/decompiler/optimization_passes/optimization_pass.py +17 -4
- angr/analyses/decompiler/optimization_passes/return_duplicator.py +4 -32
- angr/analyses/decompiler/structured_codegen/c.py +12 -2
- angr/analyses/decompiler/utils.py +13 -0
- angr/analyses/typehoon/dfa.py +108 -0
- angr/analyses/typehoon/lifter.py +34 -2
- angr/analyses/typehoon/simple_solver.py +1043 -503
- angr/analyses/typehoon/translator.py +13 -4
- angr/analyses/typehoon/typeconsts.py +117 -36
- angr/analyses/typehoon/typehoon.py +31 -11
- angr/analyses/typehoon/typevars.py +88 -21
- angr/analyses/typehoon/variance.py +10 -0
- angr/analyses/variable_recovery/engine_ail.py +28 -9
- angr/analyses/variable_recovery/engine_base.py +50 -43
- angr/analyses/variable_recovery/variable_recovery_base.py +16 -3
- angr/analyses/variable_recovery/variable_recovery_fast.py +14 -5
- angr/exploration_techniques/tracer.py +2 -0
- angr/misc/autoimport.py +26 -0
- angr/procedures/definitions/__init__.py +32 -3
- angr/utils/constants.py +1 -0
- angr/utils/graph.py +20 -1
- {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/METADATA +7 -6
- {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/RECORD +32 -244
- angr-9.2.89.dist-info/top_level.txt +1 -0
- angr/procedures/definitions/ntdll.py +0 -12
- angr-9.2.87.dist-info/top_level.txt +0 -2
- tests/__init__.py +0 -0
- tests/analyses/__init__.py +0 -0
- tests/analyses/cfg/__init__.py +0 -0
- tests/analyses/cfg/test_cfg_clflush.py +0 -43
- tests/analyses/cfg/test_cfg_get_any_node.py +0 -34
- tests/analyses/cfg/test_cfg_manager.py +0 -32
- tests/analyses/cfg/test_cfg_model.py +0 -55
- tests/analyses/cfg/test_cfg_patching.py +0 -378
- tests/analyses/cfg/test_cfg_rust_got_resolution.py +0 -36
- tests/analyses/cfg/test_cfg_thumb_firmware.py +0 -50
- tests/analyses/cfg/test_cfg_vex_postprocessor.py +0 -27
- tests/analyses/cfg/test_cfgemulated.py +0 -634
- tests/analyses/cfg/test_cfgfast.py +0 -1123
- tests/analyses/cfg/test_cfgfast_soot.py +0 -38
- tests/analyses/cfg/test_const_resolver.py +0 -38
- tests/analyses/cfg/test_iat_resolver.py +0 -37
- tests/analyses/cfg/test_jumptables.py +0 -3008
- tests/analyses/cfg/test_noop_blocks.py +0 -54
- tests/analyses/cfg_slice_to_sink/__init__.py +0 -0
- tests/analyses/cfg_slice_to_sink/test_cfg_slice_to_sink.py +0 -93
- tests/analyses/cfg_slice_to_sink/test_graph.py +0 -114
- tests/analyses/cfg_slice_to_sink/test_transitions.py +0 -28
- tests/analyses/decompiler/__init__.py +0 -0
- tests/analyses/decompiler/test_baseptr_save_simplifier.py +0 -80
- tests/analyses/decompiler/test_decompiler.py +0 -3336
- tests/analyses/decompiler/test_peephole_optimizations.py +0 -48
- tests/analyses/decompiler/test_propagator_loops.py +0 -101
- tests/analyses/decompiler/test_structurer.py +0 -275
- tests/analyses/reaching_definitions/__init__.py +0 -0
- tests/analyses/reaching_definitions/test_dep_graph.py +0 -432
- tests/analyses/reaching_definitions/test_function_handler.py +0 -131
- tests/analyses/reaching_definitions/test_heap_allocator.py +0 -46
- tests/analyses/reaching_definitions/test_rd_state.py +0 -78
- tests/analyses/reaching_definitions/test_reachingdefinitions.py +0 -463
- tests/analyses/reaching_definitions/test_subject.py +0 -76
- tests/analyses/test_bindiff.py +0 -52
- tests/analyses/test_block_simplifier.py +0 -112
- tests/analyses/test_boyscout.py +0 -104
- tests/analyses/test_calling_convention_analysis.py +0 -352
- tests/analyses/test_callsite_maker.py +0 -60
- tests/analyses/test_cdg.py +0 -165
- tests/analyses/test_cfb.py +0 -37
- tests/analyses/test_class_identifier.py +0 -46
- tests/analyses/test_clinic.py +0 -30
- tests/analyses/test_codetagging.py +0 -32
- tests/analyses/test_constantpropagation.py +0 -88
- tests/analyses/test_ddg.py +0 -95
- tests/analyses/test_ddg_global_var_dependencies.py +0 -83
- tests/analyses/test_ddg_memvar_addresses.py +0 -40
- tests/analyses/test_disassembly.py +0 -121
- tests/analyses/test_find_objects_static.py +0 -35
- tests/analyses/test_flirt.py +0 -49
- tests/analyses/test_identifier.py +0 -33
- tests/analyses/test_init_finder.py +0 -38
- tests/analyses/test_proximitygraph.py +0 -31
- tests/analyses/test_reassembler.py +0 -295
- tests/analyses/test_regionidentifier.py +0 -27
- tests/analyses/test_slicing.py +0 -164
- tests/analyses/test_stack_pointer_tracker.py +0 -74
- tests/analyses/test_static_hooker.py +0 -28
- tests/analyses/test_typehoon.py +0 -55
- tests/analyses/test_variablerecovery.py +0 -464
- tests/analyses/test_vfg.py +0 -221
- tests/analyses/test_vtable.py +0 -31
- tests/analyses/test_xrefs.py +0 -77
- tests/common.py +0 -128
- tests/engines/__init__.py +0 -0
- tests/engines/light/__init__.py +0 -0
- tests/engines/light/test_data.py +0 -17
- tests/engines/pcode/__init__.py +0 -0
- tests/engines/pcode/test_emulate.py +0 -607
- tests/engines/pcode/test_pcode.py +0 -84
- tests/engines/test_actions.py +0 -27
- tests/engines/test_hook.py +0 -112
- tests/engines/test_java.py +0 -697
- tests/engines/test_unicorn.py +0 -518
- tests/engines/vex/__init__.py +0 -0
- tests/engines/vex/test_lifter.py +0 -124
- tests/engines/vex/test_vex.py +0 -574
- tests/exploration_techniques/__init__.py +0 -0
- tests/exploration_techniques/test_cacher.py +0 -45
- tests/exploration_techniques/test_director.py +0 -67
- tests/exploration_techniques/test_driller_core.py +0 -48
- tests/exploration_techniques/test_loop_seer.py +0 -158
- tests/exploration_techniques/test_memory_watcher.py +0 -46
- tests/exploration_techniques/test_oppologist.py +0 -65
- tests/exploration_techniques/test_spiller.py +0 -82
- tests/exploration_techniques/test_stochastic.py +0 -40
- tests/exploration_techniques/test_tech_builder.py +0 -61
- tests/exploration_techniques/test_tracer.py +0 -856
- tests/exploration_techniques/test_unique.py +0 -40
- tests/exploration_techniques/test_veritesting.py +0 -120
- tests/factory/__init__.py +0 -0
- tests/factory/block/__init__.py +0 -0
- tests/factory/block/test_block_cache.py +0 -33
- tests/factory/block/test_keystone.py +0 -106
- tests/factory/test_argc.py +0 -101
- tests/factory/test_argc_sym.py +0 -110
- tests/factory/test_argv.py +0 -158
- tests/factory/test_callable.py +0 -266
- tests/factory/test_windows_args.py +0 -36
- tests/knowledge_plugins/__init__.py +0 -0
- tests/knowledge_plugins/cfg/__init__.py +0 -0
- tests/knowledge_plugins/cfg/test_cfg_manager.py +0 -36
- tests/knowledge_plugins/functions/__init__.py +0 -0
- tests/knowledge_plugins/functions/test_function.py +0 -91
- tests/knowledge_plugins/functions/test_function2.py +0 -79
- tests/knowledge_plugins/functions/test_function_manager.py +0 -139
- tests/knowledge_plugins/functions/test_prototypes.py +0 -53
- tests/knowledge_plugins/key_definitions/__init__.py +0 -0
- tests/knowledge_plugins/key_definitions/test_atoms.py +0 -24
- tests/knowledge_plugins/key_definitions/test_environment.py +0 -126
- tests/knowledge_plugins/key_definitions/test_heap_address.py +0 -27
- tests/knowledge_plugins/key_definitions/test_live_definitions.py +0 -72
- tests/knowledge_plugins/test_dwarf_variables.py +0 -240
- tests/knowledge_plugins/test_kb_plugins.py +0 -91
- tests/knowledge_plugins/test_kb_plugins_dwarf.py +0 -36
- tests/knowledge_plugins/test_patches.py +0 -48
- tests/misc/__init__.py +0 -0
- tests/misc/test_hookset.py +0 -57
- tests/perf/__init__.py +0 -0
- tests/perf/perf_cfgemulated.py +0 -19
- tests/perf/perf_cfgfast.py +0 -18
- tests/perf/perf_concrete_execution.py +0 -41
- tests/perf/perf_siminspect_nop.py +0 -36
- tests/perf/perf_state_copy.py +0 -33
- tests/perf/perf_unicorn_0.py +0 -27
- tests/perf/perf_unicorn_1.py +0 -23
- tests/procedures/__init__.py +0 -0
- tests/procedures/glibc/__init__.py +0 -0
- tests/procedures/glibc/test_ctype_locale.py +0 -164
- tests/procedures/libc/__init__.py +0 -0
- tests/procedures/libc/test_fgets.py +0 -53
- tests/procedures/libc/test_scanf.py +0 -205
- tests/procedures/libc/test_sprintf.py +0 -44
- tests/procedures/libc/test_sscanf.py +0 -63
- tests/procedures/libc/test_strcasecmp.py +0 -37
- tests/procedures/libc/test_string.py +0 -1102
- tests/procedures/libc/test_strtol.py +0 -78
- tests/procedures/linux_kernel/__init__.py +0 -0
- tests/procedures/linux_kernel/test_lseek.py +0 -174
- tests/procedures/posix/__init__.py +0 -0
- tests/procedures/posix/test_chroot.py +0 -33
- tests/procedures/posix/test_getenv.py +0 -78
- tests/procedures/posix/test_pwrite_pread.py +0 -57
- tests/procedures/posix/test_sim_time.py +0 -46
- tests/procedures/posix/test_unlink.py +0 -46
- tests/procedures/test_project_resolve_simproc.py +0 -43
- tests/procedures/test_sim_procedure.py +0 -117
- tests/procedures/test_stub_procedure_args.py +0 -53
- tests/serialization/__init__.py +0 -0
- tests/serialization/test_db.py +0 -197
- tests/serialization/test_pickle.py +0 -95
- tests/serialization/test_serialization.py +0 -132
- tests/serialization/test_vault.py +0 -169
- tests/sim/__init__.py +0 -3
- tests/sim/exec_func/__init__.py +0 -0
- tests/sim/exec_func/test_mem_funcs.py +0 -55
- tests/sim/exec_func/test_str_funcs.py +0 -93
- tests/sim/exec_func/test_syscall_result.py +0 -39
- tests/sim/exec_insn/__init__.py +0 -0
- tests/sim/exec_insn/test_adc.py +0 -44
- tests/sim/exec_insn/test_ops.py +0 -83
- tests/sim/exec_insn/test_rcr.py +0 -26
- tests/sim/exec_insn/test_rol.py +0 -51
- tests/sim/exec_insn/test_signed_div.py +0 -34
- tests/sim/exec_insn/test_sqrt.py +0 -56
- tests/sim/options/__init__.py +0 -0
- tests/sim/options/test_0div.py +0 -54
- tests/sim/options/test_symbolic_fd.py +0 -59
- tests/sim/options/test_unsupported.py +0 -34
- tests/sim/test_accuracy.py +0 -137
- tests/sim/test_checkbyte.py +0 -53
- tests/sim/test_echo.py +0 -36
- tests/sim/test_fauxware.py +0 -202
- tests/sim/test_self_modifying_code.py +0 -65
- tests/sim/test_simple_api.py +0 -36
- tests/sim/test_simulation_manager.py +0 -147
- tests/sim/test_stack_alignment.py +0 -65
- tests/sim/test_state.py +0 -303
- tests/sim/test_state_customization.py +0 -54
- tests/sim/test_symbol_hooked_by.py +0 -49
- tests/simos/__init__.py +0 -0
- tests/simos/windows/__init__.py +0 -0
- tests/simos/windows/test_windows_stack_cookie.py +0 -58
- tests/state_plugins/__init__.py +0 -0
- tests/state_plugins/inspect/__init__.py +0 -0
- tests/state_plugins/inspect/test_inspect.py +0 -310
- tests/state_plugins/inspect/test_syscall_override.py +0 -90
- tests/state_plugins/posix/__init__.py +0 -0
- tests/state_plugins/posix/test_file_struct_funcs.py +0 -56
- tests/state_plugins/posix/test_files.py +0 -69
- tests/state_plugins/posix/test_posix.py +0 -72
- tests/state_plugins/solver/__init__.py +0 -0
- tests/state_plugins/solver/test_simsolver.py +0 -58
- tests/state_plugins/solver/test_symbolic.py +0 -153
- tests/state_plugins/solver/test_variable_registration.py +0 -46
- tests/state_plugins/test_callstack.py +0 -54
- tests/state_plugins/test_gdb_plugin.py +0 -35
- tests/state_plugins/test_multi_open_file.py +0 -47
- tests/state_plugins/test_symbolization.py +0 -38
- tests/storage/__init__.py +0 -0
- tests/storage/test_memory.py +0 -960
- tests/storage/test_memory_merge.py +0 -114
- tests/storage/test_memview.py +0 -205
- tests/storage/test_mmap.py +0 -26
- tests/storage/test_multivalues.py +0 -44
- tests/storage/test_permissions.py +0 -32
- tests/storage/test_ptmalloc.py +0 -291
- tests/storage/test_relro_perm.py +0 -49
- tests/test_calling_conventions.py +0 -86
- tests/test_types.py +0 -329
- tests/utils/__init__.py +0 -0
- tests/utils/test_graph.py +0 -41
- {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/LICENSE +0 -0
- {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/WHEEL +0 -0
- {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/entry_points.txt +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
__package__ = __package__ or "tests.procedures.libc" # pylint:disable=redefined-builtin
|
|
3
|
-
|
|
4
|
-
import os
|
|
5
|
-
import subprocess
|
|
6
|
-
import sys
|
|
7
|
-
import unittest
|
|
8
|
-
|
|
9
|
-
import angr
|
|
10
|
-
|
|
11
|
-
from ...common import slow_test, bin_location # pylint:disable=import-error,wrong-import-position
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TestStrtol(unittest.TestCase):
|
|
15
|
-
# pylint: disable=no-self-use
|
|
16
|
-
|
|
17
|
-
@slow_test
|
|
18
|
-
@unittest.skipUnless(sys.platform.startswith("linux"), "linux-only")
|
|
19
|
-
def test_strtol(self, threads=None):
|
|
20
|
-
test_bin = os.path.join(bin_location, "tests", "x86_64", "strtol_test")
|
|
21
|
-
# disabling auto_load_libs increases the execution time of the test case.
|
|
22
|
-
b = angr.Project(test_bin, auto_load_libs=True)
|
|
23
|
-
|
|
24
|
-
initial_state = b.factory.entry_state(remove_options={angr.options.LAZY_SOLVES})
|
|
25
|
-
pg = b.factory.simulation_manager(thing=initial_state, threads=threads)
|
|
26
|
-
|
|
27
|
-
# find the end of main
|
|
28
|
-
expected_outputs = {
|
|
29
|
-
b"base 8 worked\n",
|
|
30
|
-
b"base +8 worked\n",
|
|
31
|
-
b"0x worked\n",
|
|
32
|
-
b"+0x worked\n",
|
|
33
|
-
b"base +10 worked\n",
|
|
34
|
-
b"base 10 worked\n",
|
|
35
|
-
b"base -8 worked\n",
|
|
36
|
-
b"-0x worked\n",
|
|
37
|
-
b"base -10 worked\n",
|
|
38
|
-
b"Nope\n",
|
|
39
|
-
}
|
|
40
|
-
pg.explore(find=0x400804, num_find=len(expected_outputs))
|
|
41
|
-
assert len(pg.found) == len(expected_outputs)
|
|
42
|
-
|
|
43
|
-
# check the outputs
|
|
44
|
-
pipe = subprocess.PIPE
|
|
45
|
-
for f in pg.found:
|
|
46
|
-
test_input = f.posix.dumps(0)
|
|
47
|
-
test_output = f.posix.dumps(1)
|
|
48
|
-
expected_outputs.remove(test_output)
|
|
49
|
-
|
|
50
|
-
# check the output works as expected
|
|
51
|
-
with subprocess.Popen(test_bin, stdout=pipe, stderr=pipe, stdin=pipe) as p:
|
|
52
|
-
ret = p.communicate(test_input)[0]
|
|
53
|
-
assert ret == test_output
|
|
54
|
-
|
|
55
|
-
# check that all of the outputs were seen
|
|
56
|
-
assert len(expected_outputs) == 0
|
|
57
|
-
|
|
58
|
-
def test_strtol_long_string(self):
|
|
59
|
-
# convert a 11-digit long string to a number.
|
|
60
|
-
# there was an off-by-one error before.
|
|
61
|
-
|
|
62
|
-
b = angr.load_shellcode(b"\x90\x90", "AMD64")
|
|
63
|
-
state = b.factory.blank_state()
|
|
64
|
-
state.memory.store(0x500000, b"98831114236\x00")
|
|
65
|
-
|
|
66
|
-
state.libc.max_strtol_len = 11
|
|
67
|
-
|
|
68
|
-
strtol = angr.SIM_LIBRARIES["libc.so.6"].get("strtol", arch=b.arch)
|
|
69
|
-
strtol.state = state.copy()
|
|
70
|
-
ret = strtol.run(0x500000, 0, 0)
|
|
71
|
-
|
|
72
|
-
assert strtol.state.satisfiable()
|
|
73
|
-
assert len(strtol.state.solver.eval_upto(ret, 2)) == 1
|
|
74
|
-
assert strtol.state.solver.eval_one(ret) == 98831114236
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if __name__ == "__main__":
|
|
78
|
-
unittest.main()
|
|
File without changes
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import unittest
|
|
3
|
-
|
|
4
|
-
from angr import SIM_PROCEDURES
|
|
5
|
-
from angr import SimState, SimPosixError, SimFile
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
FAKE_ADDR = 0x100000
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def lseek(state, arguments):
|
|
12
|
-
return SIM_PROCEDURES["linux_kernel"]["lseek"]().execute(state, arguments=arguments)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Taken from unistd.h
|
|
16
|
-
SEEK_SET = 0 # Seek from beginning of file.
|
|
17
|
-
SEEK_CUR = 1 # Seek from current position.
|
|
18
|
-
SEEK_END = 2 # Seek from end of file.
|
|
19
|
-
# GNU Extensions
|
|
20
|
-
SEEK_DATA = 3 # Seek to next data.
|
|
21
|
-
SEEK_HOLE = 4 # Seek to next hole.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class TestLseek(unittest.TestCase):
|
|
25
|
-
def test_lseek_set(self):
|
|
26
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
27
|
-
|
|
28
|
-
# This could be any number above 2 really
|
|
29
|
-
fd = 3
|
|
30
|
-
|
|
31
|
-
# Create a file
|
|
32
|
-
state.fs.insert("/tmp/qwer", SimFile(name="qwer", size=100))
|
|
33
|
-
assert fd == state.posix.open(b"/tmp/qwer", 2)
|
|
34
|
-
|
|
35
|
-
# Part 1
|
|
36
|
-
|
|
37
|
-
# Seek to the top of the file
|
|
38
|
-
current_pos = lseek(state, [fd, 0, SEEK_SET]).ret_expr
|
|
39
|
-
current_pos = state.solver.eval(current_pos)
|
|
40
|
-
|
|
41
|
-
# We should be at the start
|
|
42
|
-
assert current_pos == 0
|
|
43
|
-
|
|
44
|
-
# Part 2
|
|
45
|
-
|
|
46
|
-
# Seek to the top of the file
|
|
47
|
-
current_pos = lseek(state, [fd, 8, SEEK_SET]).ret_expr
|
|
48
|
-
current_pos = state.solver.eval(current_pos)
|
|
49
|
-
|
|
50
|
-
# We should be at the start
|
|
51
|
-
assert current_pos == 8
|
|
52
|
-
|
|
53
|
-
# Part 3
|
|
54
|
-
|
|
55
|
-
# Seek to the top of the file
|
|
56
|
-
current_pos = lseek(state, [fd, 3, SEEK_SET]).ret_expr
|
|
57
|
-
current_pos = state.solver.eval(current_pos)
|
|
58
|
-
|
|
59
|
-
# We should be at the start
|
|
60
|
-
assert current_pos == 3
|
|
61
|
-
|
|
62
|
-
def test_lseek_cur(self):
|
|
63
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
64
|
-
|
|
65
|
-
# This could be any number above 2 really
|
|
66
|
-
fd = 3
|
|
67
|
-
|
|
68
|
-
# Create a file
|
|
69
|
-
state.fs.insert("/tmp/qwer", SimFile(name="qwer", size=100))
|
|
70
|
-
assert fd == state.posix.open(b"/tmp/qwer", 2)
|
|
71
|
-
|
|
72
|
-
# Part 1
|
|
73
|
-
|
|
74
|
-
# Add 12
|
|
75
|
-
current_pos = lseek(state, [fd, 12, SEEK_CUR]).ret_expr
|
|
76
|
-
current_pos = state.solver.eval(current_pos)
|
|
77
|
-
|
|
78
|
-
# We should be at the start
|
|
79
|
-
assert current_pos == 12
|
|
80
|
-
|
|
81
|
-
# Part 2
|
|
82
|
-
|
|
83
|
-
# Remove 3
|
|
84
|
-
current_pos = lseek(state, [fd, -3, SEEK_CUR]).ret_expr
|
|
85
|
-
current_pos = state.solver.eval(current_pos)
|
|
86
|
-
|
|
87
|
-
# We should be at the start
|
|
88
|
-
assert current_pos == 9
|
|
89
|
-
|
|
90
|
-
def test_lseek_end(self):
|
|
91
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
92
|
-
|
|
93
|
-
fd = 3
|
|
94
|
-
|
|
95
|
-
# Create a file
|
|
96
|
-
state.fs.insert("/tmp/qwer", SimFile(name="qwer", size=16))
|
|
97
|
-
assert fd == state.posix.open(b"/tmp/qwer", 2)
|
|
98
|
-
|
|
99
|
-
# Part 1
|
|
100
|
-
|
|
101
|
-
# Add 5
|
|
102
|
-
current_pos = lseek(state, [fd, 0, SEEK_END]).ret_expr
|
|
103
|
-
current_pos = state.solver.eval(current_pos)
|
|
104
|
-
|
|
105
|
-
# We should be at the end + offset
|
|
106
|
-
assert current_pos == 16
|
|
107
|
-
|
|
108
|
-
# Part 2
|
|
109
|
-
|
|
110
|
-
# Minus 6. End of file never actually changed
|
|
111
|
-
current_pos = lseek(state, [fd, -6, SEEK_END]).ret_expr
|
|
112
|
-
current_pos = state.solver.eval(current_pos)
|
|
113
|
-
|
|
114
|
-
# We should be at the end + offset
|
|
115
|
-
assert current_pos == 10
|
|
116
|
-
|
|
117
|
-
def test_lseek_unseekable(self):
|
|
118
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
119
|
-
|
|
120
|
-
# Illegal seek
|
|
121
|
-
current_pos = lseek(state, [0, 0, SEEK_SET]).ret_expr
|
|
122
|
-
current_pos = state.solver.eval(current_pos)
|
|
123
|
-
|
|
124
|
-
# Assert we have a negative return value
|
|
125
|
-
assert current_pos & (1 << 63) != 0
|
|
126
|
-
|
|
127
|
-
# Illegal seek
|
|
128
|
-
current_pos = lseek(state, [1, 0, SEEK_SET]).ret_expr
|
|
129
|
-
current_pos = state.solver.eval(current_pos)
|
|
130
|
-
|
|
131
|
-
# Assert we have a negative return value
|
|
132
|
-
assert current_pos & (1 << 63) != 0
|
|
133
|
-
|
|
134
|
-
# Illegal seek
|
|
135
|
-
current_pos = lseek(state, [2, 0, SEEK_SET]).ret_expr
|
|
136
|
-
current_pos = state.solver.eval(current_pos)
|
|
137
|
-
|
|
138
|
-
# Assert we have a negative return value
|
|
139
|
-
assert current_pos & (1 << 63) != 0
|
|
140
|
-
|
|
141
|
-
def test_lseek_symbolic_whence(self):
|
|
142
|
-
with self.assertRaises(SimPosixError):
|
|
143
|
-
# symbolic whence is currently not possible
|
|
144
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
145
|
-
|
|
146
|
-
# This could be any number above 2 really
|
|
147
|
-
fd = 3
|
|
148
|
-
|
|
149
|
-
# Create a file
|
|
150
|
-
assert fd == state.posix.open(b"/tmp/qwer", 1)
|
|
151
|
-
|
|
152
|
-
whence = state.solver.BVS("whence", 64)
|
|
153
|
-
|
|
154
|
-
# This should cause the exception
|
|
155
|
-
lseek(state, [fd, 0, whence])
|
|
156
|
-
|
|
157
|
-
def test_lseek_symbolic_seek(self):
|
|
158
|
-
# symbolic seek is currently not possible
|
|
159
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
160
|
-
|
|
161
|
-
# This could be any number above 2 really
|
|
162
|
-
fd = 3
|
|
163
|
-
|
|
164
|
-
# Create a file
|
|
165
|
-
assert fd == state.posix.open(b"/tmp/qwer", 1)
|
|
166
|
-
|
|
167
|
-
seek = state.solver.BVS("seek", 64)
|
|
168
|
-
|
|
169
|
-
# This should NOT cause an exception
|
|
170
|
-
lseek(state, [fd, seek, SEEK_SET])
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if __name__ == "__main__":
|
|
174
|
-
unittest.main()
|
|
File without changes
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# pylint:disable=missing-class-docstring,no-self-use
|
|
3
|
-
__package__ = __package__ or "tests.procedures.posix" # pylint:disable=redefined-builtin
|
|
4
|
-
|
|
5
|
-
import os
|
|
6
|
-
import unittest
|
|
7
|
-
|
|
8
|
-
import angr
|
|
9
|
-
from angr.state_plugins.posix import Flags
|
|
10
|
-
|
|
11
|
-
from ...common import bin_location
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
test_location = os.path.join(bin_location, "tests")
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class TestChroot(unittest.TestCase):
|
|
18
|
-
def test_chroot(self):
|
|
19
|
-
project = angr.Project(os.path.join(test_location, "x86_64", "chroot_test"))
|
|
20
|
-
initial_state = project.factory.entry_state()
|
|
21
|
-
|
|
22
|
-
simgr = project.factory.simgr(initial_state)
|
|
23
|
-
|
|
24
|
-
simgr.run()
|
|
25
|
-
|
|
26
|
-
# Try and read the files stat size from new chrooted dir
|
|
27
|
-
fd = simgr.deadended[0].posix.open("/test.txt", Flags.O_RDONLY)
|
|
28
|
-
stat = simgr.deadended[0].posix.fstat(fd)
|
|
29
|
-
print(f"File's Stat Size: {stat.st_size}")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if __name__ == "__main__":
|
|
33
|
-
unittest.main()
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# Disable some pylint warnings: no-self-use, missing-docstring
|
|
3
|
-
# pylint: disable=R0201, C0111
|
|
4
|
-
__package__ = __package__ or "tests.procedures.posix" # pylint:disable=redefined-builtin
|
|
5
|
-
|
|
6
|
-
import os
|
|
7
|
-
import unittest
|
|
8
|
-
|
|
9
|
-
import claripy
|
|
10
|
-
|
|
11
|
-
import angr
|
|
12
|
-
|
|
13
|
-
from ...common import bin_location
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
test_location = os.path.join(bin_location, "tests")
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class TestRunEcho(unittest.TestCase):
|
|
20
|
-
flag = "this_is_a_string!"
|
|
21
|
-
|
|
22
|
-
def test_run_getenv_with_env(self):
|
|
23
|
-
env = {"PATH": "/home/angr/", "TEST_ENV1": "this_is_a_string!", "JAVA_HOME": "jdk-install-dir"}
|
|
24
|
-
TEST_name = ["TEST_ENV1", "TEST_ENV2"]
|
|
25
|
-
p = angr.Project(os.path.join(test_location, "x86_64", "test_getenv"))
|
|
26
|
-
s = p.factory.entry_state(env=env)
|
|
27
|
-
simgr = p.factory.simulation_manager(s)
|
|
28
|
-
simgr.explore()
|
|
29
|
-
|
|
30
|
-
assert len(simgr.deadended) == 1
|
|
31
|
-
|
|
32
|
-
output_lines = simgr.deadended[0].posix.dumps(1).decode().splitlines(keepends=False)
|
|
33
|
-
expect_output = (
|
|
34
|
-
[f"# {k}={v}" for k, v in env.items()]
|
|
35
|
-
+ ["{k}: {v}".format(k=k, v=env.get(k, "__NULL__")) for k in TEST_name]
|
|
36
|
-
+ ["!! Bingo " + self.flag]
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
output_lines.sort()
|
|
40
|
-
expect_output.sort()
|
|
41
|
-
|
|
42
|
-
assert output_lines == expect_output
|
|
43
|
-
|
|
44
|
-
def test_run_getenv_without_env(self):
|
|
45
|
-
p = angr.Project(os.path.join(test_location, "x86_64", "test_getenv"))
|
|
46
|
-
s = p.factory.entry_state()
|
|
47
|
-
simgr = p.factory.simulation_manager(s)
|
|
48
|
-
simgr.explore()
|
|
49
|
-
|
|
50
|
-
assert len(simgr.deadended) == 2
|
|
51
|
-
|
|
52
|
-
bingo_count = 0
|
|
53
|
-
for s in simgr.deadended:
|
|
54
|
-
bingo_count += int(b"Bingo" in s.posix.dumps(1))
|
|
55
|
-
|
|
56
|
-
assert bingo_count == 1
|
|
57
|
-
|
|
58
|
-
def test_run_getenv_with_symbolic_env(self):
|
|
59
|
-
flag = claripy.Concat(*[claripy.BVS("flag_%d" % i, 8) for i in range(30)])
|
|
60
|
-
env = {"PATH": "/home/angr/", "TEST_ENV1": flag, "JAVA_HOME": "jdk-install-dir"}
|
|
61
|
-
p = angr.Project(os.path.join(test_location, "x86_64", "test_getenv"))
|
|
62
|
-
s = p.factory.entry_state(env=env)
|
|
63
|
-
simgr = p.factory.simulation_manager(s)
|
|
64
|
-
simgr.explore()
|
|
65
|
-
|
|
66
|
-
assert len(simgr.deadended) == 2
|
|
67
|
-
|
|
68
|
-
solved_flag = []
|
|
69
|
-
for s in simgr.deadended:
|
|
70
|
-
if b"Bingo" in s.posix.dumps(1):
|
|
71
|
-
solved_flag.append(s.solver.eval(flag, cast_to=bytes).strip(b"\x00"))
|
|
72
|
-
|
|
73
|
-
assert len(solved_flag) == 1
|
|
74
|
-
assert solved_flag[0].decode() == self.flag
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if __name__ == "__main__":
|
|
78
|
-
unittest.main()
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
|
|
3
|
-
|
|
4
|
-
import unittest
|
|
5
|
-
|
|
6
|
-
from angr import SimState, SimFile, SIM_PROCEDURES
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TestPwrite(unittest.TestCase):
|
|
10
|
-
def test_pwrite(self):
|
|
11
|
-
pwrite = SIM_PROCEDURES["posix"]["pwrite64"]()
|
|
12
|
-
|
|
13
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
14
|
-
simfile = SimFile("concrete_file", content="hello world!\n")
|
|
15
|
-
state.fs.insert("test", simfile)
|
|
16
|
-
fd = state.posix.open(b"test", 1)
|
|
17
|
-
|
|
18
|
-
buf_addr = 0xD0000000
|
|
19
|
-
state.memory.store(buf_addr, b"test!")
|
|
20
|
-
pwrite.execute(state, arguments=[fd, buf_addr, 5, 6])
|
|
21
|
-
|
|
22
|
-
simfd = state.posix.get_fd(fd)
|
|
23
|
-
simfd.seek(0)
|
|
24
|
-
res = 0xC0000000
|
|
25
|
-
simfd.read(res, 13)
|
|
26
|
-
data = state.solver.eval(state.mem[res].string.resolved, cast_to=bytes)
|
|
27
|
-
|
|
28
|
-
assert data == b"hello test!!\n"
|
|
29
|
-
|
|
30
|
-
state.posix.close(fd)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class TestPread(unittest.TestCase):
|
|
34
|
-
def test_pread(self):
|
|
35
|
-
pwrite = SIM_PROCEDURES["posix"]["pread64"]()
|
|
36
|
-
|
|
37
|
-
state = SimState(arch="AMD64", mode="symbolic")
|
|
38
|
-
simfile = SimFile("concrete_file", content="hello world!\n")
|
|
39
|
-
state.fs.insert("test", simfile)
|
|
40
|
-
fd = state.posix.open(b"test", 1)
|
|
41
|
-
|
|
42
|
-
buf1_addr = 0xD0000000
|
|
43
|
-
buf2_addr = 0xD0001000
|
|
44
|
-
pwrite.execute(state, arguments=[fd, buf1_addr, 6, 6])
|
|
45
|
-
pwrite.execute(state, arguments=[fd, buf2_addr, 5, 0])
|
|
46
|
-
|
|
47
|
-
data1 = state.solver.eval(state.mem[buf1_addr].string.resolved, cast_to=bytes)
|
|
48
|
-
data2 = state.solver.eval(state.mem[buf2_addr].string.resolved, cast_to=bytes)
|
|
49
|
-
|
|
50
|
-
assert data1 == b"world!"
|
|
51
|
-
assert data2 == b"hello"
|
|
52
|
-
|
|
53
|
-
state.posix.close(fd)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if __name__ == "__main__":
|
|
57
|
-
unittest.main()
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
|
|
3
|
-
|
|
4
|
-
import unittest
|
|
5
|
-
|
|
6
|
-
import angr
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TestSimTime(unittest.TestCase):
|
|
10
|
-
def test_gettimeofday(self):
|
|
11
|
-
proc = angr.SIM_PROCEDURES["posix"]["gettimeofday"]()
|
|
12
|
-
|
|
13
|
-
s = angr.SimState(arch="amd64")
|
|
14
|
-
s.regs.rdi = 0x8000
|
|
15
|
-
s.regs.rsi = 0
|
|
16
|
-
|
|
17
|
-
s.options.add(angr.options.USE_SYSTEM_TIMES)
|
|
18
|
-
proc.execute(s)
|
|
19
|
-
assert not s.mem[0x8000].qword.resolved.symbolic
|
|
20
|
-
assert not s.mem[0x8008].qword.resolved.symbolic
|
|
21
|
-
|
|
22
|
-
s.options.discard(angr.options.USE_SYSTEM_TIMES)
|
|
23
|
-
proc.execute(s)
|
|
24
|
-
assert s.mem[0x8000].qword.resolved.symbolic
|
|
25
|
-
assert s.mem[0x8008].qword.resolved.symbolic
|
|
26
|
-
|
|
27
|
-
def test_clock_gettime(self):
|
|
28
|
-
proc = angr.SIM_PROCEDURES["posix"]["clock_gettime"]()
|
|
29
|
-
|
|
30
|
-
s = angr.SimState(arch="amd64")
|
|
31
|
-
s.regs.rdi = 0
|
|
32
|
-
s.regs.rsi = 0x8000
|
|
33
|
-
|
|
34
|
-
s.options.add(angr.options.USE_SYSTEM_TIMES)
|
|
35
|
-
proc.execute(s)
|
|
36
|
-
assert not s.mem[0x8000].qword.resolved.symbolic
|
|
37
|
-
assert not s.mem[0x8008].qword.resolved.symbolic
|
|
38
|
-
|
|
39
|
-
s.options.discard(angr.options.USE_SYSTEM_TIMES)
|
|
40
|
-
proc.execute(s)
|
|
41
|
-
assert s.mem[0x8000].qword.resolved.symbolic
|
|
42
|
-
assert s.mem[0x8008].qword.resolved.symbolic
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if __name__ == "__main__":
|
|
46
|
-
unittest.main()
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
|
|
3
|
-
|
|
4
|
-
import unittest
|
|
5
|
-
|
|
6
|
-
import angr
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TestUnlink(unittest.TestCase):
|
|
10
|
-
def test_file_unlink(self):
|
|
11
|
-
# Initialize a blank state with an arbitrary errno location
|
|
12
|
-
state = angr.SimState(arch="AMD64", mode="symbolic")
|
|
13
|
-
state.libc.errno_location = 0xA0000000
|
|
14
|
-
state.libc.errno = 0
|
|
15
|
-
|
|
16
|
-
# Create a file 'test'
|
|
17
|
-
fd = state.posix.open(b"test", 1)
|
|
18
|
-
state.posix.close(fd)
|
|
19
|
-
|
|
20
|
-
# Ensure 'test' was in fact created
|
|
21
|
-
assert b"/test" in state.fs._files
|
|
22
|
-
|
|
23
|
-
# Store the filename in memory
|
|
24
|
-
path_addr = 0xB0000000
|
|
25
|
-
state.memory.store(path_addr, b"test\x00")
|
|
26
|
-
|
|
27
|
-
# Unlink 'test': should return 0 and leave ERRNO unchanged
|
|
28
|
-
unlink = angr.SIM_PROCEDURES["posix"]["unlink"]()
|
|
29
|
-
state.scratch.sim_procedure = unlink
|
|
30
|
-
rval = unlink.execute(state, arguments=[path_addr]).ret_expr
|
|
31
|
-
assert rval == 0
|
|
32
|
-
assert state.solver.eval(state.libc.errno) == 0
|
|
33
|
-
|
|
34
|
-
# Check that 'test' was in fact deleted
|
|
35
|
-
assert state.fs._files == {}
|
|
36
|
-
|
|
37
|
-
# Unlink again: should return -1 and set ERRNO to ENOENT
|
|
38
|
-
unlink = angr.SIM_PROCEDURES["posix"]["unlink"]()
|
|
39
|
-
state.scratch.sim_procedure = unlink
|
|
40
|
-
rval = unlink.execute(state, arguments=[path_addr]).ret_expr
|
|
41
|
-
assert rval == -1
|
|
42
|
-
assert state.solver.eval(state.libc.errno) == state.posix.ENOENT
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if __name__ == "__main__":
|
|
46
|
-
unittest.main()
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
|
|
3
|
-
__package__ = __package__ or "tests.procedures" # pylint:disable=redefined-builtin
|
|
4
|
-
|
|
5
|
-
import os
|
|
6
|
-
import unittest
|
|
7
|
-
|
|
8
|
-
import angr
|
|
9
|
-
|
|
10
|
-
from ..common import bin_location
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
test_location = os.path.join(bin_location, "tests")
|
|
14
|
-
bina = os.path.join(test_location, "x86_64", "test_project_resolve_simproc")
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# We voluntarily don't use SimProcedures for 'rand' and 'sleep' because we want
|
|
18
|
-
# to step into their lib code.
|
|
19
|
-
class TestProjectResolveSimProc(unittest.TestCase):
|
|
20
|
-
def test_bina(self):
|
|
21
|
-
# auto_load_libs can't be disabled as the testcase fails
|
|
22
|
-
p = angr.Project(bina, exclude_sim_procedures_list=["rand", "sleep"], load_options={"auto_load_libs": True})
|
|
23
|
-
|
|
24
|
-
# Make sure external functions are not replaced with a SimProcedure
|
|
25
|
-
sleep_jmpslot = p.loader.main_object.jmprel["sleep"]
|
|
26
|
-
rand_jmpslot = p.loader.main_object.jmprel["rand"]
|
|
27
|
-
read_jmpslot = p.loader.main_object.jmprel["read"]
|
|
28
|
-
|
|
29
|
-
sleep_addr = p.loader.memory.unpack_word(sleep_jmpslot.rebased_addr)
|
|
30
|
-
rand_addr = p.loader.memory.unpack_word(rand_jmpslot.rebased_addr)
|
|
31
|
-
read_addr = p.loader.memory.unpack_word(read_jmpslot.rebased_addr)
|
|
32
|
-
|
|
33
|
-
libc_sleep_addr = p.loader.shared_objects["libc.so.6"].get_symbol("sleep").rebased_addr
|
|
34
|
-
libc_rand_addr = p.loader.shared_objects["libc.so.6"].get_symbol("rand").rebased_addr
|
|
35
|
-
|
|
36
|
-
assert sleep_addr == libc_sleep_addr
|
|
37
|
-
assert rand_addr == libc_rand_addr
|
|
38
|
-
assert p.is_hooked(read_addr)
|
|
39
|
-
assert "read" in str(p._sim_procedures[read_addr])
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if __name__ == "__main__":
|
|
43
|
-
unittest.main()
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
|
|
3
|
-
__package__ = __package__ or "tests.procedures" # pylint:disable=redefined-builtin
|
|
4
|
-
|
|
5
|
-
import os
|
|
6
|
-
import unittest
|
|
7
|
-
|
|
8
|
-
import angr
|
|
9
|
-
from angr.codenode import BlockNode, HookNode, SyscallNode
|
|
10
|
-
|
|
11
|
-
from ..common import bin_location
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
test_location = os.path.join(bin_location, "tests")
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class TestSimProcedure(unittest.TestCase):
|
|
18
|
-
def test_ret_float(self):
|
|
19
|
-
class F1(angr.SimProcedure):
|
|
20
|
-
def run(self, *args, **kwargs): # pylint: disable=unused-argument
|
|
21
|
-
return 12.5
|
|
22
|
-
|
|
23
|
-
p = angr.load_shellcode(b"X", arch="i386")
|
|
24
|
-
|
|
25
|
-
p.hook(0x1000, F1(prototype="float (x)();"))
|
|
26
|
-
p.hook(0x2000, F1(prototype="double (x)();"))
|
|
27
|
-
|
|
28
|
-
s = p.factory.call_state(addr=0x1000, ret_addr=0, prototype="float(x)()")
|
|
29
|
-
succ = s.step()
|
|
30
|
-
assert len(succ.successors) == 1
|
|
31
|
-
s2 = succ.flat_successors[0]
|
|
32
|
-
assert not s2.regs.st0.symbolic
|
|
33
|
-
assert s2.solver.eval(s2.regs.st0.raw_to_fp()) == 12.5
|
|
34
|
-
|
|
35
|
-
s = p.factory.call_state(addr=0x2000, ret_addr=0, prototype="double(x)()")
|
|
36
|
-
succ = s.step()
|
|
37
|
-
assert len(succ.successors) == 1
|
|
38
|
-
s2 = succ.flat_successors[0]
|
|
39
|
-
assert not s2.regs.st0.symbolic
|
|
40
|
-
assert s2.solver.eval(s2.regs.st0.raw_to_fp()) == 12.5
|
|
41
|
-
|
|
42
|
-
p = angr.load_shellcode(b"X", arch="amd64")
|
|
43
|
-
|
|
44
|
-
p.hook(0x1000, F1(prototype="float (x)();"))
|
|
45
|
-
p.hook(0x2000, F1(prototype="double (x)();"))
|
|
46
|
-
|
|
47
|
-
s = p.factory.call_state(addr=0x1000, ret_addr=0, prototype="float(x)()")
|
|
48
|
-
succ = s.step()
|
|
49
|
-
assert len(succ.successors) == 1
|
|
50
|
-
s2 = succ.flat_successors[0]
|
|
51
|
-
res = s2.registers.load("xmm0", 4).raw_to_fp()
|
|
52
|
-
assert not res.symbolic
|
|
53
|
-
assert s2.solver.eval(res) == 12.5
|
|
54
|
-
|
|
55
|
-
s = p.factory.call_state(addr=0x2000, ret_addr=0, prototype="double(x)()")
|
|
56
|
-
succ = s.step()
|
|
57
|
-
assert len(succ.successors) == 1
|
|
58
|
-
s2 = succ.flat_successors[0]
|
|
59
|
-
res = s2.registers.load("xmm0", 8).raw_to_fp()
|
|
60
|
-
assert not res.symbolic
|
|
61
|
-
assert s2.solver.eval(res) == 12.5
|
|
62
|
-
|
|
63
|
-
def test_syscall_and_simprocedure(self):
|
|
64
|
-
bin_path = os.path.join(test_location, "cgc", "CADET_00002")
|
|
65
|
-
proj = angr.Project(bin_path, auto_load_libs=False)
|
|
66
|
-
cfg = proj.analyses.CFGFast(normalize=True)
|
|
67
|
-
|
|
68
|
-
# check syscall
|
|
69
|
-
node = cfg.get_any_node(proj.loader.kernel_object.mapped_base + 1)
|
|
70
|
-
func = proj.kb.functions[node.addr]
|
|
71
|
-
|
|
72
|
-
assert node.is_simprocedure
|
|
73
|
-
assert node.is_syscall
|
|
74
|
-
assert not node.to_codenode().is_hook
|
|
75
|
-
assert not proj.is_hooked(node.addr)
|
|
76
|
-
assert func.is_syscall
|
|
77
|
-
assert func.is_simprocedure
|
|
78
|
-
assert type(proj.factory.snippet(node.addr)) == SyscallNode
|
|
79
|
-
|
|
80
|
-
# check normal functions
|
|
81
|
-
node = cfg.get_any_node(0x80480A0)
|
|
82
|
-
func = proj.kb.functions[node.addr]
|
|
83
|
-
|
|
84
|
-
assert not node.is_simprocedure
|
|
85
|
-
assert not node.is_syscall
|
|
86
|
-
assert not proj.is_hooked(node.addr)
|
|
87
|
-
assert not func.is_syscall
|
|
88
|
-
assert not func.is_simprocedure
|
|
89
|
-
assert type(proj.factory.snippet(node.addr)) == BlockNode
|
|
90
|
-
|
|
91
|
-
# check hooked functions
|
|
92
|
-
proj.hook(0x80480A0, angr.SIM_PROCEDURES["libc"]["puts"]())
|
|
93
|
-
cfg = proj.analyses.CFGFast(normalize=True) # rebuild cfg to updated nodes
|
|
94
|
-
node = cfg.get_any_node(0x80480A0)
|
|
95
|
-
func = proj.kb.functions[node.addr]
|
|
96
|
-
|
|
97
|
-
assert node.is_simprocedure
|
|
98
|
-
assert not node.is_syscall
|
|
99
|
-
assert proj.is_hooked(node.addr)
|
|
100
|
-
assert not func.is_syscall
|
|
101
|
-
assert func.is_simprocedure
|
|
102
|
-
assert type(proj.factory.snippet(node.addr)) == HookNode
|
|
103
|
-
|
|
104
|
-
def test_inet_ntoa(self) -> None:
|
|
105
|
-
"""
|
|
106
|
-
Test the inet_ntoa simprocedure for functionality
|
|
107
|
-
"""
|
|
108
|
-
bin_path = os.path.join(test_location, "x86_64", "inet_ntoa")
|
|
109
|
-
proj = angr.Project(bin_path, auto_load_libs=False, use_sim_procedures=True)
|
|
110
|
-
initial_state = proj.factory.entry_state()
|
|
111
|
-
simgr = proj.factory.simgr(initial_state)
|
|
112
|
-
after = simgr.run()
|
|
113
|
-
assert after.deadended[0].posix.dumps(1) == b"192.168.192.168\n"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if __name__ == "__main__":
|
|
117
|
-
unittest.main()
|