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

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

Overview

Starts a customized Interactive Ruby console.

Constant Summary

Constants included from Banner

Banner::BANNER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Banner

#print_banner

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.



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

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)


45
46
47
# File 'lib/ronin/core/cli/ruby_shell.rb', line 45

def context
  @context
end

#nameString (readonly)

The console name.

Returns:

  • (String)


40
41
42
# File 'lib/ronin/core/cli/ruby_shell.rb', line 40

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.



90
91
92
# File 'lib/ronin/core/cli/ruby_shell.rb', line 90

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

Instance Method Details

#configureObject

Configures IRB.



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

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

  set_prompt
end

#startObject

Starts a customized irb console.



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ronin/core/cli/ruby_shell.rb', line 108

def start
  print_banner if STDOUT.tty?

  configure

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

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