ronin 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +17 -6
  3. data/README.txt +3 -2
  4. data/Rakefile +1 -0
  5. data/bin/ronin-add +12 -0
  6. data/bin/ronin-console +12 -0
  7. data/bin/ronin-ext +12 -0
  8. data/bin/ronin-help +12 -0
  9. data/bin/ronin-install +12 -0
  10. data/bin/ronin-ls +12 -0
  11. data/bin/ronin-overlay +12 -0
  12. data/bin/ronin-rm +12 -0
  13. data/bin/ronin-uninstall +12 -0
  14. data/bin/ronin-update +12 -0
  15. data/lib/ronin/extensions/string.rb +5 -3
  16. data/lib/ronin/platform/extension.rb +8 -2
  17. data/lib/ronin/platform/overlay.rb +16 -32
  18. data/lib/ronin/ui.rb +1 -1
  19. data/lib/ronin/ui/command_line.rb +1 -1
  20. data/lib/ronin/ui/command_line/command.rb +42 -60
  21. data/lib/ronin/ui/command_line/command_line.rb +28 -50
  22. data/lib/ronin/ui/command_line/commands/add.rb +41 -40
  23. data/lib/ronin/ui/command_line/commands/{default.rb → console.rb} +28 -21
  24. data/lib/ronin/ui/command_line/commands/{extension.rb → ext.rb} +25 -27
  25. data/lib/ronin/ui/command_line/commands/help.rb +26 -28
  26. data/lib/ronin/ui/command_line/commands/install.rb +32 -32
  27. data/lib/ronin/ui/command_line/commands/ls.rb +123 -0
  28. data/lib/ronin/ui/command_line/commands/overlay.rb +115 -114
  29. data/lib/ronin/ui/command_line/commands/{remove.rb → rm.rb} +27 -29
  30. data/lib/ronin/ui/command_line/commands/uninstall.rb +27 -29
  31. data/lib/ronin/ui/command_line/commands/update.rb +28 -30
  32. data/lib/ronin/ui/command_line/options.rb +0 -12
  33. data/lib/ronin/ui/command_line/param_parser.rb +34 -14
  34. data/lib/ronin/ui/console.rb +1 -0
  35. data/lib/ronin/ui/diagnostics.rb +5 -19
  36. data/lib/ronin/ui/{command_line/commands.rb → verbose.rb} +19 -11
  37. data/lib/ronin/version.rb +1 -1
  38. data/spec/arch_spec.rb +24 -24
  39. data/spec/chars/chars_spec.rb +49 -13
  40. data/spec/extensions/string_spec.rb +6 -6
  41. data/spec/spec_helper.rb +1 -1
  42. data/spec/ui/command_line/helpers/example_command.rb +21 -0
  43. data/spec/ui/command_line/param_parser_spec.rb +9 -18
  44. data/spec/ui/verbose_spec.rb +17 -0
  45. metadata +39 -8
  46. data/lib/ronin/ui/command_line/commands/list.rb +0 -122
  47. data/spec/ui/diagnostics_spec.rb +0 -17
@@ -21,10 +21,11 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/ui/command_line/commands/default'
25
24
  require 'ronin/ui/command_line/exceptions/unknown_command'
25
+ require 'ronin/ui/command_line/commands/console'
26
26
  require 'ronin/ui/console'
27
- require 'ronin/version'
27
+
28
+ require 'reverse_require'
28
29
 
29
30
  module Ronin
30
31
  module UI
@@ -33,15 +34,20 @@ module Ronin
33
34
  # Returns the commands registered with the command-line utility.
34
35
  #
35
36
  def CommandLine.commands
36
- @@ronin_commands ||= []
37
- end
37
+ unless class_variable_defined?('@@ronin_commands')
38
+ paths = Gem.find_resources('bin/ronin-*')
39
+
40
+ @@ronin_commands = {}
41
+
42
+ paths.each do |path|
43
+ next unless File.executable?(path)
44
+ name = File.basename(path).gsub(/^ronin-/,'')
38
45
 
