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
@@ -27,47 +27,45 @@ require 'ronin/platform/overlay'
27
27
  module Ronin
28
28
  module UI
29
29
  module CommandLine
30
- class UninstallCommand < Command
30
+ module Commands
31
+ class Uninstall < Command
31
32
 
32
- command :uninstall
33
-
34
- def initialize
35
- @cache = nil
36
- @verbose = false
37
-
38
- super
39
- end
33
+ def defaults
34
+ @cache = nil
35
+ @verbose = false
36
+ end
40
37
 
41
- def define_options(opts)
42
- opts.usage = 'NAME [NAME ...] [options]'
38
+ def define_options(opts)
39
+ opts.usage = 'NAME [NAME ...] [options]'
43
40
 
44
- opts.options do
45
- opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
46
- @cache = dir
47
- end
41
+ opts.options do
42
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
43
+ @cache = dir
44
+ end
48
45
 
49
- opts.on('-v','--verbose','Enable verbose output') do
50
- @verbose = true
46
+ opts.on('-v','--verbose','Enable verbose output') do
47
+ @verbose = true
48
+ end
51
49
  end
52
- end
53
50
 
54
- opts.arguments(
55
- 'NAME' => 'The overlay to uninstall'
56
- )
51
+ opts.arguments(
52
+ 'NAME' => 'The overlay to uninstall'
53
+ )
57
54
 
58
- opts.summary('Uninstall the specified repositories')
59
- end
55
+ opts.summary('Uninstall the specified repositories')
56
+ end
60
57
 
61
- def arguments(*args)
62
- Platform.load_overlays(@cache) if @cache
58
+ def arguments(*args)
59
+ Platform.load_overlays(@cache) if @cache
63
60
 
64
- args.each do |name|
65
- Platform.uninstall(name) do |overlay|
66
- puts "Uninstalling #{overlay.name.dump} ..."
61
+ args.each do |name|
62
+ Platform.uninstall(name) do |overlay|
63
+ puts "Uninstalling #{overlay.name.dump} ..."
64
+ end
67
65
  end
68
66
  end
69
- end
70
67
 
68
+ end
71
69
  end
72
70
  end
73
71
  end
@@ -27,47 +27,45 @@ require 'ronin/platform/overlay'
27
27
  module Ronin
28
28
  module UI
29
29
  module CommandLine
30
- class UpdateCommand < Command
30
+ module Commands
31
+ class Update < Command
31
32
 
32
- command :update, :up
33
-
34
- def initialize
35
- @cache = nil
36
- @verbose = false
37
-
38
- super
39
- end
33
+ def defaults
34
+ @cache = nil
35
+ @verbose = false
36
+ end
40
37
 
41
- def define_options(opts)
42
- opts.usage = '[NAME ...] [options]'
38
+ def define_options(opts)
39
+ opts.usage = '[NAME ...] [options]'
43
40
 
44
- opts.options do
45
- opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
46
- @cache = dir
47
- end
41
+ opts.options do
42
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
43
+ @cache = dir
44
+ end
48
45
 
49
- opts.on('-v','--verbose','Enable verbose output') do
50
- @verbose = true
46
+ opts.on('-v','--verbose','Enable verbose output') do
47
+ @verbose = true
48
+ end
51
49
  end
52
- end
53
50
 
54
- opts.arguments(
55
- 'NAME' => 'The overlay to update'
56
- )
51
+ opts.arguments(
52
+ 'NAME' => 'The overlay to update'
53
+ )
57
54
 
58
- opts.summary('Updates all or the specified repositories')
59
- end
55
+ opts.summary('Updates all or the specified repositories')
56
+ end
60
57
 
61
- def arguments(*args)
62
- Platform.load_overlays(@cache) if @cache
58
+ def arguments(*args)
59
+ Platform.load_overlays(@cache) if @cache
63
60
 
