ExplorationTechnique

Last updated on May 24, 2023 am

About ExplorationTechnique

首先,这也是一个类。先来看看angr对这个类的说明

An technique is a set of hooks for a simulation manager that assists in the implementation of new techniques in symbolic exploration.

Any number of these methods may be overridden by a subclass. To use an exploration technique, call simgr.use_technique with an *instance* of the technique.

就是说这个technique是一系列hook的集合,可以更好帮助我们符号执行。而且这个类里面的方法都可以使用子类重写,用一个实例来调用simgr.use_technique

其实这个类就是帮我们把符号执行所必须的几个步骤给我们打包起来,然后让我们重载里面的步骤,新生成一个子类,然后按照这子类里面规定的方法去符号执行

这是整个类的定义以及相关成员函数的说明

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class ExplorationTechnique:

# 主要hook函数
_hook_list = ("step", "filter", "selector", "step_state", "successors")

# 得到被重写的hook函数
def _get_hooks(self):
return {name: getattr(self, name) for name in self._hook_list if self._is_overriden(name)}

# 判断哪些函数被重写
def _is_overriden(self, name):
return getattr(self, name).__code__ is not getattr(ExplorationTechnique, name).__code__

def __init__(self):
if not hasattr(self, "project"):
self.project: angr.project.Project = None

# 这确实就是一个空函数,专门提供给使用者来初始化自己所要的
def setup(self, simgr):


def step(self, simgr, stash="active", **kwargs):
"""
用来hook step函数,最后应该调用simgr.step以便真正执行
原本的step是往下执行一步,去到后继block
"""
simgr.step(stash=stash, **kwargs)


def filter(self, simgr, state, **kwargs):
"""
决定该state要被移去哪一个stash

如果说这个state要被filter的话,就把这个state要被移去的stash名字返回
如果想在filter之前对state做一些改变,就返回一个stash的元组,并修改state

这和step里的filter_fun起到的作用一样的
"""
return simgr.filter(state, **kwargs)


def selector(self, simgr, state, **kwargs):
"""
决定该state是否要参与进这个step round,也就是如果这个state要进入的话,就返
回True否则返回False

这个step里的selector_fun起到的作用是一样的
"""
return simgr.selector(state, **kwargs)


def step_state(self, simgr, state, **kwargs):
"""
决定该state的successor应该放去哪个块。结果应该是一个stash到successor列表的字典映射
如["active:[succ1,succ2]"]

note:该函数的优先级高于filter filter是作用于当前返回的state
"""
return simgr.step_state(state, **kwargs)


def successors(self, simgr, state, **kwargs):
"""
在进入一个state时调用,返回一个SimSuccssors对象
"""
return simgr.successors(state, **kwargs)


def complete(self, simgr):
"""
返回当前simgr是否到达 "completed" state

该方法不是hook的对象,也不应该直接调用此方法,而是应该自己决定返回True或者False
"""
return False

总结

setup 初始化

step hook步入

filter决定该state放去哪 即丢去哪

selector 决定该state是否执行

step_state 决定successors放去哪个stash

successors 在进入一个state时调用

complete 是否全部完成


ExplorationTechnique
http://example.com/2023/05/24/ExplorationTechniques/
Author
yring
Posted on
May 24, 2023
Licensed under