Skip to content

Commit

Permalink
Added Text::Patterns::HEX_QWORD (issue #553).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 12, 2024
1 parent 5ff212e commit 9780e69
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 @@ -57,6 +57,11 @@ module Patterns
# @since 1.2.0
HEX_DWORD = /(?:0x)?[0-9a-fA-F]{8}/

# Regular expression for finding hexadecimal double words (0000000000000000 - ffffffffffffffff).
#
# @since 1.2.0
HEX_QWORD = /(?:0x)?[0-9a-fA-F]{16}/

# 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 @@ -129,6 +129,36 @@
end
end

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

it "must match 0000000000000000 - ffffffffffffffff" do
expect("0000000000000000").to match(subject)
expect("ffffffffffffffff").to match(subject)
end

it "must match 0000000000000000 - FFFFFFFFFFFFFFFF" do
expect("0000000000000000").to match(subject)
expect("FFFFFFFFFFFFFFFF").to match(subject)
end

it "must match 0x0000000000000000 - 0xffffffffffffffff" do
expect("0x0000000000000000").to match(subject)
expect("0xffffffffffffffff").to match(subject)
end

it "must match 0x0000000000000000 - 0xFFFFFFFFFFFFFFFF" do
expect("0x0000000000000000").to match(subject)
expect("0xFFFFFFFFFFFFFFFF").to match(subject)
end

it "must only match eight hexadecimal digits" do
string = "1234567890abcdef11111"

expect(string[subject]).to eq("1234567890abcdef")
end
end

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

Expand Down

0 comments on commit 9780e69

Please sign in to comment.