39
- #
40
- # Returns the Hash of the Command names and their Command objects
41
- # registered with the command-line utility.
42
- #
43
- def CommandLine.commands_by_name
44
- @@ronin_commands_by_name ||= {}
46
+ @@ronin_commands[name] ||= path
47
+ end
48
+ end
49
+
50
+ return @@ronin_commands
45
51
  end
46
52
 
47
53
  #
@@ -49,7 +55,7 @@ module Ronin
49
55
  # registered with the command-line utility.
50
56
  #
51
57
  def CommandLine.has_command?(name)
52
- CommandLine.commands_by_name.has_key?(name.to_s)
58
+ CommandLine.commands.has_key?(name.to_s)
53
59
  end
54
60
 
55
61
  #
@@ -63,27 +69,7 @@ module Ronin
63
69
  raise(UnknownCommand,"unknown command #{name.dump}",caller)
64
70
  end
65
71
 
66
- return CommandLine.commands_by_name[name]
67
- end
68
-
69
- #
70
- # Prints the specified error _message_.
71
- #
72
- def CommandLine.error(message)
73
- STDERR.puts "ronin: #{message}"
74
- return false
75
- end
76
-
77
- #
78
- # Prints the given error _message_ and exits unseccessfully from the
79
- # command-line utility. If a _block_ is given, it will be called before
80
- # any error _message_ are printed.
81
- #
82
- def CommandLine.fail(message,&block)
83
- block.call(self) if block
84
-
85
- CommandLine.error(message)
86
- exit -1
72
+ return CommandLine.commands[name]
87
73
  end
88
74
 
89
75
  #
@@ -92,26 +78,18 @@ module Ronin
92
78
  # attempt to find and execute the Command with the same name.
93
79
  #
94
80
  def CommandLine.run(*argv)
95
- begin
96
- if (argv.empty? || argv[0][0..0]=='-')
97
- DefaultCommand.run(*argv)
98
- else
99
- cmd = argv.first
100
- argv = argv[1..-1]
81
+ if (argv.empty? || argv[0][0..0]=='-')
82
+ Commands::Console.run(*argv)
83
+ else
84
+ cmd = argv.first
85
+ argv = argv[1..-1]
101
86
 
102
- if CommandLine.has_command?(cmd)
103
- begin
104
- CommandLine.commands_by_name[cmd].run(*argv)
105
- rescue => excp
106
- STDERR.puts excp
107
- exit -1
108
- end
109
- else
110
- CommandLine.fail("unknown command #{cmd.dump}")
111
- end
87
+ begin
88
+ exec(CommandLine.get_command(cmd),*argv)
89
+ rescue UnknownCommand => e
90
+ STDERR.puts e
91
+ exit -1
112
92
  end
113
- rescue OptionParser::MissingArgument, OptionParser::InvalidOption => e
114
- CommandLine.fail(e)
115
93
  end
116
94
 
117
95
  return true
@@ -27,63 +27,64 @@ require 'ronin/platform/overlay'
27
27
  module Ronin
28
28
  module UI
29
29
  module CommandLine
30
- class AddCommand < Command
30
+ module Commands
31
+ class Add < Command
31
32
 
32
- command :add
33
+ def defaults
34
+ @cache = nil
35
+ @media = nil
36
+ @uri = nil
37
+ end
33
38
 
34
- def initialize
35
- @cache = nil
36
- @media = nil
37
- @uri = nil
39
+ def define_options(opts)
40
+ opts.usage = 'PATH [options]'
38
41
 
39
- super
40
- end
42
+ opts.options do
43
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
44
+ @cache = dir
45
+ end
41
46
 
42
- def define_options(opts)
43
- opts.usage = 'PATH [options]'
47
+ opts.on('-m','--media MEDIA','Spedify the media-type of the overlay') do |media|
48
+ @media = media
49
+ end
44
50
 
