Class: Ronin::Exploits::Loot::File Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/exploits/loot/file.rb

Overview

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

Represents a loot file.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, contents, format: nil) ⇒ File

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 loot file.

Parameters:

  • path (String)

    The file name or relative path of the loot file.

  • contents (String, Array, Hash, #to_s)

    The contents of the loot file.

  • format (:json, :yaml, :csv, nil) (defaults to: nil)

    The optional output format to serialize the loot file data as.

Since:

  • 1.0.0



66
67
68
69
70
# File 'lib/ronin/exploits/loot/file.rb', line 66

def initialize(path,contents, format: nil)
  @path     = path
  @contents = contents
  @format   = format
end

Instance Attribute Details

#contentsString, ... (readonly)

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.

The contents of the loot file.

Returns:

  • (String, Array, Hash, #to_s)

Since:

  • 1.0.0



47
48
49
# File 'lib/ronin/exploits/loot/file.rb', line 47

def contents
  @contents
end

#format:json, ... (readonly)

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.

The desired output format for the loot file.

Returns:

  • (:json, :yaml, :csv, nil)

Since:

  • 1.0.0



52
53
54
# File 'lib/ronin/exploits/loot/file.rb', line 52

def format
  @format
end

#pathString (readonly)

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.

The file name or relative path of the loot file.

Returns:

  • (String)

Since:

  • 1.0.0



42
43
44
# File 'lib/ronin/exploits/loot/file.rb', line 42

def path
  @path
end

Instance Method Details

#save(output_dir) ⇒ Object

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.

Saves the loot file to the output directory.

Parameters:

  • output_dir (String)

    The output directory to save the loot file into.

Since:

  • 1.0.0



104
105
106
107
108
109
# File 'lib/ronin/exploits/loot/file.rb', line 104

def save(output_dir)
  absolute_path = ::File.join(output_dir,@path)

  FileUtils.mkdir_p(::File.dirname(absolute_path))
  ::File.binwrite(absolute_path,self.to_s)
end

#to_sString

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.

Converts the loot file into a String.

Returns:

  • (String)

    The contents of the loot file.

Raises:

  • (NotImplementedError)

    The #format value is not supported.

Since:

  • 1.0.0



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ronin/exploits/loot/file.rb', line 81

def to_s
  case @format
  when :json then JSON.pretty_generate(@contents)
  when :yaml then YAML.dump(@contents)
  when :csv
    CSV.generate do |csv|
      @contents.each do |row|
        csv << row
      end
    end
  when nil
    @contents.to_s
  else
    raise(NotImplementedError,"unsupported loot format: #{@format.inspect}")
  end
end