Class: Ronin::Vulns::SSTI::TestExpression
- Inherits:
-
Object
- Object
- Ronin::Vulns::SSTI::TestExpression
- Defined in:
- lib/ronin/vulns/ssti/test_expression.rb
Overview
Represents a expression to test SSTI with (ex: 7*7
).
Instance Attribute Summary collapse
-
#result ⇒ String
readonly
The expected result of the string.
-
#string ⇒ String
readonly
The expression string.
Class Method Summary collapse
-
.parse(string) ⇒ TestExpression
Parses an expression string and calculates the result.
Instance Method Summary collapse
-
#initialize(string, result) ⇒ TestExpression
constructor
Initializes the test expression.
-
#to_s ⇒ String
The test expression as a String.
Constructor Details
#initialize(string, result) ⇒ TestExpression
Initializes the test expression.
53 54 55 56 |
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 53 def initialize(string,result) @string = string @result = result end |
Instance Attribute Details
#result ⇒ String (readonly)
The expected result of the string.
42 43 44 |
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 42 def result @result end |
#string ⇒ String (readonly)
The expression string.
37 38 39 |
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 37 def string @string end |
Class Method Details
.parse(string) ⇒ TestExpression
Parses an expression string and calculates the result.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 70 def self.parse(string) unless (match = string.match(%r{\A(\d+)\s*([\*/\+\-])\s*(\d+)\z})) raise(ArgumentError,"could not parse the expression: #{string.inspect}") end lvalue = match[1].to_i op = match[2] rvalue = match[3].to_i result = case op when '*' then lvalue * rvalue when '/' then lvalue / rvalue when '+' then lvalue + rvalue when '-' then lvalue - rvalue else raise(NotImplementedError,"unsupported expression operator: #{op.inspect}") end return new(string,result.to_s) end |
Instance Method Details
#to_s ⇒ String
The test expression as a String.
97 98 99 |
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 97 def to_s @string end |