Skip to content

Commit

Permalink
Added Text::Patterns::HEX_DWORD (issue #553).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 11, 2024
1 parent e6865d0 commit b73b3f3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ronin/support/text/patterns/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ module Patterns
# @since 1.2.0
HEX_WORD = /(?:0x)?[0-9a-fA-F]{4}/

# Regular expression for finding hexadecimal double words (00000000 - ffffffff).
#
# @since 1.2.0
HEX_DWORD = /(?:0x)?[0-9a-fA-F]{8}/

# Regular expression for finding all hexadecimal numbers in text.
#
# @since 1.0.0
Expand Down
30 changes: 30 additions & 0 deletions spec/text/patterns/numeric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@
end
end

describe "HEX_DWORD" do
subject { described_class::HEX_DWORD }

it "must match 00000000 - ffffffff" do
expect("00000000").to match(subject)
expect("ffffffff").to match(subject)
end

it "must match 00000000 - FFFFFFFF" do
expect("00000000").to match(subject)
expect("FFFFFFFF").to match(subject)
end

it "must match 0x00000000 - 0xffffffff" do
expect("0x00000000").to match(subject)
expect("0xffffffff").to match(subject)
end

it "must match 0x00000000 - 0xFFFFFFFF" do
expect("0x00000000").to match(subject)
expect("0xFFFFFFFF").to match(subject)
end

it "must only match eight hexadecimal digits" do
string = "1234abcdefg"

expect(string[subject]).to eq("1234abcd")
end
end

describe "HEX_NUMBER" do
subject { described_class::HEX_NUMBER }

Expand Down

0 comments on commit b73b3f3

Please sign in to comment.