45
- opts.options do
46
- opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
47
- @cache = dir
48
- end
51
+ opts.on('-U','--uri URI','Specify the source URI of the overlay') do |uri|
52
+ @uri = uri
53
+ end
49
54
 
50
- opts.on('-m','--media MEDIA','Spedify the media-type of the overlay') do |media|
51
- @media = media
55
+ opts.on('-L','--local','Similiar to: --media local') do
56
+ @media = :local
57
+ end
52
58
  end
53
59
 
54
- opts.on('-U','--uri URI','Specify the source URI of the overlay') do |uri|
55
- @uri = uri
56
- end
60
+ opts.arguments(
61
+ 'PATH' => 'Add the overlay located at the specified PATH'
62
+ )
57
63
 
58
- opts.on('-L','--local','Similiar to: --media local') do
59
- @media = :local
60
- end
64
+ opts.summary %{
65
+ Add a local overlay located at the specified PATH to the
66
+ Overlay cache
67
+ }
61
68
  end
62
69
 
63
- opts.arguments(
64
- 'PATH' => 'Add the overlay located at the specified PATH'
65
- )
66
-
67
- opts.summary('Add a local overlay located at the specified PATH to the Overlay cache')
68
- end
69
-
70
- def arguments(*args)
71
- unless args.length == 1
72
- fail('only one overlay path maybe specified')
73
- end
70
+ def arguments(*args)
71
+ unless args.length == 1
72
+ fail('only one overlay path maybe specified')
73
+ end
74
74
 
75
- Platform.load_overlays(@cache) if @cache
75
+ Platform.load_overlays(@cache) if @cache
76
76
 
77
- overlay_options = {:path => path.first}
77
+ overlay_options = {:path => args.first}
78
78
 
79
- overlay_options[:media] = @media if @media
80
- overlay_options[:uri] = @uri if @uri
79
+ overlay_options[:media] = @media if @media
80
+ overlay_options[:uri] = @uri if @uri
81
81
 
82
- Platform.add(overlay_options) do |overlay|
83
- puts "Overlay #{overlay.name.dump} added."
82
+ Platform.add(overlay_options) do |overlay|
83
+ puts "Overlay #{overlay.name.dump} added."
84
+ end
84
85
  end
85
- end
86
86
 
87
+ end
87
88
  end
88
89
  end
89
90
  end
@@ -22,42 +22,49 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
+ require 'ronin/ui/verbose'
25
26
  require 'ronin/ui/console'
26
27
  require 'ronin/database'
27
28
 
28
29
  module Ronin
29
30
  module UI
30
31
  module CommandLine
31
- class DefaultCommand < Command
32
+ module Commands
33
+ class Console < Command
32
34
 
33
- def define_options(opts)
34
- opts.usage = '<command> [options]'
35
- opts.options do
36
- opts.on('-d','--database URI','The URI for the Database') do |uri|
37
- Database.config = uri.to_s
38
- end
35
+ def define_options(opts)
36
+ opts.usage = '<command> [options]'
37
+ opts.options do
38
+ opts.on('-D','--database URI','The URI for the Database') do |uri|
39
+ Database.config = uri.to_s
40
+ end
39
41
 
40
- opts.on('-r','--require LIB','require the specified library or path') do |lib|
41
- Console.auto_load << lib.to_s
42
- end
42
+ opts.on('-r','--require LIB','Require the specified library or path') do |lib|
43
+ UI::Console.auto_load << lib.to_s
44
+ end
45
+
46
+ opts.on('-v','--verbose','Enables verbose output') do
47
+ UI::Verbose.enable!
48
+ end
43
49
 
