Sha256: 26027f02c405865d59288541782c67e57cd26b5308cfef0e0d3fc0837fa9ab9c

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/interface'

module Contrast
  module Agent
    # This module is used to apply instrumentation to classes as they are required
    module TracePointHook
      include Contrast::Components::Interface

      access_component :logging, :scope

      class << self
        def enable!
          @require_hook ||= TracePoint.new(:end) do |tracepoint_event|
            process(tracepoint_event)
          end

          @require_hook.enable
          logger.debug('Enabled :end event tracing')
        end

        def disable
          instance_variable_defined?(:@require_hook) && @require_hook.disable
        end

        private

        def process tracepoint_event
          with_contrast_scope do
            logger.trace('Received TracePoint end event', module: tracepoint_event.self.to_s)

            loaded_module = tracepoint_event.self
            path = tracepoint_event.path
            return if path&.include?('contrast')

            Contrast::Utils::InventoryUtil.inventory_class(path) if path
            Contrast::Agent::Patching::Policy::Patcher.patch_specific_module(loaded_module)
            Contrast::Agent::Assess::Policy::RewriterPatch.rewrite_interpolation(loaded_module)
            Contrast::Agent::Assess::Policy::PolicyScanner.scan(tracepoint_event)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contrast-agent-3.16.0 lib/contrast/agent/tracepoint_hook.rb
contrast-agent-3.15.0 lib/contrast/agent/tracepoint_hook.rb
contrast-agent-3.14.0 lib/contrast/agent/tracepoint_hook.rb