当前位置:   article > 正文

angr源码分析——DFG 数据流图_angr数据流分析

angr数据流分析

这篇文章主要讲述,angr中数据流图(Data Flow Gragh)的构建。

DFG恢复的是CFG中每个基本块的数据流!
DFG为CFG的每个基本块构建一个数据流图(DFG)
DFG可以通过字典self.dfgs获得,其中key的值为基本块的地址,或DFG中的值。
param CFG:用于获得所有基本块的CFG

param annocfg:一个由向后片构建的注释cfg,用于在白名单上构建DFG。

构造函数:

  1. def __init__(self, cfg=None, annocfg=None):
  2. """
  3. Build a Data Flow Grah (DFG) for every basic block of a CFG
  4. The DFGs are available in the dict self.dfgs where the key
  5. is a basic block addr and the value a DFG.
  6. :param cfg: A CFG used to get all the basic blocks
  7. :param annocfg: An AnnotatedCFG built from a backward slice used to only build the DFG on the whitelisted statements
  8. """
  9. if cfg is None:
  10. self._cfg = self.project.analyses.CFGAccurate()
  11. else:
  12. self._cfg = cfg
  13. self._annocfg = annocfg
  14. self.dfgs = self._construct()

如果没有cfg就构建cfg。

然后,调用_construct()函数构建DFG。这个函数,有点长,不过也是构造数据流的主要函数。下面开始分析吧。

  1. def _construct(self):
  2. """
  3. We want to build the type of DFG that's used in "Automated Ident. of Crypto
  4. Primitives in Binary Code with Data Flow Graph Isomorphisms." Unlike that
  5. paper, however, we're building it on Vex IR instead of assembly instructions.
  6. """
  7. cfg = self._cfg
  8. p = self.project
  9. dfgs = {}
  10. l.debug("Building Vex DFG...")
  11. for node in cfg.nodes():#遍历每个节点
  12. try:
  13. if node.simprocedure_name == None:
  14. irsb = p.factory.block(node.addr).vex #根据节点获得irsb
  15. else:
  16. l.debug("Cannot process SimProcedures, ignoring %s" % node.simprocedure_name)
  17. continue
  18. except Exception as e:
  19. l.debug(e)
  20. continue
  21. tmpsnodes = {}
  22. storesnodes = {}
  23. putsnodes = {}
  24. statements = irsb.statements #获取irsb的所有语句
  25. dfg = DiGraph()
  26. for stmt_idx, stmt in enumerate(statements):#遍历每条语句
  27. # We want to skip over certain types, such as Imarks
  28. if self._need_to_ignore(node.addr, stmt, stmt_idx):
  29. continue
  30. # break statement down into sub-expressions
  31. exprs = stmt.expressions #获得语句的子表达式
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/331243
推荐阅读
相关标签
  

闽ICP备14008679号