44
- opts.on('-V','--version','print version information and exit') do
45
- CommandLine.success do
46
- puts "Ronin #{Ronin::VERSION}"
50
+ opts.on('-V','--version','Print version information and exit') do
51
+ success do
52
+ puts "Ronin #{Ronin::VERSION}"
53
+ end
47
54
  end
48
55
  end
56
+
57
+ opts.summary %{
58
+ Ronin is a Ruby development platform designed for information
59
+ security and data exploration tasks.
60
+ }
49
61
  end
50
62
 
51
- opts.summary %{
52
- Ronin is a Ruby development platform designed for information security
53
- and data exploration tasks.
54
- }
55
- end
63
+ def arguments(*args)
64
+ UI::Console.start
65
+ end
56
66
 
57
- def arguments(*args)
58
- Console.start
59
67
  end
60
-
61
68
  end
62
69
  end
63
70
  end
@@ -31,41 +31,39 @@ require 'erb'
31
31
  module Ronin
32
32
  module UI
33
33
  module CommandLine
34
- class ExtensionCommand < Command
34
+ module Commands
35
+ class Ext < Command
35
36
 
36
- command :extension, :ext
37
-
38
- def initialize
39
- @uses = []
40
-
41
- super
42
- end
37
+ def defaults
38
+ @uses = []
39
+ end
43
40
 
44
- def define_options(opts)
45
- opts.usage = 'PATH [...]'
41
+ def define_options(opts)
42
+ opts.usage = 'PATH [...]'
46
43
 
47
- opts.arguments(
48
- 'PATH' => 'The PATH of the Extension to be created'
49
- )
44
+ opts.arguments(
45
+ 'PATH' => 'The PATH of the Extension to be created'
46
+ )
50
47
 
51
- opts.summary('Create an empty Extension at the specified PATH')
52
- end
48
+ opts.summary('Create an empty Extension at the specified PATH')
49
+ end
53
50
 
54
- def arguments(*args)
55
- args.each do |path|
56
- path = File.expand_path(path)
57
- extension_path = File.join(path,Platform::Extension::EXTENSION_FILE)
58
- lib_dir = File.join(path,Platform::Extension::LIB_DIR)
59
- template_path = File.join(Config::STATIC_DIR,'extension.rb')
51
+ def arguments(*args)
52
+ args.each do |path|
53
+ path = File.expand_path(path)
54
+ extension_path = File.join(path,Platform::Extension::EXTENSION_FILE)
55
+ lib_dir = File.join(path,Platform::Extension::LIB_DIR)
56
+ template_path = File.join(Config::STATIC_DIR,'extension.rb')
60
57
 
61
- FileUtils.mkdir_p(path)
62
- FileUtils.mkdir_p(lib_dir)
63
- FileUtils.touch(File.join(lib_dir,File.basename(path) + '.rb'))
64
- FileUtils.mkdir_p(File.join(lib_dir,File.basename(path)))
65
- FileUtils.cp(template_path,extension_path)
58
+ FileUtils.mkdir_p(path)
59
+ FileUtils.mkdir_p(lib_dir)
60
+ FileUtils.touch(File.join(lib_dir,File.basename(path) + '.rb'))
61
+ FileUtils.mkdir_p(File.join(lib_dir,File.basename(path)))
62
+ FileUtils.cp(template_path,extension_path)
63
+ end
66
64
  end
67
- end
68
65
 
66
+ end
69
67
  end
70
68
  end
71
69
  end
@@ -22,48 +22,46 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
+ require 'ronin/ui/command_line/command_line'
25
26
 
26
27
  module Ronin
27
28
  module UI
28
29
  module CommandLine
29
- class HelpCommand < Command
30
+ module Commands
31
+ class Help < Command
30
32
 
31
- command :help
33
+ def define_options(opts)
34
+ opts.usage = '[COMMAND]'
32
35
 
33
- def define_options(opts)
34
- opts.usage = '[COMMAND]'
36
+ opts.arguments(
37
+ 'COMMAND' => 'The command to view'
38
+ )
35
39
 
