【angr源码分析】2. Block

angr\block.py

Block类

factory中的block方法返回了Block的对象

class Block(object):

def _init_():

参数也没有注释,心累。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def __init__(self, 
addr,
project=None,
arch=None,
size=None,
byte_string=None, #之前编译了什么东西,然后传进来
vex=None, #该block的中间语言,没有设置的话就用engine生成
thumb=False, #是否是ARM的thumb指令集
backup_state=None,
opt_level=None,
num_inst=None, #number of instructions
traceflags=0,
strict_block_end=None):

# set up arch
if project is not None:
self.arch = project.arch
else:
self.arch = arch

.... ....

self._project = project
self.thumb = thumb
self.addr = addr
self._opt_level = opt_level

#byte_string和project不能同时为空。目前还不清楚byte_string的用途
if self._project is None and byte_string is None:
raise ValueError('"byte_string" has to be specified if "project" is not provided.')

if size is None:
if byte_string is not None:
size = len(byte_string)
elif vex is not None:
size = vex.size
else:
#lift方法用于获取中间语言(具体功能未知)
#_vex_engine实际上调用了factory.default_engine
vex = self._vex_engine.lift(
clemory=project.loader.memory,
state=backup_state,
insn_bytes=byte_string,
addr=addr,
thumb=thumb,
opt_level=opt_level,
num_inst=num_inst,
traceflags=traceflags,
strict_block_end=strict_block_end)
size = vex.size

可以看到,调用了vex = self._vex_engine.lift(... ...) 。在engine中,_vex_engine实际上是factory.default_engine,而default_engine在 ‘default’ preset中使用的实际上是 SimEngineVEX的对象。所以调用的lift方法实际上是SimEngineVEX.lift ,返回一个IRSB对象。