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/ui/text/irb_shell.rb
Views: 11655
1
# -*- coding: binary -*-
2
module Rex
3
module Ui
4
module Text
5
6
###
7
#
8
# This class wraps the creation of an IRB shell.
9
#
10
###
11
class IrbShell
12
13
@@IrbInitialized = false
14
15
def initialize(binding)
16
@binding_ctx = binding
17
end
18
19
#
20
# Runs the IRB shell until completion. The binding parameter initializes
21
# IRB to the appropriate binding context.
22
#
23
def run
24
# Initialize IRB by setting up its internal configuration hash and
25
# stuff.
26
if (@@IrbInitialized == false)
27
require 'irb'
28
29
IRB.setup(nil)
30
IRB.conf[:PROMPT_MODE] = :SIMPLE
31
32
@@IrbInitialized = true
33
end
34
35
# Create a new IRB instance
36
irb = IRB::Irb.new(IRB::WorkSpace.new(@binding_ctx))
37
38
# Set the primary irb context so that exit and other intrinsic
39
# commands will work.
40
IRB.conf[:MAIN_CONTEXT] = irb.context
41
42
# Trap interrupt
43
old_sigint = trap("SIGINT") do
44
begin
45
irb.signal_handle
46
rescue RubyLex::TerminateLineInput
47
irb.eval_input
48
end
49
end
50
51
# Keep processing input until the cows come home...
52
catch(:IRB_EXIT) do
53
irb.eval_input
54
end
55
56
trap("SIGINT", old_sigint)
57
end
58
59
end
60
end
61
end
62
end
63
64