Class: Necropsy::Analyzers::Static::CHA

Inherits:
Necropsy::Analyzer show all
Defined in:
lib/necropsy/analyzers/static/cha.rb

Instance Method Summary collapse

Instance Method Details

#analyze(graph, _project) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/necropsy/analyzers/static/cha.rb', line 7

def analyze(graph, _project)
  edge_evidences = []
  resolutions = graph.call_sites.map do |site|
    lookup = graph.cha_method_lookup(site)
    targets = lookup.targets
    site_edges = targets.map do |candidate|
      EdgeEvidence.new(
        caller_id: site.caller_id,
        callee_id: candidate.graph_id,
        evidence: evidence(
          kind: :call_edge,
          details: "CHA candidate at #{site.file}:#{site.line}",
          metadata: site.to_h.merge('target_definition_id' => candidate.graph_id),
          grade: :conservative,
          relation: :call_edge,
          source: call_site_evidence_source(site).merge('target_definition_id' => candidate.graph_id),
          scope: call_site_evidence_scope(site).merge('target_definition_id' => candidate.graph_id)
        )
      )
    end
    edge_evidences.concat(site_edges)
    status = if lookup.complete?
               :complete
             else
               (targets.empty? ? :unknown : :partial)
             end
    resolution_record(
      site,
      targets,
      site_edges,
      status: status,
      rejected_targets: lookup.complete? ? lookup.rejected_targets : [],
      unknown_scope: graph.residual_scope_for(site)
    )
  end

  AnalyzerResult.new(
    edge_evidences: edge_evidences,
    alive_evidences: [],
    uncertainties: {},
    observation: {},
    resolutions: resolutions,
    evidences: result_evidences(edge_evidences)
  )
end

#capabilitiesObject



64
65
66
# File 'lib/necropsy/analyzers/static/cha.rb', line 64

def capabilities
  [:complete_resolution].freeze
end

#profileObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/necropsy/analyzers/static/cha.rb', line 53

def profile
  AnalyzerProfile.new(
    name: :cha,
    kind: :static,
    soundness: :conservative,
    description: 'Expands call targets through class hierarchy, descendants, and included/prepended modules.',
    version: Necropsy::VERSION,
    assumptions: %w[closed_scanned_hierarchy loaded_ancestry]
  )
end