Files
metasploit-gs/lib/rex/ui/text/irb_shell.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.1 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2005-12-06 04:39:14 +00:00
module Rex
module Ui
module Text
###
#
# This class wraps the creation of an IRB shell.
#
###
class IrbShell
@@IrbInitialized = false
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
def initialize(binding)
@binding_ctx = binding
end
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
#
# Runs the IRB shell until completion. The binding parameter initializes
# IRB to the appropriate binding context.
#
def run
# Initialize IRB by setting up its internal configuration hash and
# stuff.
if (@@IrbInitialized == false)
2021-03-25 20:08:07 +00:00
require 'irb'
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
IRB.setup(nil)
IRB.conf[:PROMPT_MODE] = :SIMPLE
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
@@IrbInitialized = true
end
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
# Create a new IRB instance
irb = IRB::Irb.new(IRB::WorkSpace.new(@binding_ctx))
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
# Set the primary irb context so that exit and other intrinsic
# commands will work.
IRB.conf[:MAIN_CONTEXT] = irb.context
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
# Trap interrupt
old_sigint = trap("SIGINT") do
begin
irb.signal_handle
rescue RubyLex::TerminateLineInput
2013-01-13 13:24:48 -06:00
irb.eval_input
end
2005-12-06 04:39:14 +00:00
end
2013-08-30 16:28:33 -05:00
2005-12-06 04:39:14 +00:00
# Keep processing input until the cows come home...
catch(:IRB_EXIT) do
irb.eval_input
end
2013-08-30 16:28:33 -05:00
trap("SIGINT", old_sigint)
2005-12-06 04:39:14 +00:00
end
end
end
end
end