36
- opts.arguments(
37
- 'COMMAND' => 'The command to view'
38
- )
40
+ opts.summary %{
41
+ View a list of supported commands or information on a
42
+ specific command
43
+ }
44
+ end
39
45
 
40
- opts.summary('View a list of supported commands or information on a specific command')
41
- end
46
+ def arguments(*args)
47
+ if args.length > 1
48
+ fail('only one command maybe specified')
49
+ end
42
50
 
43
- def arguments(*args)
44
- if args.length > 1
45
- fail('only one command maybe specified')
46
- end
51
+ topic = args.first
47
52
 
48
- topic = args.first
53
+ if topic
54
+ CommandLine.run(topic,'--help')
55
+ else
56
+ puts 'Available commands:'
49
57
 
50
- if topic
51
- begin
52
- CommandLine.get_command(topic).help
53
- rescue UnknownCommand => exp
54
- CommandLine.fail(exp)
58
+ CommandLine.commands.keys.sort.each do |name|
59
+ puts " #{name}"
60
+ end
55
61
  end
56
- else
57
- puts 'Available commands:'
58
-
59
- CommandLine.commands.sort_by { |cmd|
60
- cmd.command_names.first
61
- }.each { |cmd|
62
- puts " #{cmd.command_names.join(', ')}"
63
- }
64
62
  end
65
- end
66
63
 
64
+ end
67
65
  end
68
66
  end
69
67
  end
@@ -27,51 +27,51 @@ require 'ronin/platform/overlay'
27
27
  module Ronin
28
28
  module UI
29
29
  module CommandLine
30
- class InstallCommand < Command
30
+ module Commands
31
+ class Install < Command
31
32
 
32
- command :install
33
-
34
- def initialize
35
- @cache = nil
36
- @media = nil
33
+ def defaults
34
+ @cache = nil
35
+ @media = nil
36
+ end
37
37
 
38
- super
39
- end
38
+ def define_options(opts)
39
+ opts.usage = 'URI [options]'
40
40
 
41
- def define_options(opts)
42
- opts.usage = 'URI [options]'
41
+ opts.options do
42
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
43
+ @cache = dir
44
+ end
43
45
 
44
- opts.options do
45
- opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
46
- @cache = dir
46
+ opts.on('-m','--media [MEDIA]','Spedify the media-type of the overlay') do |media|
47
+ @media = media
48
+ end
47
49
  end
48
50
 
49
- opts.on('-m','--media [MEDIA]','Spedify the media-type of the overlay') do |media|
50
- @media = media
51
- end
52
- end
53
-
54
- opts.arguments(
55
- 'URI' => 'The URI of the overlay to install'
56
- )
51
+ opts.arguments(
52
+ 'URI' => 'The URI of the overlay to install'
53
+ )
57
54
 
58
- opts.summary('Installs the overlay located at the specified URI')
59
- end
60
-
61
- def arguments(args)
62
- unless args.length == 1
63
- fail('only one overlay URI maybe specified')
55
+ opts.summary %{
56
+ Installs the overlay located at the specified URI
57
+ }
64
58
  end
65
59
 
66
- uri = args.first
60
+ def arguments(args)
61
+ unless args.length == 1
62
+ fail('only one overlay URI maybe specified')
63
+ end
64
+
65
+ uri = args.first
67
66
 
68
- Platform.load_overlays(@cache) if @cache
67
+ Platform.load_overlays(@cache) if @cache
69
68
 
70
- Platform.install(:uri => uri, :media => @media) do |overlay|
71
- puts "Overlay #{overlay.name.dump} has been installed."
69
+ Platform.install(:uri => uri, :media => @media) do |overlay|
70
+ puts "Overlay #{overlay.name.dump} has been installed."
71
+ end
72
72
  end
73
- end
74
73
 
74
+ end
75
75
  end
76
76
  end
77
77
  end