angr/tests/analyses/test_callsite_maker.py

61 lines
2 KiB
Python
Executable file

#!/usr/bin/env python3
from __future__ import annotations
__package__ = __package__ or "tests.analyses" # pylint:disable=redefined-builtin
import os
import unittest
import angr
from angr import ailment
from angr.analyses.decompiler.block_simplifier import BlockSimplifier
from angr.analyses.decompiler.callsite_maker import CallSiteMaker
from tests.common import bin_location
test_location = os.path.join(bin_location, "tests")
# pylint: disable=missing-class-docstring
# pylint: disable=no-self-use
class TestCallsiteMaker(unittest.TestCase):
def test_callsite_maker(self):
project = angr.Project(
os.path.join(test_location, "x86_64", "all"),
auto_load_libs=False,
)
manager = ailment.Manager(arch=project.arch)
# Generate a CFG
cfg = project.analyses.CFG()
new_cc_found = True
while new_cc_found:
new_cc_found = False
for func in cfg.kb.functions.values():
if func.calling_convention is None:
# determine the calling convention of each function
project.analyses.VariableRecoveryFast(func)
cc_analysis = project.analyses.CallingConvention(func)
if cc_analysis.cc is not None:
func.calling_convention = cc_analysis.cc
func.prototype = cc_analysis.prototype
new_cc_found = True
main_func = cfg.kb.functions["main"]
for block in sorted(main_func.blocks, key=lambda x: x.addr):
print(block.vex.pp())
ail_block = ailment.IRSBConverter.convert(block.vex, manager)
simp = BlockSimplifier(project, ail_block, manager, main_func.addr)
csm = CallSiteMaker(project, simp.result_block, ail_manager=manager)
if csm.result_block:
ail_block = csm.result_block
simp = BlockSimplifier(project, ail_block, manager, main_func.addr)
print(simp.result_block)
if __name__ == "__main__":
unittest.main()