Class: Rex::Ui::Text::IrbShell

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/ui/text/irb_shell.rb

Overview

This class wraps the creation of an IRB shell.

Constant Summary collapse

@@IrbInitialized =
false

Instance Method Summary collapse

Constructor Details

#initialize(binding) ⇒ IrbShell

Returns a new instance of IrbShell.



15
16
17
# File 'lib/rex/ui/text/irb_shell.rb', line 15

def initialize(binding)
  @binding_ctx = binding
end

Instance Method Details

#runObject

Runs the IRB shell until completion. The binding parameter initializes IRB to the appropriate binding context.



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
# File 'lib/rex/ui/text/irb_shell.rb', line 23

def run
  # Initialize IRB by setting up its internal configuration hash and
  # stuff.
  if (@@IrbInitialized == false)
    require 'irb'

    IRB.setup(nil)
    IRB.conf[:PROMPT_MODE]  = :SIMPLE

    @@IrbInitialized = true
  end

  # Create a new IRB instance
  irb = IRB::Irb.new(IRB::WorkSpace.new(@binding_ctx))

  # Set the primary irb context so that exit and other intrinsic
  # commands will work.
  IRB.conf[:MAIN_CONTEXT] = irb.context

  # Trap interrupt
  begin
    old_sigint = trap("SIGINT") do
      irb.signal_handle
    end

    # Keep processing input until the cows come home...
    catch(:IRB_EXIT) do
      irb.eval_input
    end
  ensure
    trap("SIGINT", old_sigint) if old_sigint
  end
end