def test_init_the_call_stack_with_another_block_as_subject_does_not_deepen_the_call_stack(self): binary_path = _binary_path('all') project = angr.Project(binary_path, load_options={'auto_load_libs': False}) cfg = project.analyses.CFGFast() _start = cfg.kb.functions['_start'] __libc_start_main = cfg.kb.functions['__libc_start_main'] initial_call_stack = [ _start.addr, __libc_start_main.addr ] main_function = cfg.kb.functions['main'] main_address = main_function.addr main_block = Block(addr=main_address, project=project) another_block_in_main = Block(addr=0x4006fd, project=project) new_call_stack = project.analyses.ReachingDefinitions( subject=main_block, call_stack=initial_call_stack )._call_stack reaching_definitions = project.analyses.ReachingDefinitions( subject=another_block_in_main, call_stack=new_call_stack ) expected_call_stack = initial_call_stack + [ main_function.addr ] self.assertEqual(reaching_definitions._call_stack, expected_call_stack)
def test_insn_observe_after_a_pyvex_statement(self): # Create several different observation points observation_points = [('node', 0x42, OP_AFTER), ('insn', 0x43, OP_AFTER)] project, main_function, reaching_definition, state =\ InsnAndNodeObserveTestingUtils.setup(observation_points) code_block = main_function._addr_to_block_node[main_function.addr] # pylint: disable=W0212 block = Block(addr=0x43, byte_string=code_block.bytestr, project=project) # When observing OP_AFTER an instruction, the statement has to be the last of a block # (or preceding an IMark) statement = block.vex.statements[-1] reaching_definition.insn_observe(0x43, statement, block, state, OP_AFTER) results = InsnAndNodeObserveTestingUtils.filter( reaching_definition.observed_results, observation_points) expected_results = [state] nose.tools.assert_greater(len(results), 0) list( map( lambda x: InsnAndNodeObserveTestingUtils. assert_equals_for_live_definitions(x[0], x[1]), zip(results, expected_results)))
def test_func_graph_attribute_should_raise_error_when_subject_is_a_block(): arch = ArchX86() block = Block(0x42, byte_string=b'', arch=arch) subject = Subject(block, None) with nose.tools.assert_raises(TypeError): _ = subject.func_graph
def test_can_be_instantiated_with_a_block(_): arch = ArchX86() block = Block(0x42, byte_string=b'', arch=arch) subject = Subject(block, None) nose.tools.assert_equals(subject.content, block) nose.tools.assert_equals(subject.type, SubjectType.Block)
def test_func_graph_attribute_should_raise_error_when_subject_is_a_block( self): arch = ArchX86() block = Block(0x42, byte_string=b'', arch=arch) subject = Subject(block) with self.assertRaises(TypeError): _ = subject.func_graph
def test_can_be_instantiated_with_a_block(self, _): arch = ArchX86() block = Block(0x42, byte_string=b'', arch=arch) subject = Subject(block) assert subject.content == block assert subject.type == SubjectType.Block
def test_insn_observe_before_an_imark_pyvex_statement(self): # Create several different observation points observation_points = [('node', 0x42, OP_AFTER), ('insn', 0x43, OP_BEFORE)] project, main_function, reaching_definition, state =\ InsnAndNodeObserveTestingUtils.setup(observation_points) code_block = main_function._addr_to_block_node[main_function.addr] # pylint: disable=W0212 block = Block(addr=0x43, byte_string=code_block.bytestr, project=project) statement = block.vex.statements[0] reaching_definition.insn_observe(0x43, statement, block, state, OP_BEFORE) results = InsnAndNodeObserveTestingUtils.filter( reaching_definition.observed_results, observation_points) expected_results = [state.live_definitions] self.assertGreater(len(results), 0) list( map( lambda x: InsnAndNodeObserveTestingUtils. assert_for_live_definitions(self.assertEqual, x[0], x[1]), zip(results, expected_results)))
def test_reaching_definition_analysis_with_a_block_as_suject(self): binary_path = os.path.join(TESTS_LOCATION, 'x86_64', 'all') project = angr.Project(binary_path, load_options={'auto_load_libs': False}) cfg = project.analyses.CFGFast() main_function = cfg.kb.functions['main'] block_node = main_function._addr_to_block_node[main_function.addr] # pylint: disable=W0212 main_block = Block(addr=0x42, byte_string=block_node.bytestr, project=project) reaching_definitions = project.analyses.ReachingDefinitions(subject=main_block) nose.tools.assert_equal(reaching_definitions._function, None) nose.tools.assert_equal(reaching_definitions._block, main_block) nose.tools.assert_equal(reaching_definitions._init_func, False) nose.tools.assert_equal(reaching_definitions._cc, None)
def test_init_the_call_stack_with_a_block_as_subject_add_its_owning_function_to_the_call_stack(self): binary_path = _binary_path('all') project = angr.Project(binary_path, load_options={'auto_load_libs': False}) cfg = project.analyses.CFGFast() _start = cfg.kb.functions['_start'] __libc_start_main = cfg.kb.functions['__libc_start_main'] call_stack = [ _start.addr, __libc_start_main.addr ] main_function = cfg.kb.functions['main'] main_address = main_function.addr main_block = Block(addr=main_address, project=project) reaching_definitions = project.analyses.ReachingDefinitions(subject=main_block, call_stack=call_stack) expected_call_stack = call_stack + [ main_function.addr ] self.assertEqual(reaching_definitions._call_stack, expected_call_stack)