Module: Metasploit::Model::Module::Path

Extended by:
ActiveModel::Naming, ActiveSupport::Concern
Includes:
NilifyBlanks, Translation
Defined in:
lib/metasploit/model/module/path.rb

Overview

Concern for sharing common code between Mdm::Module::Path and Metasploit::Framework::Module::Path. Define #gem, #name, and #real_path by following the abstract instructions for each attribute.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NilifyBlanks

#nilify_blanks

Instance Attribute Details

#gemString

This method is abstract.

In an ActiveModel, this should be an attr_accessor :gem. In an ActiveRecord, this should be a string gem column.

The name of the gem that is adding this module path to metasploit-framework. For paths normally added by metasploit-framework itself, this would be 'metasploit-framework', while for Metasploit Pro this would be 'metasploit-pro'. The name used for gem does not have to be a gem on rubygems, it just functions as a namespace for #name so that projects using metasploit-framework do not need to worry about collisions on #name which could disrupt the cache behavior.

Returns:

  • (String)


# File 'lib/metasploit/model/module/path.rb', line 51

#nameString

This method is abstract.

In an ActiveModel, this should be an attr_accessor :name. In an ActiveRecord, this should be a string name column.

The name of the module path scoped to #gem. #gem and #name uniquely identify this path so that if #real_path changes, the entire cache does not need to be invalidated because the change in #real_path will still be tied to the same (#gem, #name) tuple.

Returns:

  • (String)


# File 'lib/metasploit/model/module/path.rb', line 63

#real_pathString

This method is abstract.

In an ActiveModel, this should be an attr_accesor :real_path. In an ActiveRecord, this should

Note:

Non-real paths will be converted to real paths in a before validation callback, so take care to either pass real paths or pay attention when setting #real_path and then changing directories before validating.

be a text real_path column.

The real (absolute) path to module path.

Returns:

  • (String)


# File 'lib/metasploit/model/module/path.rb', line 73

Instance Method Details

#directoryvoid (private)

This method returns an undefined value.

Validates that either #directory? is true.



137
138
139
140
141
# File 'lib/metasploit/model/module/path.rb', line 137

def directory
  unless directory?
    errors[:real_path] << 'must be a directory'
  end
end

#directory?true, false

Returns whether #real_path is a directory.

Returns:



93
94
95
96
97
98
99
100
101
# File 'lib/metasploit/model/module/path.rb', line 93

def directory?
  directory = false

  if real_path and File.directory?(real_path)
    directory = true
  end

  directory
end

#gem_and_namevoid (private)

This method returns an undefined value.

Validates that either both #gem and #name are present or both are nil.



146
147
148
149
150
151
152
153
154
# File 'lib/metasploit/model/module/path.rb', line 146

def gem_and_name
  if name.present? and gem.blank?
    errors[:gem] << "can't be blank if name is present"
  end

  if gem.present? and name.blank?
    errors[:name] << "can't be blank if gem is present"
  end
end

#named?false, true

Returns whether is a named path.

Returns:

  • (false)

    if gem is blank or name is blank.

  • (true)

    if gem is not blank and name is not blank.



107
108
109
110
111
112
113
114
115
# File 'lib/metasploit/model/module/path.rb', line 107

def named?
  named = false

  if gem.present? and name.present?
    named = true
  end

  named
end

#normalize_real_pathvoid (private)

This method returns an undefined value.

If #real_path is set and exists on disk, then converts it to a real path to eliminate any symlinks.

See Also:



160
161
162
163
164
# File 'lib/metasploit/model/module/path.rb', line 160

def normalize_real_path
  if real_path and File.exist?(real_path)
    self.real_path = Metasploit::Model::File.realpath(real_path)
  end
end

#was_named?false, true

Returns whether was a named path. This is the equivalent of #named?, but checks the old, pre-change values for #gem and #name.

Returns:

  • (false)

    is gem_was is blank or name_was is blank.

  • (true)

    if gem_was is not blank and name_was is not blank.



122
123
124
125
126
127
128
129
130
# File 'lib/metasploit/model/module/path.rb', line 122

def was_named?
  was_named = false

  if gem_was.present? and name_was.present?
    was_named = true
  end

  was_named
end