
explore的find和avoid支持函数作为参数,根据函数返回值来判断是否成功。Angr把状态传入了函数,从而判断成功与否。
import angr
import sysdef main(argv):path_to_binary = argv[1]project = angr.Project(path_to_binary)initial_state = project.factory.entry_state()simulation = project.factory.simgr(initial_state)# 定义一个函数,根据状态来判断输出是否成功def is_successful(state):stdout_output = state.posix.dumps(sys.stdout.fileno())# 正确是输出是'Good Job.'return b'Good Job.' in stdout_output# 类似上面的函数,这个函数用来检测是否要忽略。如果有输出"Try again.",则跳过。def should_abort(state):stdout_output = state.posix.dumps(sys.stdout.fileno())return b"Try again." in stdout_output # 把find和avoid参数改为函数名,来根据状态来搜索过滤。simulation.explore(find=is_successful, avoid=should_abort)if simulation.found:solution_state = simulation.found[0]print solution_state.posix.dumps(sys.stdin.fileno())else:raise Exception('Could not find the solution')if __name__ == '__main__':main(sys.argv)

参考:https://angr.io/api-doc/angr.html#angr.exploration_techniques.explorer.Explorer

















