Class: Metasploit::Model::Search::Operation::Jsonb
- Defined in:
- app/models/metasploit/model/search/operation/jsonb.rb
Overview
Search operation with Base#operator with #type
':jsonb'.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#transform_value(input) ⇒ String
private
Transform an input String to a JSON if it contains a colon.
-
#value=(formatted_value) ⇒ String
Sets Base#value by parsing the
formatted_value
String and attempting to generate a valid JSON if it contains a colon.
Methods inherited from Base
Methods inherited from Base
Constructor Details
This class inherits a constructor from Metasploit::Model::Base
Instance Method Details
#transform_value(input) ⇒ String (private)
Transform an input String to a JSON if it contains a colon. It returns the String if not. Also, the first colon is used as a delimiter between the key and the value. Any subsequent colon will be part of the value. Finally, it handles double/single quotes to escape any colon that are not suppose to be a delimiter between the key and the value.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/metasploit/model/search/operation/jsonb.rb', line 36 def transform_value(input) # Regex to find the first colon that is NOT inside quotes match = input.match(/((?:[^'":]++|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')*?):(.*)/) # If no valid colon is found, return the original string return input unless match key = match[1].strip # Extract key (before first valid colon) value = match[2].strip # Extract value (after first valid colon) # Remove starting and ending quotes and ensure they are valid JSON strings key = key.gsub(/^["'](.*)["']$/, '\1').to_json value = value.gsub(/^["'](.*)["']$/, '\1').to_json "{#{key}: #{value}}" end |
#value=(formatted_value) ⇒ String
Sets Base#value by parsing the formatted_value
String and attempting to generate a valid JSON if it contains a colon.
Otherwise, it keeps the same value as a String.
21 22 23 |
# File 'app/models/metasploit/model/search/operation/jsonb.rb', line 21 def value=(formatted_value) @value = transform_value(formatted_value.to_s) end |