Class: Ronin::Core::CLI::RubyShell

Inherits:
Object
  • Object
show all
Includes:
CommandKit::Colors
Defined in:
lib/ronin/core/cli/ruby_shell.rb

Overview

Starts a customized Interactive Ruby console.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: 'ronin', context: nil, **kwargs) ⇒ RubyShell

Initializes the console.

Parameters:

  • name (String) (defaults to: 'ronin')

    The name of the IRB console.

  • context (Object, Module) (defaults to: nil)

    Custom context to launch IRB from within.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for initialize.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ronin/core/cli/ruby_shell.rb', line 57

def initialize(name: 'ronin', context: nil, **kwargs)
  super(**kwargs)

  @name    = name
  @context = case context
             when Module
               Object.new.tap do |obj|
                 obj.singleton_class.include(context)
                 obj.singleton_class.define_singleton_method(:const_missing,&context.method(:const_missing))
                 obj.define_singleton_method(:inspect) do
                   "#<#{context}>"
                 end
               end
             else
               context
             end
end

Instance Attribute Details

#contextObject? (readonly)

The optional context to spawn the console inside of.

Returns:

  • (Object, nil)


43
44
45
# File 'lib/ronin/core/cli/ruby_shell.rb', line 43

def context
  @context
end

#nameString (readonly)

The console name.

Returns:

  • (String)


38
39
40
# File 'lib/ronin/core/cli/ruby_shell.rb', line 38

def name
  @name
end

Class Method Details

.start(**kwargs) ⇒ Object

Starts a customized irb console.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #initialize.

Options Hash (**kwargs):

  • :name (String)

    The name of the IRB console.

  • :context (Object)

    Custom context to launch IRB from within.



88
89
90
# File 'lib/ronin/core/cli/ruby_shell.rb', line 88

def self.start(**kwargs)
  new(**kwargs).start
end

Instance Method Details

#configureObject

Configures IRB.



95
96
97
98
99
100
# File 'lib/ronin/core/cli/ruby_shell.rb', line 95

def configure
  IRB.setup(nil, argv: [])
  IRB.conf[:IRB_NAME] = @name

  set_prompt
end

#startObject

Starts a customized irb console.



106
107
108
109
110
111
112
113
114
115
# File 'lib/ronin/core/cli/ruby_shell.rb', line 106

def start
  configure

  workspace = if @context then IRB::WorkSpace.new(@context)
              else             IRB::WorkSpace.new
              end

  irb = IRB::Irb.new(workspace)
  irb.run
end