CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/script.rb
Views: 11766
1
# -*- coding: binary -*-
2
3
module Rex
4
5
###
6
#
7
# This class provides an easy interface for loading and executing ruby
8
# scripts.
9
#
10
###
11
module Script
12
13
class Completed < ::RuntimeError
14
end
15
16
#
17
# Reads the contents of the supplied file and exeutes them.
18
#
19
def self.execute_file(file, in_binding = nil)
20
str = ''
21
buf = ::File.read(file, ::File.size(file), mode: 'rb')
22
execute(buf, in_binding)
23
end
24
25
#
26
# Executes arbitrary ruby from the supplied string.
27
#
28
def self.execute(str, in_binding = nil)
29
begin
30
eval(str, in_binding)
31
rescue Completed
32
end
33
end
34
35
end
36
37
end
38
39