Path: blob/master/lib/rex/ui/text/irb_shell.rb
19812 views
# -*- coding: binary -*-1module Rex2module Ui3module Text45###6#7# This class wraps the creation of an IRB shell.8#9###10class IrbShell1112@@IrbInitialized = false1314def initialize(binding)15@binding_ctx = binding16end1718#19# Runs the IRB shell until completion. The binding parameter initializes20# IRB to the appropriate binding context.21#22def run23# Initialize IRB by setting up its internal configuration hash and24# stuff.25if (@@IrbInitialized == false)26require 'irb'2728IRB.setup(nil)29IRB.conf[:PROMPT_MODE] = :SIMPLE3031@@IrbInitialized = true32end3334# Create a new IRB instance35irb = IRB::Irb.new(IRB::WorkSpace.new(@binding_ctx))3637# Set the primary irb context so that exit and other intrinsic38# commands will work.39IRB.conf[:MAIN_CONTEXT] = irb.context4041# Trap interrupt42begin43old_sigint = trap("SIGINT") do44irb.signal_handle45end4647# Keep processing input until the cows come home...48catch(:IRB_EXIT) do49irb.eval_input50end51ensure52trap("SIGINT", old_sigint) if old_sigint53end54end5556end57end58end59end606162