当前位置: 首页 > news >正文

静态分析2:控制流分析(构建CFG)

参考:南京大学《软件分析》课程2

1、控制流分析

  • 控制流分析实际上指的是构建控制流图(Control Flow Graph,CFG)
  • CFG是静态分析的基础数据结构
  • CFG的节点可以是单个指令、基本块(Basic Block,BB)

2、构建基本块(Basic Block,BB)

(1)基本块的概念

Basic blocks (BB) are maximal sequences of consecutive three-address instructions with the properties that

  • It can be entered only at the beginning, i.e., the first instruction in the block
  • It can be exited only at the end, i.e., the last instruction in the block

解释:

基本块是具有以下属性的连续3AC指令的最大序列:

  • 只有一个入口,仅在开头进入,即块的第一条指令。
  • 只有一个出口,仅在结尾退出,即块的最后一条指令。
(2)构建基本块

INPUT: A sequence of three-address instructions of P
OUTPUT: A list of basic blocks of P
METHOD:
(1) Determine the leaders in P
• The first instruction in P is a leader
• Any target instruction of a conditional or
unconditional jump is a leader
• Any instruction that immediately follows a
conditional or unconditional jump is a leader
(2) Build BBs for P
• A BB consists of a leader and all its subsequent
instructions until the next leader

解释:

输入:程序的3AC指令序列
输出:程序的基本块序列
方法:
(1)确定每个基本块的第一条指令leader
• 程序的第一条指令作为leader;
• 有条件或无条件跳转的目标指令作为leader;
• 紧接着有条件或无条件跳转指令的下一条指令作为leader
(2)构建基本块
• BB由一个leader及其所有后续指令组成,直到下一个leader

例子:
在这里插入图片描述

3、构建控制流图(Control Flow Graph ,CFG)

• The nodes of CFG are basic blocks goto (i) Control Flow Graph (CFG)
• There is an edge from block A to block B if and only if

  • There is a conditional or unconditional jump from the end of A to the beginning of B
  • B immediately follows A in the original order of instructions and A does not end in an unconditional jump

• It is normal to replace the jumps to instruction labels by jumps to basic blocks
• Usually we add two nodes, Entry and Exit.

  • They do not correspond to executable IR
  • An edge from Entry to the BB containing the first instruction of IR
  • An edge to Exit from any BB containing an instruction that could be the last instruction of IR

解释:

• 控制流图的节点是基本块
• 基本块之间的边

  • 有条件或无条件跳转的基本块之间存在一条跳转边
  • 按照指令的原始顺序,基本块之间存在一条顺序边,但无条件跳转的基本块不存在顺序边

• 将跳转到指令替换成跳转到基本块
• 添加entry和exit

  • CFG和IR通常不对应
  • Entry到BB的边,包括IR的第一条指令
  • BB到Exit的边(可能是多条),包括IR的最后一条指令

在这里插入图片描述

http://www.lryc.cn/news/471338.html

相关文章:

  • Linux 应用领域
  • FPM383C指纹模块超详解 附驱动
  • 若依框架篇-若依集成 X-File-Storage 框架(实现图片上传阿里云 OSS 服务器)、EasyExcel 框架(实现 Excel 数据批量导入功能)
  • .rmallox勒索病毒肆虐:如何有效防范与应对
  • 人工智能能否影响未来生活:一场深刻的社会与技术变革
  • cmu 15-445学习笔记-3 存储引擎
  • [linux]和windows间传输命令scp 执行WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!错误解决
  • C++ | Leetcode C++题解之第518题零钱兑换II
  • 高并发-负载均衡
  • Docker 常用命令全解析:提升对雷池社区版的使用经验
  • 基于 Postman 和 Elasticsearch 测试乐观锁的操作流程
  • 如何从PPT中导出600dpi的高清图
  • day01-ElasticStack+Kibana
  • HTML 约束验证
  • vue3项目开发一些必备的内容,该安装安装,该创建创建
  • 2D拓扑图
  • 大数据面试题整理——Hive
  • Python实现图像(边缘)锐化:梯度锐化、Roberts 算子、Laplace算子、Sobel算子的详细方法
  • 【电机控制】相电流重构——单电阻采样方案
  • #基础算法
  • 如何用猿大师办公助手实现OA系统中Word公文/合同在线编辑及流转?
  • Python中的列表是什么?它们有什么用途?
  • 探索现代软件开发中的持续集成与持续交付(CI/CD)实践
  • React 前端框架开发入门案例
  • 模拟 DDoS 攻击与防御实验
  • 【electron8】electron实现“图片”的另存为
  • Python分析假期对美国出生率的影响
  • 机械臂笛卡尔空间轨迹规划
  • 红队工具---Behinder学习
  • k8s 1.28.2 集群部署 NFS server 和 NFS Subdir External Provisioner