From 8654a4df3d100185ce73f22f3f60dc106db1aa54 Mon Sep 17 00:00:00 2001 From: raj921 Date: Sun, 8 Dec 2024 15:52:34 +0530 Subject: [PATCH 1/5] Add more basic pattern options to CLI::PatternOptions Added new pattern options: - --alpha: /[a-zA-Z]+/ - --uppercase: /[A-Z]+/ - --lowercase: /[a-z]+/ - --alpha-numeric: /[0-9a-zA-Z]+/ - --hex: /[0-9a-fA-F]+/ - --uppercase-hex: /[0-9A-F]+/ - --lowercase-hex: /[0-9a-f]+/ Resolves #253 --- lib/ronin/cli/pattern_options.rb | 66 +++++++++++++++++++++++++++----- spec/cli/pattern_options_spec.rb | 49 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 9 deletions(-) diff --git a/lib/ronin/cli/pattern_options.rb b/lib/ronin/cli/pattern_options.rb index a90d05e77..765055763 100644 --- a/lib/ronin/cli/pattern_options.rb +++ b/lib/ronin/cli/pattern_options.rb @@ -116,19 +116,67 @@ def self.included(command) # def self.define_numeric_options(command) command.option :number, short: '-N', - desc: 'Searches for all numbers' do - @pattern = NUMBER - end + desc: 'Searches for all numbers', + value: { + type: Regexp, + value: NUMBER + } command.option :hex_number, short: '-X', - desc: 'Searches for all hexadecimal numbers' do - @pattern = HEX_NUMBER - end + desc: 'Searches for all hexadecimal numbers', + value: { + type: Regexp, + value: HEX_NUMBER + } command.option :version_number, short: '-V', - desc: 'Searches for all version numbers' do - @pattern = VERSION_NUMBER - end + desc: 'Searches for all version numbers', + value: { + type: Regexp, + value: VERSION_NUMBER + } + + command.option :alpha, desc: 'Searches for all alphabetic characters', + value: { + type: Regexp, + value: /[a-zA-Z]+/ + } + + command.option :uppercase, desc: 'Searches for all uppercase alphabetic characters', + value: { + type: Regexp, + value: /[A-Z]+/ + } + + command.option :lowercase, desc: 'Searches for all lowercase alphabetic characters', + value: { + type: Regexp, + value: /[a-z]+/ + } + + command.option :alpha_numeric, desc: 'Searches for all alphanumeric characters', + value: { + type: Regexp, + value: /[0-9a-zA-Z]+/ + } + + command.option :hex, desc: 'Searches for all hexadecimal characters', + value: { + type: Regexp, + value: /[0-9a-fA-F]+/ + } + + command.option :uppercase_hex, desc: 'Searches for all uppercase hexadecimal characters', + value: { + type: Regexp, + value: /[0-9A-F]+/ + } + + command.option :lowercase_hex, desc: 'Searches for all lowercase hexadecimal characters', + value: { + type: Regexp, + value: /[0-9a-f]+/ + } end # diff --git a/spec/cli/pattern_options_spec.rb b/spec/cli/pattern_options_spec.rb index 35d37dd62..871765d6c 100644 --- a/spec/cli/pattern_options_spec.rb +++ b/spec/cli/pattern_options_spec.rb @@ -39,6 +39,55 @@ class TestCommand < Ronin::CLI::Command expect(subject.options[:version_number].desc).to eq('Searches for all version numbers') end + it "must define a '--alpha' option" do + expect(subject.options[:alpha]).to_not be(nil) + expect(subject.options[:alpha].short).to be(nil) + expect(subject.options[:alpha].value).to be(nil) + expect(subject.options[:alpha].desc).to eq('Searches for all alphabetic characters') + end + + it "must define a '--uppercase' option" do + expect(subject.options[:uppercase]).to_not be(nil) + expect(subject.options[:uppercase].short).to be(nil) + expect(subject.options[:uppercase].value).to be(nil) + expect(subject.options[:uppercase].desc).to eq('Searches for all uppercase alphabetic characters') + end + + it "must define a '--lowercase' option" do + expect(subject.options[:lowercase]).to_not be(nil) + expect(subject.options[:lowercase].short).to be(nil) + expect(subject.options[:lowercase].value).to be(nil) + expect(subject.options[:lowercase].desc).to eq('Searches for all lowercase alphabetic characters') + end + + it "must define a '--alpha-numeric' option" do + expect(subject.options[:alpha_numeric]).to_not be(nil) + expect(subject.options[:alpha_numeric].short).to be(nil) + expect(subject.options[:alpha_numeric].value).to be(nil) + expect(subject.options[:alpha_numeric].desc).to eq('Searches for all alphanumeric characters') + end + + it "must define a '--hex' option" do + expect(subject.options[:hex]).to_not be(nil) + expect(subject.options[:hex].short).to be(nil) + expect(subject.options[:hex].value).to be(nil) + expect(subject.options[:hex].desc).to eq('Searches for all hexadecimal characters') + end + + it "must define a '--uppercase-hex' option" do + expect(subject.options[:uppercase_hex]).to_not be(nil) + expect(subject.options[:uppercase_hex].short).to be(nil) + expect(subject.options[:uppercase_hex].value).to be(nil) + expect(subject.options[:uppercase_hex].desc).to eq('Searches for all uppercase hexadecimal characters') + end + + it "must define a '--lowercase-hex' option" do + expect(subject.options[:lowercase_hex]).to_not be(nil) + expect(subject.options[:lowercase_hex].short).to be(nil) + expect(subject.options[:lowercase_hex].value).to be(nil) + expect(subject.options[:lowercase_hex].desc).to eq('Searches for all lowercase hexadecimal characters') + end + # # Language pattern options # From c6c12e271ead172bf2bcb02ec29c62e09bb85a87 Mon Sep 17 00:00:00 2001 From: raj921 Date: Sun, 8 Dec 2024 15:55:32 +0530 Subject: [PATCH 2/5] Add spec for CLI::Commands::New::Exploit (issue #252) Added a basic spec file that verifies the command_name matches the file name for the Exploit command class. --- spec/cli/commands/new/exploit_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 spec/cli/commands/new/exploit_spec.rb diff --git a/spec/cli/commands/new/exploit_spec.rb b/spec/cli/commands/new/exploit_spec.rb new file mode 100644 index 000000000..f0e4f6acb --- /dev/null +++ b/spec/cli/commands/new/exploit_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require 'ronin/cli/commands/new/exploit' + +describe Ronin::CLI::Commands::New::Exploit do + describe "command_name" do + subject { described_class } + + it do + expect(subject.command_name).to eq('exploit') + end + end +end From 4a20559241e5346f6431f9abe7a434d1f4f6c7fc Mon Sep 17 00:00:00 2001 From: raj921 Date: Sun, 8 Dec 2024 16:36:12 +0530 Subject: [PATCH 3/5] Fix pattern options to use blocks instead of value Replaced value: {...} with blocks that set @pattern to the respective Regexp for all pattern options. This maintains the existing behavior where options set @pattern directly rather than accepting a value. --- lib/ronin/cli/pattern_options.rb | 94 +++++++++++++------------------- 1 file changed, 37 insertions(+), 57 deletions(-) diff --git a/lib/ronin/cli/pattern_options.rb b/lib/ronin/cli/pattern_options.rb index 765055763..309a142ea 100644 --- a/lib/ronin/cli/pattern_options.rb +++ b/lib/ronin/cli/pattern_options.rb @@ -116,67 +116,47 @@ def self.included(command) # def self.define_numeric_options(command) command.option :number, short: '-N', - desc: 'Searches for all numbers', - value: { - type: Regexp, - value: NUMBER - } + desc: 'Searches for all numbers' do + @pattern = NUMBER + end command.option :hex_number, short: '-X', - desc: 'Searches for all hexadecimal numbers', - value: { - type: Regexp, - value: HEX_NUMBER - } + desc: 'Searches for all hexadecimal numbers' do + @pattern = HEX_NUMBER + end command.option :version_number, short: '-V', - desc: 'Searches for all version numbers', - value: { - type: Regexp, - value: VERSION_NUMBER - } - - command.option :alpha, desc: 'Searches for all alphabetic characters', - value: { - type: Regexp, - value: /[a-zA-Z]+/ - } - - command.option :uppercase, desc: 'Searches for all uppercase alphabetic characters', - value: { - type: Regexp, - value: /[A-Z]+/ - } - - command.option :lowercase, desc: 'Searches for all lowercase alphabetic characters', - value: { - type: Regexp, - value: /[a-z]+/ - } - - command.option :alpha_numeric, desc: 'Searches for all alphanumeric characters', - value: { - type: Regexp, - value: /[0-9a-zA-Z]+/ - } - - command.option :hex, desc: 'Searches for all hexadecimal characters', - value: { - type: Regexp, - value: /[0-9a-fA-F]+/ - } - - command.option :uppercase_hex, desc: 'Searches for all uppercase hexadecimal characters', - value: { - type: Regexp, - value: /[0-9A-F]+/ - } - - command.option :lowercase_hex, desc: 'Searches for all lowercase hexadecimal characters', - value: { - type: Regexp, - value: /[0-9a-f]+/ - } + desc: 'Searches for all version numbers' do + @pattern = VERSION_NUMBER + end + + command.option :alpha, desc: 'Searches for all alphabetic characters' do + @pattern = /[a-zA-Z]+/ + end + + command.option :uppercase, desc: 'Searches for all uppercase alphabetic characters' do + @pattern = /[A-Z]+/ + end + + command.option :lowercase, desc: 'Searches for all lowercase alphabetic characters' do + @pattern = /[a-z]+/ + end + + command.option :alpha_numeric, desc: 'Searches for all alphanumeric characters' do + @pattern = /[0-9a-zA-Z]+/ + end + + command.option :hex, desc: 'Searches for all hexadecimal characters' do + @pattern = /[0-9a-fA-F]+/ + end + + command.option :uppercase_hex, desc: 'Searches for all uppercase hexadecimal characters' do + @pattern = /[0-9A-F]+/ + end + + command.option :lowercase_hex, desc: 'Searches for all lowercase hexadecimal characters' do + @pattern = /[0-9a-f]+/ + end end # From c74109ec11dac0d5440a8391096a8c1a2cc1d5bc Mon Sep 17 00:00:00 2001 From: raj921 Date: Mon, 9 Dec 2024 00:16:34 +0530 Subject: [PATCH 4/5] Update pattern options to use blocks instead of value: {...} syntax --- lib/ronin/cli/pattern_options.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ronin/cli/pattern_options.rb b/lib/ronin/cli/pattern_options.rb index 309a142ea..91423c37f 100644 --- a/lib/ronin/cli/pattern_options.rb +++ b/lib/ronin/cli/pattern_options.rb @@ -117,18 +117,18 @@ def self.included(command) def self.define_numeric_options(command) command.option :number, short: '-N', desc: 'Searches for all numbers' do - @pattern = NUMBER - end + @pattern = NUMBER + end command.option :hex_number, short: '-X', desc: 'Searches for all hexadecimal numbers' do - @pattern = HEX_NUMBER - end + @pattern = HEX_NUMBER + end command.option :version_number, short: '-V', desc: 'Searches for all version numbers' do - @pattern = VERSION_NUMBER - end + @pattern = VERSION_NUMBER + end command.option :alpha, desc: 'Searches for all alphabetic characters' do @pattern = /[a-zA-Z]+/ From 9a1a2b8cc422c5d09d50c89fabd91befc196c01b Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sun, 8 Dec 2024 11:01:00 -0800 Subject: [PATCH 5/5] Delete spec/cli/commands/new/exploit_spec.rb * This should go into a separate commit. --- spec/cli/commands/new/exploit_spec.rb | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 spec/cli/commands/new/exploit_spec.rb diff --git a/spec/cli/commands/new/exploit_spec.rb b/spec/cli/commands/new/exploit_spec.rb deleted file mode 100644 index f0e4f6acb..000000000 --- a/spec/cli/commands/new/exploit_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'spec_helper' -require 'ronin/cli/commands/new/exploit' - -describe Ronin::CLI::Commands::New::Exploit do - describe "command_name" do - subject { described_class } - - it do - expect(subject.command_name).to eq('exploit') - end - end -end