Skip to content

Commit

Permalink
Added new number options to CLI::PatternOptions (closes #260).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 15, 2024
1 parent 04b414e commit 90e3971
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/ronin/cli/commands/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ module Commands
# ## Options
#
# -N, --number Searches for all numbers
# --float Searches for all floating point numbers
# --octal-byte Searches for all octal bytes
# --decimal-byte Searches for all decimal bytes
# -X, --hex-number Searches for all hexadecimal numbers
# --hex-byte Searches for all hexadecimal bytes
# --hex-word Searches for all hexadecimal words
# --hex-dword Searches for all hexadecimal double-words
# --hex-qword Searches for all hexadecimal quad-words
# --alpha Searches for all alphabetic characters
# --uppercase Searches for all uppercase alphabetic characters
# --lowercase Searches for all lowercase alphabetic characters
Expand Down
7 changes: 7 additions & 0 deletions lib/ronin/cli/commands/grep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ module Commands
# ## Options
#
# -N, --number Searches for all numbers
# --float Searches for all floating point numbers
# --octal-byte Searches for all octal bytes
# --decimal-byte Searches for all decimal bytes
# -X, --hex-number Searches for all hexadecimal numbers
# --hex-byte Searches for all hexadecimal bytes
# --hex-word Searches for all hexadecimal words
# --hex-dword Searches for all hexadecimal double-words
# --hex-qword Searches for all hexadecimal quad-words
# --alpha Searches for all alphabetic characters
# --uppercase Searches for all uppercase alphabetic characters
# --lowercase Searches for all lowercase alphabetic characters
Expand Down
35 changes: 35 additions & 0 deletions lib/ronin/cli/pattern_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ class CLI
# ## Options
#
# -N, --number Searches for all numbers
# --float Searches for all floating point numbers
# --octal-byte Searches for all octal bytes
# --decimal-byte Searches for all decimal bytes
# -X, --hex-number Searches for all hexadecimal numbers
# --hex-byte Searches for all hexadecimal bytes
# --hex-word Searches for all hexadecimal words
# --hex-dword Searches for all hexadecimal double-words
# --hex-qword Searches for all hexadecimal quad-words
# --alpha Searches for all alphabetic characters
# --uppercase Searches for all uppercase alphabetic characters
# --lowercase Searches for all lowercase alphabetic characters
Expand Down Expand Up @@ -132,10 +139,38 @@ def self.define_numeric_options(command)
@pattern = NUMBER
end

command.option :float, desc: 'Searches for all floating point numbers' do
@pattern = FLOAT
end

command.option :octal_byte, desc: 'Searches for all octal bytes' do
@pattern = OCTAL_BYTE
end

command.option :decimal_byte, desc: 'Searches for all decimal bytes' do
@pattern = DECIMAL_BYTE
end

command.option :hex_number, short: '-X',
desc: 'Searches for all hexadecimal numbers' do
@pattern = HEX_NUMBER
end

command.option :hex_byte, desc: 'Searches for all hexadecimal bytes' do
@pattern = HEX_BYTE
end

command.option :hex_word, desc: 'Searches for all hexadecimal words' do
@pattern = HEX_WORD
end

command.option :hex_dword, desc: 'Searches for all hexadecimal double-words' do
@pattern = HEX_DWORD
end

command.option :hex_qword, desc: 'Searches for all hexadecimal quad-words' do
@pattern = HEX_QWORD
end
end

#
Expand Down
21 changes: 21 additions & 0 deletions man/ronin-extract.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,30 @@ Extract common patterns in the given file(s) or input stream.
`-N`, `--number`
: Searches for all numbers.

`--float`
: Searches for all floating point numbers.

`--octal-byte`
: Searches for all bytes in octal format.

`--decimal-byte`
: Searches for all bytes in decimal format.

`-X`, `--hex-number`
: Searches for all hexadecimal numbers.

`--hex-byte`
: Searches for all bytes in hexadecimal format.

`--hex-word`
: Searches for all words in hexadecimal format.

`--hex-dword`
: Searches for all double-words in hexadecimal format.

`--hex-qword`
: Searches for all quad-words in hexadecimal format.

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

Expand Down
21 changes: 21 additions & 0 deletions man/ronin-grep.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,30 @@ Greps for common patterns in the given file(s) or input stream.
`-N`, `--number`
: Searches for all numbers.

`--float`
: Searches for all floating point numbers.

`--octal-byte`
: Searches for all bytes in octal format.

`--decimal-byte`
: Searches for all bytes in decimal format.

`-X`, `--hex-number`
: Searches for all hexadecimal numbers.

`--hex-byte`
: Searches for all bytes in hexadecimal format.

`--hex-word`
: Searches for all words in hexadecimal format.

`--hex-dword`
: Searches for all double-words in hexadecimal format.

`--hex-qword`
: Searches for all quad-words in hexadecimal format.

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

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

it "must define a '--float' option" do
expect(subject.options[:float]).to_not be(nil)
expect(subject.options[:float].short).to be(nil)
expect(subject.options[:float].value).to be(nil)
expect(subject.options[:float].desc).to eq('Searches for all floating point numbers')
end

it "must define a '-X,--hex-number' option" do
expect(subject.options[:hex_number]).to_not be(nil)
expect(subject.options[:hex_number].short).to eq('-X')
expect(subject.options[:hex_number].value).to be(nil)
expect(subject.options[:hex_number].desc).to eq('Searches for all hexadecimal numbers')
end

it "must define a '--hex-byte' option" do
expect(subject.options[:hex_byte]).to_not be(nil)
expect(subject.options[:hex_byte].short).to be(nil)
expect(subject.options[:hex_byte].value).to be(nil)
expect(subject.options[:hex_byte].desc).to eq('Searches for all hexadecimal bytes')
end

it "must define a '--hex-word' option" do
expect(subject.options[:hex_word]).to_not be(nil)
expect(subject.options[:hex_word].short).to be(nil)
expect(subject.options[:hex_word].value).to be(nil)
expect(subject.options[:hex_word].desc).to eq('Searches for all hexadecimal words')
end

it "must define a '--hex-dword' option" do
expect(subject.options[:hex_dword]).to_not be(nil)
expect(subject.options[:hex_dword].short).to be(nil)
expect(subject.options[:hex_dword].value).to be(nil)
expect(subject.options[:hex_dword].desc).to eq('Searches for all hexadecimal double-words')
end

it "must define a '--hex-qword' option" do
expect(subject.options[:hex_qword]).to_not be(nil)
expect(subject.options[:hex_qword].short).to be(nil)
expect(subject.options[:hex_qword].value).to be(nil)
expect(subject.options[:hex_qword].desc).to eq('Searches for all hexadecimal quad-words')
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 @@ -591,8 +626,15 @@ class TestCommand < Ronin::CLI::Command
#
include_context "pattern option", '-N', :NUMBER
include_context "pattern option", '--number', :NUMBER
include_context "pattern option", '--float', :FLOAT
include_context "pattern option", '--octal-byte', :OCTAL_BYTE
include_context "pattern option", '--decimal-byte', :DECIMAL_BYTE
include_context "pattern option", '-X', :HEX_NUMBER
include_context "pattern option", '--hex-number', :HEX_NUMBER
include_context "pattern option", '--hex-byte', :HEX_BYTE
include_context "pattern option", '--hex-word', :HEX_WORD
include_context "pattern option", '--hex-dword', :HEX_DWORD
include_context "pattern option", '--hex-qword', :HEX_QWORD

#
# Language pattern options
Expand Down

0 comments on commit 90e3971

Please sign in to comment.