Skip to content

Commit

Permalink
Added new software options to ronin grep/ronin extract (closes #261
Browse files Browse the repository at this point in the history
…).

* `--version-constraint` -> `Ronin::Support::Text::Patterns::VERSION_CONSTRAINT`.
* `--version-range` -> `Ronin::Support::Text::Patterns::VERSION_RANGE`.
  • Loading branch information
postmodern committed Dec 15, 2024
1 parent 3426ea1 commit 3902415
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 20 deletions.
3 changes: 3 additions & 0 deletions lib/ronin/cli/commands/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ module Commands
# --ruby-comment Searches for all Ruby comments
# --python-comment Searches for all Python comments
# --comment Searches for all comments
# -V, --version-number Searches for all version numbers
# --version-constraint Searches for all version constraints
# --version-range Searches for all version ranges
# -e, --regexp /REGEXP/ Custom regular expression to search for
# -h, --help Print help information
#
Expand Down
3 changes: 3 additions & 0 deletions lib/ronin/cli/commands/grep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ module Commands
# --ruby-comment Searches for all Ruby comments
# --python-comment Searches for all Python comments
# --comment Searches for all comments
# -V, --version-number Searches for all version numbers
# --version-constraint Searches for all version constraints
# --version-range Searches for all version ranges
# -e, --regexp /REGEXP/ Custom regular expression to search for
# -o, --only-matching Only print the matching data
# -n, --line-number Print the line number for each line
Expand Down
31 changes: 25 additions & 6 deletions lib/ronin/cli/pattern_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CLI
#
# -N, --number Searches for all numbers
# -X, --hex-number Searches for all hexadecimal numbers
# -V, --version-number Searches for all version numbers
# --alpha Searches for all alphabetic characters
# --uppercase Searches for all uppercase alphabetic characters
# --lowercase Searches for all lowercase alphabetic characters
Expand Down Expand Up @@ -88,6 +87,9 @@ class CLI
# --double-quoted-string Searches for all double-quoted strings
# -S, --string Searches for all quoted strings
# -B, --base64 Searches for all Base64 strings
# -V, --version-number Searches for all version numbers
# --version-constraint Searches for all version constraints
# --version-range Searches for all version ranges
# -e, --regexp /REGEXP/ Custom regular expression to search for
#
module PatternOptions
Expand All @@ -109,6 +111,7 @@ def self.included(command)
define_source_code_options(command)
define_crypto_options(command)
define_credentials_options(command)
define_software_options(command)

command.option :regexp, short: '-e',
value: {type: Regexp},
Expand All @@ -133,11 +136,6 @@ def self.define_numeric_options(command)
desc: 'Searches for all hexadecimal numbers' do
@pattern = HEX_NUMBER
end

command.option :version_number, short: '-V',
desc: 'Searches for all version numbers' do
@pattern = VERSION_NUMBER
end
end

#
Expand Down Expand Up @@ -497,6 +495,27 @@ def self.define_credentials_options(command)
end
end

#
# Defines software pattern options.
#
# @param [Class<Command>] command
# The command including {PatternOptions}.
#
def self.define_software_options(command)
command.option :version_number, short: '-V',
desc: 'Searches for all version numbers' do
@pattern = VERSION_NUMBER
end

command.option :version_constraint, desc: 'Searches for all version constraints' do
@pattern = VERSION_CONSTRAINT
end

command.option :version_range, desc: 'Searches for all version ranges' do
@pattern = VERSION_RANGE
end
end

# The pattern to search for.
#
# @return [Regexp, nil]
Expand Down
12 changes: 9 additions & 3 deletions man/ronin-extract.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ Extract common patterns in the given file(s) or input stream.
`-X`, `--hex-number`
: Searches for all hexadecimal numbers.

`-V`, `--version-number`
: Searches for all version numbers.

`--alpha`
: Searches for all alphabetic characters.

Expand Down Expand Up @@ -240,6 +237,15 @@ Extract common patterns in the given file(s) or input stream.
`--comment`
: Searches for all comments.

`-V`, `--version-number`
: Searches for all version numbers.

`--version-constraint`
: Searches for all version constraints.

`--version-range`
: Searches for all version ranges.

`-e`, `--regexp` /*REGEXP*/
: Custom regular expression to search for.

Expand Down
12 changes: 9 additions & 3 deletions man/ronin-grep.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ Greps for common patterns in the given file(s) or input stream.
`-X`, `--hex-number`
: Searches for all hexadecimal numbers.

`-V`, `--version-number`
: Searches for all version numbers.

`--alpha`
: Searches for all alphabetic characters.

Expand Down Expand Up @@ -240,6 +237,15 @@ Greps for common patterns in the given file(s) or input stream.
`--comment`
: Searches for all comments.

`-V`, `--version-number`
: Searches for all version numbers.

`--version-constraint`
: Searches for all version constraints.

`--version-range`
: Searches for all version ranges.

`-e`, `--regexp` /*REGEXP*/
: Custom regular expression to search for.

Expand Down
39 changes: 31 additions & 8 deletions spec/cli/pattern_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ class TestCommand < Ronin::CLI::Command
expect(subject.options[:hex_number].desc).to eq('Searches for all hexadecimal numbers')
end

it "must define a '-V,--version-number' option" do
expect(subject.options[:version_number]).to_not be(nil)
expect(subject.options[:version_number].short).to eq('-V')
expect(subject.options[:version_number].value).to be(nil)
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)
Expand Down Expand Up @@ -543,6 +536,30 @@ class TestCommand < Ronin::CLI::Command
expect(subject.options[:api_key].desc).to eq('Searches for all API keys')
end

#
# Software options
#
it "must define a '-V,--version-number' option" do
expect(subject.options[:version_number]).to_not be(nil)
expect(subject.options[:version_number].short).to eq('-V')
expect(subject.options[:version_number].value).to be(nil)
expect(subject.options[:version_number].desc).to eq('Searches for all version numbers')
end

it "must define a '--version-constraint' option" do
expect(subject.options[:version_constraint]).to_not be(nil)
expect(subject.options[:version_constraint].short).to be(nil)
expect(subject.options[:version_constraint].value).to be(nil)
expect(subject.options[:version_constraint].desc).to eq('Searches for all version constraints')
end

it "must define a '--version-range' option" do
expect(subject.options[:version_range]).to_not be(nil)
expect(subject.options[:version_range].short).to be(nil)
expect(subject.options[:version_range].value).to be(nil)
expect(subject.options[:version_range].desc).to eq('Searches for all version ranges')
end

#
# General options
#
Expand Down Expand Up @@ -576,7 +593,6 @@ class TestCommand < Ronin::CLI::Command
include_context "pattern option", '--number', :NUMBER
include_context "pattern option", '-X', :HEX_NUMBER
include_context "pattern option", '--hex-number', :HEX_NUMBER
include_context "pattern option", '--version-number', :VERSION_NUMBER

#
# Language pattern options
Expand Down Expand Up @@ -681,6 +697,13 @@ class TestCommand < Ronin::CLI::Command
include_context "pattern option", '--api-key', :API_KEY
include_context "pattern option", '-A', :API_KEY

#
# Software pattern options
#
include_context "pattern option", '--version-number', :VERSION_NUMBER
include_context "pattern option", '--version-constraint', :VERSION_CONSTRAINT
include_context "pattern option", '--version-range', :VERSION_RANGE

#
# General options
#
Expand Down

0 comments on commit 3902415

Please sign in to comment.