64
- if args.empty?
65
- Platform.overlays.each_overlay { |overlay| overlay.update }
66
- else
67
- args.each { |name| Platform.overlays.update(name) }
61
+ if args.empty?
62
+ Platform.overlays.each_overlay { |overlay| overlay.update }
63
+ else
64
+ args.each { |name| Platform.overlays.update(name) }
65
+ end
68
66
  end
69
- end
70
67
 
68
+ end
71
69
  end
72
70
  end
73
71
  end
@@ -39,18 +39,6 @@ module Ronin
39
39
  super(&block)
40
40
  end
41
41
 
42
- #
43
- # Creates a new Options object for a Command with the specified
44
- # _program_ name and the given command _name_. If a _block_ is
45
- # given, it will be passed the newly created Options object.
46
- #
47
- def Options.command(program,name=nil,&block)
48
- program = program.to_s
49
- program << " #{name}" if name
50
-
51
- return Options.new(program,&block)
52
- end
53
-
54
42
  #
55
43
  # Sets the example usage for the options to the specified _example_.
56
44
  #
@@ -27,25 +27,38 @@ module Ronin
27
27
  module UI
28
28
  module CommandLine
29
29
  module ParamParser
30
- # Hash of format patterns and their parsers
31
- FORMATS = {
32
- /^[0-9]+$/ => lambda { |value| value.to_i },
33
- /^0x[0-9a-fA-F]+$/ => lambda { |value| value.hex },
34
- /^[a-zA-Z][a-zA-Z0-9]*:\/\// => lambda { |value| URI(value) },
35
- 'true' => lambda { |value| true },
36
- 'false' => lambda { |value| false }
37
- }
38
-
39
30
  # The params Hash
40
31
  attr_reader :params
41
32
 
42
33
  #
43
- # Creates an empty +params+ Hash.
34
+ # The Array of parameter patterns and their parsers.
44
35
  #
45
- def initialize
46
- @params = {}
36
+ def ParamParser.formats
37
+ @@ronin_param_formats ||= []
47
38
  end
48
39
 
40
+ #
41
+ # Itereates over each parameter pattern and parser, passing them to the
42
+ # specified _block_.
43
+ #
44
+ def ParamParser.each_format(&block)
45
+ ParamParser.formats.each do |format|
46
+ block.call(format[:pattern],format[:parser])
47
+ end
48
+ end
49
+
50
+ #
51
+ # Adds a new parameter _pattern_ using the specified _block_ as the parser.
52
+ #
53
+ def ParamParser.recognize(pattern,&block)
54
+ ParamParser.formats.unshift({
55
+ :pattern => pattern,
56
+ :parser => block
57
+ })
58
+ end
59
+
60
+ protected
61
+
49
62
  #
50
63
  # Parses the specified _name_and_value_ string of the form
51
64
  # "name=value" and extracts both the _name_ and the _value_, saving
@@ -57,7 +70,7 @@ module Ronin
57
70
  name, value = name_and_value.split('=',2)
58
71
 
59
72
  if value
60
- FORMATS.each do |pattern,parser|
73
+ ParamParser.each_format do |pattern,parser|
61
74
  if value.match(pattern)
62
75
  value = parser.call(value)
63
76
  break
@@ -65,8 +78,15 @@ module Ronin
65
78
  end
66
79
  end
67
80
 
68
- @params[name.to_sym] = value
81
+ return {name.to_sym => value}
69
82
  end
