VulnCheck.Beam.CallGraph (VulnCheck v1.0.1)

Copy Markdown View Source

Immutable call graph indexed by caller and callee.

Built from module summaries: static and resolved dynamic edges, {M, F, A} references and, for modules without debug info, over-approximated edges from every exported function to every imported function (:imports). Further edges (behaviour callbacks, supervisor children, ...) are added with add_edges/2.

Summary

Functions

Adds edges to the graph. Duplicate pairs prefer proven edges, with ties keeping the first edge.

Builds the graph from summaries (a map keyed by module name or a list).

Incoming edges of a function.

Number of distinct edges.

Outgoing edges of a function.

Returns true when the module was loaded from a .beam file.

All functions reachable from roots (MFAs or entrypoints), roots included.

Modules containing at least one reachable function.

Finds a shortest call chain (fewest hops) from any root to any target.

Types

t()

@type t() :: %VulnCheck.Beam.CallGraph{
  in_edges: %{
    required(VulnCheck.Types.MFA.t()) => [VulnCheck.Types.CallEdge.t()]
  },
  modules: %{required(String.t()) => VulnCheck.Types.ModuleSummary.t()},
  out_edges: %{
    required(VulnCheck.Types.MFA.t()) => [VulnCheck.Types.CallEdge.t()]
  },
  pairs: %{
    required({VulnCheck.Types.MFA.t(), VulnCheck.Types.MFA.t()}) => boolean()
  }
}

Functions

add_edges(graph, edges)

@spec add_edges(t(), [VulnCheck.Types.CallEdge.t()]) :: t()

Adds edges to the graph. Duplicate pairs prefer proven edges, with ties keeping the first edge.

build(summaries, opts \\ [])

@spec build(
  %{required(String.t()) => VulnCheck.Types.ModuleSummary.t()}
  | [VulnCheck.Types.ModuleSummary.t()],
  keyword()
) :: t()

Builds the graph from summaries (a map keyed by module name or a list).

callers(call_graph, mfa)

Incoming edges of a function.

edge_count(call_graph)

@spec edge_count(t()) :: non_neg_integer()

Number of distinct edges.

edges_from(call_graph, mfa)

@spec edges_from(t(), VulnCheck.Types.MFA.t()) :: [VulnCheck.Types.CallEdge.t()]

Outgoing edges of a function.

module?(call_graph, module)

@spec module?(t(), String.t()) :: boolean()

Returns true when the module was loaded from a .beam file.

reachable(graph, roots)

All functions reachable from roots (MFAs or entrypoints), roots included.

reachable_modules(reachable)

@spec reachable_modules(MapSet.t(VulnCheck.Types.MFA.t())) :: MapSet.t(String.t())

Modules containing at least one reachable function.

shortest_path(graph, roots, targets)

Finds a shortest call chain (fewest hops) from any root to any target.

Returns {:ok, hops} where the first hop is the entrypoint and every following hop carries the call site (file:line) in its caller and the kind of the edge, or :none.