Class: Ronin::Recon::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/recon/graph.rb

Overview

Represents a directed graph of discovered values and their parent values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the graph.



45
46
47
48
# File 'lib/ronin/recon/graph.rb', line 45

def initialize
  @nodes = Set.new
  @edges = {}
end

Instance Attribute Details

#edgesHash{Value => Set<Value>} (readonly)

The edges between nodes in the graph.

Returns:



38
39
40
# File 'lib/ronin/recon/graph.rb', line 38

def edges
  @edges
end

#nodesSet<Value> (readonly)

The nodes in the graph.

Returns:



33
34
35
# File 'lib/ronin/recon/graph.rb', line 33

def nodes
  @nodes
end

Instance Method Details

#[](value) ⇒ Set<Value>?

Fetches the parent value nodes for the value.

Parameters:

  • value (Value)

    The value node to lookup.

Returns:

  • (Set<Value>, nil)

    The set of parent value nodes or nil if the value does not exist in the graph.



112
113
114
# File 'lib/ronin/recon/graph.rb', line 112

def [](value)
  @edges[value]
end

#add_edge(new_value, parent_value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a value to the graph, if it already hasn't been added.

Parameters:

  • new_value (Value)

    The new value node to add.

  • parent_value (Value, nil)

    The parent value node of the new value node.

Returns:

  • (Boolean)

    Indicates whether the value node was successfully added to the graph, or if the value node was already added to the graph.



81
82
83
84
85
86
87
# File 'lib/ronin/recon/graph.rb', line 81

def add_edge(new_value,parent_value)
  if parent_value
    node_parents = (@edges[new_value] ||= Set.new)

    return !node_parents.add?(parent_value).nil?
  end
end

#add_node(new_value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a value to the graph, if it already hasn't been added.

Parameters:

  • new_value (Value)

    The new value node to add.

Returns:

  • (Boolean)

    Indicates whether the value node was successfully added to the graph, or if the value node was already added to the graph.



62
63
64
# File 'lib/ronin/recon/graph.rb', line 62

def add_node(new_value)
  !@nodes.add?(new_value).nil?
end

#empty?Boolean

Determines if the graph is empty.

Returns:

  • (Boolean)


121
122
123
# File 'lib/ronin/recon/graph.rb', line 121

def empty?
  @nodes.empty?
end

#include?(value) ⇒ Boolean

Determines if the value is in the graph.

Parameters:

  • value (Value)

    The value node.

Returns:

  • (Boolean)

    Indicates whether the value exists in the graph or not.



98
99
100
# File 'lib/ronin/recon/graph.rb', line 98

def include?(value)
  @nodes.include?(value)
end