<commit_before>=begin
    Copyright 2010-2012 <NAME> <<EMAIL>>

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
=end

require Arachni::Options.instance.dir['lib'] + 'module/utilities'
require Arachni::Options.instance.dir['lib'] + 'module/key_filler'

module Arachni
class Parser
module Element
module Mutable

    include Arachni::Module::Utilities


    #
    # @return   [String]    name of the altered/mutated parameter
    #
    attr_accessor :altered

    #
    # Holds constant bitfields that describe the preferred formatting
    # of injection strings.
    #
    module Format

      #
      # Leaves the injection string as is.
      #
      STRAIGHT = 1 << 0

      #
      # Apends the injection string to the default value of the input vector.<br/>
      # (If no default value exists Arachni will choose one.)
      #
      APPEND   = 1 << 1

      #
      # Terminates the injection string with a null character.
      #
      NULL     = 1 << 2

      #
      # Prefix the string with a ';', useful for command injection modules
      #
      SEMICOLON = 1 << 3
    end

    # Default formatting and permutation options
    OPTIONS = {
        #
        # Formatting of the injection strings.
        #
        # A new set of audit inputs will be generated
        # for each value in the array.
        #
        # Values can be OR'ed bitfields of all available constants
        # of {Format}.
        #
        :format   => [ Format::STRAIGHT, Format::APPEND,
                       Format::NULL, Format::APPEND | Format::NULL ],


       # skip submission with default/original values (for {Arachni::Parser::Element::Form} elements)
       :skip_orig => false,

       # flip injection value and input name
       :param_flip => false
    }

    #
    # Injects the injecton_str in self's values according to formatting options
    # and returns an array of permutations of self.
    #
    # TODO: Move type specific mutations into their respective classes.
    #
    # @param    [String]  injection_str  the string to inject
    # @param    [Hash]    opts           {OPTIONS}
    #
    # @return    [Array]
    #
    def mutations( injection_str, opts = { } )

        opts = OPTIONS.merge( opts )
        hash = auditable.dup

        var_combo = []
        return [] if !hash || hash.size == 0

        if( self.is_a?( Arachni::Parser::Element::Form ) && !opts[:skip_orig] )

            if !audited?( audit_id( Arachni::Parser::Element::Form::FORM_VALUES_ORIGINAL ) )
                # this is the original hash, in case the default values<commit_msg>updated comments<commit_after>=begin
    Copyright 2010-2012 <NAME> <<EMAIL>>

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
=end

require Arachni::Options.instance.dir['lib'] + 'module/utilities'
require Arachni::Options.instance.dir['lib'] + 'module/key_filler'

module Arachni
class Parser
module Element
module Mutable

    include Arachni::Module::Utilities


    #
    # @return   [String]    name of the altered/mutated parameter
    #
    attr_accessor :altered

    #
    # Holds constant bitfields that describe the preferred formatting
    # of injection strings.
    #
    module Format

      #
      # Leaves the injection string as is.
      #
      STRAIGHT = 1 << 0

      #
      # Apends the injection string to the default value of the input vector.<br/>
      # (If no default value exists Arachni will choose one.)
      #
      APPEND   = 1 << 1

      #
      # Terminates the injection string with a null character.
      #
      NULL     = 1 << 2

      #
      # Prefix the string with a ';', useful for command injection modules
      #
      SEMICOLON = 1 << 3
    end

    # Default formatting and permutation options
    OPTIONS = {
        #
        # Formatting of the injection strings.
        #
        # A new set of audit inputs will be generated
        # for each value in the array.
        #
        # Values can be OR'ed bitfields of all available constants
        # of {Format}.
        #
        :format   => [ Format::STRAIGHT, Format::APPEND,
                       Format::NULL, Format::APPEND | Format::NULL ],


       # skip mutation with default/original values (for {Arachni::Parser::Element::Form} elements)
       :skip_orig => false,

       # flip injection value and input name
       :param_flip => false
    }

    #
    # Injects the injecton_str in self's values according to formatting options
    # and returns an array of permutations of self.
    #
    # TODO: Move type specific mutations into their respective classes.
    #
    # @param    [String]  injection_str  the string to inject
    # @param    [Hash]    opts           {OPTIONS}
    #
    # @return    [Array]
    #
    def mutations( injection_str, opts = { } )

        opts = OPTIONS.merge( opts )
        hash = auditable.dup

        var_combo = []
        return [] if !hash || hash.size == 0

        if( self.is_a?( Arachni::Parser::Element::Form ) && !opts[:skip_orig] )

            if !audited?( audit_id( Arachni::Parser::Element::Form::FORM_VALUES_ORIGINAL ) )
                # this is the original hash, in case the default values
{'fraction_non_alphanumeric': 0.0832658350882877, 'fraction_numerical': 0.006803823100599384, 'mean_word_length': 2.2875399361022364, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4807448', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1653, 'n_words': 628}