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 48

#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 60

#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 70

Instance Method Details

#directoryvoid (private)

This method returns an undefined value.

Validates that either #directory? is true.



134
135
136
137
138
# File 'lib/metasploit/model/module/path.rb', line 134

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

#directory?true, false

Returns whether #real_path is a directory.

Returns:



90
91
92
93
94
95
96
97
98
# File 'lib/metasploit/model/module/path.rb', line 90

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.



143
144
145
146
147
148
149
150
151
# File 'lib/metasploit/model/module/path.rb', line 143

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.



104
105
106
107
108
109
110
111
112
# File 'lib/metasploit/model/module/path.rb', line 104

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:



157
158
159
160
161
# File 'lib/metasploit/model/module/path.rb', line 157

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.



119
120
121
122
123
124
125
126
127
# File 'lib/metasploit/model/module/path.rb', line 119

def was_named?
  was_named = false

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

  was_named
end