83
+
84
+ ParamParser.recognize(/^[a-zA-Z][a-zA-Z0-9]*:\/\//) { |value| URI(value) }
85
+ ParamParser.recognize('false') { |value| false }
86
+ ParamParser.recognize('true') { |value| true }
87
+ ParamParser.recognize(/^0x[0-9a-fA-F]+$/) { |value| value.hex }
88
+ ParamParser.recognize(/^[0-9]+$/) { |value| value.to_i }
89
+
70
90
  end
71
91
  end
72
92
  end
@@ -88,6 +88,7 @@ module Ronin
88
88
  # configure the irb workspace
89
89
  irb.context.main.instance_eval do
90
90
  require 'ronin/environment'
91
+ require 'ronin/platform'
91
92
 
92
93
  Ronin::UI::Console.auto_load.each do |path|
93
94
  require path
@@ -21,32 +21,18 @@
21
21
  #++
22
22
  #
23
23
 
24
+ require 'ronin/ui/verbose'
25
+
24
26
  module Ronin
25
27
  module UI
26
28
  module Diagnostics
27
- def Diagnostics.enable!
28
- @@ronin_diagnostics = true
29
- end
30
-
31
- def Diagnostics.enabled?
32
- (@@ronin_diagnostics ||= false) == true
33
- end
34
-
35
- def Diagnostics.disable!
36
- @@ronin_diagnostics = false
37
- end
38
-
39
- def Diagnostics.disabled?
40
- (@@ronin_diagnostics ||= false) == false
41
- end
42
-
43
29
  protected
44
30
 
45
31
  #
46
32
  # Prints the given _messages_ as info diagnostics.
47
33
  #
48
34
  def print_info(*messages)
49
- if Diagnostics.enabled?
35
+ if Verbose.enabled?
50
36
  STDERR.puts(*(messages.map { |mesg| "[-] #{mesg}" }))
51
37
  end
52
38
  end
@@ -55,7 +41,7 @@ module Ronin
55
41
  # Prints the given _messages_ as warning diagnostics.
56
42
  #
57
43
  def print_warning(*messages)
58
- if Diagnostics.enabled?
44
+ if Verbose.enabled?
59
45
  STDERR.puts(*(messages.map { |mesg| "[*] #{mesg}" }))
60
46
  end
61
47
  end
@@ -64,7 +50,7 @@ module Ronin
64
50
  # Prints the given _messages_ as error diagnostics.
65
51
  #
66
52
  def print_error(*messages)
67
- if Diagnostics.enabled?
53
+ if Verbose.enabled?
68
54
  STDERR.puts(*(messages.map { |mesg| "[!] #{mesg}" }))
69
55
  end
70
56
  end
@@ -21,16 +21,24 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/ui/command_line/commands/overlay'
25
- require 'ronin/ui/command_line/commands/extension'
26
- require 'ronin/ui/command_line/commands/add'
27
- require 'ronin/ui/command_line/commands/install'
28
- require 'ronin/ui/command_line/commands/list'
29
- require 'ronin/ui/command_line/commands/update'
30
- require 'ronin/ui/command_line/commands/uninstall'
31
- require 'ronin/ui/command_line/commands/remove'
32
- require 'ronin/ui/command_line/commands/help'
24
+ module Ronin
25
+ module UI
26
+ module Verbose
27
+ def Verbose.enable!
28
+ @@ronin_verbose = true
29
+ end
33
30
 
34
- require 'reverse_require'
31
+ def Verbose.enabled?
32
+ (@@ronin_verbose ||= false) == true
33
+ end
35
34
 
36
- require_for 'ronin', 'ronin/ui/command_line/commands'
35
+ def Verbose.disable!
36
+ @@ronin_verbose = false
37
+ end
38
+
39
+ def Verbose.disabled?
40
+ (@@ronin_verbose ||= false) == false
41
+ end
42
+ end
43
+ end
44
+ end
@@ -23,5 +23,5 @@
23
23
 
24
24
  module Ronin
25
25
  # Ronin version
26
- VERSION = '0.2.0'
26
+ VERSION = '0.2.1'
27
27
  end
@@ -4,55 +4,55 @@ require 'helpers/database'
4
4
 
5
5
  describe Arch do
6
6
  it "should require a name, endian and address_length attributes" do
7
- @arch = Arch.new
8
- @arch.should_not be_valid
7
+ arch = Arch.new
8
+ arch.should_not be_valid
9
9
 
10
- @arch.name = 'future'
11
- @arch.should_not be_valid
10
+ arch.name = 'future'
11
+ arch.should_not be_valid
12
12
 
13
- @arch.endian = 'little'
14
- @arch.should_not be_valid
13
+ arch.endian = 'little'
14
+ arch.should_not be_valid
15
15
 
16
- @arch.address_length = 4
17
- @arch.should be_valid
16
+ arch.address_length = 4
17
+ arch.should be_valid
18
18
  end
19
19
 
20
20
  it "should require a unique name" do
21
- @first_arch = Arch.create(:name => 'cats',
21
+ first_arch = Arch.create(:name => 'cats',
22
22
  :endian => 'little',
23
23
  :address_length => 4)
24
- @first_arch.should be_valid
24
+ first_arch.should be_valid
25
25
 
26
- @second_arch = Arch.new(:name => 'cats',
26
+ second_arch = Arch.new(:name => 'cats',
27
27
  :endian => 'big',
28
28
  :address_length => 4)
29
- @second_arch.should_not be_valid
29
+ second_arch.should_not be_valid
30
30
  end
31
31
 
32
32
  it "should require either 'little' or 'big' for the endian attribute" do
33
- @arch = Arch.new(:name => 'test',
33
+ arch = Arch.new(:name => 'test',
34
34
  :endian => 'lol',
35
35
  :address_length => 4)
36
- @arch.should_not be_valid
36
+ arch.should_not be_valid
37
37
 
38
- @arch.endian = 'little'
39
- @arch.should be_valid
38
+ arch.endian = 'little'
39
+ arch.should be_valid
40
40
 
41
- @arch.endian = 'big'
42
- @arch.should be_valid
41
+ arch.endian = 'big'
42
+ arch.should be_valid
43
43
  end
44
44
 
45
45
  it "should require a numeric valid for the address_length attribute" do
46
- @arch = Arch.new(:name => 'test2',
46
+ arch = Arch.new(:name => 'test2',
47
47
  :endian => 'big',
48
48
  :address_length => 'x')
49
- @arch.should_not be_valid
49
+ arch.should_not be_valid
50
50
 
51
- @arch.address_length = '4'
52
- @arch.should be_valid
51
+ arch.address_length = '4'
52
+ arch.should be_valid
53
53
 
54
- @arch.address_length = 4
55
- @arch.should be_valid
54
+ arch.address_length = 4
55
+ arch.should be_valid
56
56
  end
57
57
 
58
58
  it "should provide built-in archs" do
@@ -12,7 +12,7 @@ describe Chars do
12
12
  @uppercase_alpha_string = Chars.uppercase_alpha.random_string(10)
13
13
  @lowercase_alpha_string = Chars.lowercase_alpha.random_string(10)
14
14
  @alpha_string = Chars.alpha.random_string(10)
15
- @alpha_numeric = Chars.alpha_numeric.random_string(10)
15
+ @alpha_numeric_string = Chars.alpha_numeric.random_string(10)
16
16
  @space_string = Chars.space.random_string(10)
17
17
  @punctuation_string = Chars.punctuation.random_string(10)
18
18
  @symbols_string = Chars.symbols.random_string(10)
@@ -22,50 +22,86 @@ describe Chars do
22
22
  end
23
23
 
24
24
  it "should provide a numeric CharSet" do
25
- (@numeric_string =~ /[0-9]{10}/).should_not be_nil
25
+ @numeric_string.length.should == 10
26
+ @numeric_string.each_byte do |b|
27
+ Chars::NUMERIC.include?(b).should == true
28
+ end
26
29
  end
27
30
 
28
31
  it "should provide an octal CharSet" do
29
- (@octal_string =~ /[0-7]{10}/).should_not be_nil
32
+ @octal_string.length.should == 10
33
+ @octal_string.each_byte do |b|
34
+ Chars::OCTAL.include?(b).should == true
35
+ end
30
36
  end
31
37
 
32
38
  it "should provide an upper-case hexadecimal CharSet" do
33
- (@uppercase_hex_string =~ /[0-9A-F]{10}/).should_not be_nil
39
+ @uppercase_hex_string.length.should == 10
40
+ @uppercase_hex_string.each_byte do |b|
41
+ Chars::UPPERCASE_HEXADECIMAL.include?(b).should == true
42
+ end
34
43
  end
35
44
 
36
45
  it "should provide a lower-case hexadecimal CharSet" do
37
- (@lowercase_hex_string =~ /[0-9a-f]{10}/).should_not be_nil
46
+ @lowercase_hex_string.length.should == 10
47
+ @lowercase_hex_string.each_byte do |b|
48
+ Chars::LOWERCASE_HEXADECIMAL.include?(b).should == true
49
+ end
38
50
  end
39
51
 
40
52
  it "should provide a hexadecimal CharSet" do
41
- (@hex_string =~ /[0-9A-Fa-f]{10}/).should_not be_nil
53
+ @hex_string.length.should == 10
54
+ @hex_string.each_byte do |b|
55
+ Chars::HEXADECIMAL.include?(b).should == true
56
+ end
42
57
  end
43
58
 
44
59
  it "should provide an upper-case alpha CharSet" do
45
- (@uppercase_alpha_string =~ /[A-Z]{10}/).should_not be_nil
60
+ @uppercase_alpha_string.length.should == 10
61
+ @uppercase_alpha_string.each_byte do |b|
62
+ Chars::UPPERCASE_ALPHA.include?(b).should == true
63
+ end
46
64
  end
47
65
 
48
66
  it "should provide a lower-case alpha CharSet" do
49
- (@lowercase_alpha_string =~ /[a-z]{10}/).should_not be_nil
67
+ @lowercase_alpha_string.length.should == 10
68
+ @lowercase_alpha_string.each_byte do |b|
69
+ Chars::LOWERCASE_ALPHA.include?(b).should == true
70
+ end
50
71
  end
51
72
 
52
73
  it "should provide an alpha CharSet" do
53
- (@alpha_string =~ /[A-Za-z]{10}/).should_not be_nil
74
+ @alpha_string.length.should == 10
75
+ @alpha_string.each_byte do |b|
76
+ Chars::ALPHA.include?(b).should == true
77
+ end
54
78
  end
55
79
 
56
80
  it "should provide an alpha-numeric CharSet" do
57
- (@alpha_numeric_string =~ /[A-Za-z0-9]{10}/).should_not be_nil
81
+ @alpha_numeric_string.length.should == 10
82
+ @alpha_numeric_string.each_byte do |b|
83
+ Chars::ALPHA_NUMERIC.include?(b).should == true
84
+ end
58
85
  end
59
86
 
60
87
  it "should provide a space CharSet" do
61
- (@space_string =~ /[ \f\n\r\t\v]{10}/).should_not be_nil
88
+ @space_string.length.should == 10
89
+ @space_string.each_byte do |b|
90
+ Chars::SPACE.include?(b).should == true
91
+ end
62
92
  end
63
93
 
64
94
  it "should provide a punctuation CharSet" do
65
- (@punctuation_string =~ /[ \'\"\`\,\;\:\~\-\(\)\[\]\{\}\.\?\!]{10}/).should_not be_nil
95
+ @punctuation_string.length.should == 10
96
+ @punctuation_string.each_byte do |b|
97
+ Chars::PUNCTUATION.include?(b).should == true
98
+ end
66
99
  end
67
100
 
68
101
  it "should provide a symbols CharSet" do
69
- (@symbols_string =~ /[\@\#\$\%\^\&\*\_\+\=\|\\\<\>\/]/).should_not be_nil
102
+ @symbols_string.length.should == 10
103
+ @symbols_string.each_byte do |b|
104
+ Chars::SYMBOLS.include?(b).should == true
105
+ end
70
106
  end
71
107
  end