Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/ui/text/irb_shell.rb
19812 views
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
begin
44
old_sigint = trap("SIGINT") do
45
irb.signal_handle
46
end
47
48
# Keep processing input until the cows come home...
49
catch(:IRB_EXIT) do
50
irb.eval_input
51
end
52
ensure
53
trap("SIGINT", old_sigint) if old_sigint
54
end
55
end
56
57
end
58
end
59
end
60
end
61
62