module Resilience::CLI

Constants

OUTPUT_LABELS

Public Instance Methods

boot2offset() click to toggle source
# File lib/resilience/cli/disk.rb, line 34
def boot2offset
  setup_image
  mbr2offset if conf.mbr
  gpt2offset if conf.gpt
end
bytes_per_sector_output() click to toggle source
# File lib/resilience/cli/output.rb, line 66
def bytes_per_sector_output
  "#{image.bytes_per_sector.indented.yellow.bold} (#{OUTPUT_LABELS[:bps]})"
end
cluster_size_output() click to toggle source
# File lib/resilience/cli/output.rb, line 74
def cluster_size_output
  "#{image.cluster_size.indented.yellow.bold} (#{OUTPUT_LABELS[:bpc]})\n"
end
conf() click to toggle source
# File lib/resilience/cli/conf.rb, line 10
def conf
  Conf
end
create_output_dir!() click to toggle source
# File lib/resilience/cli/output.rb, line 52
def create_output_dir!
  return unless write_to_output_dir?
  Dir.mkdir(output_dir) unless File.directory?(output_dir)
end
default_options(option_parser) click to toggle source
# File lib/resilience/cli/default.rb, line 10
def default_options(option_parser)
  option_parser.on('-h', '--help', 'Print help message') do
    puts option_parser
    exit
  end
end
disk_options(option_parser) click to toggle source
# File lib/resilience/cli/disk.rb, line 10
def disk_options(option_parser)
  option_parser.on("-m", "--mbr", "Extract FS Info From MBR") do
    conf.mbr = true
  end

  option_parser.on("-g", "--gpt", "Extract FS Info From GUID Partition Table") do
    conf.gpt = true
  end
end
file_select_options(option_parser) click to toggle source
# File lib/resilience/cli/file.rb, line 10
def file_select_options(option_parser)
  option_parser.on("-f", "--file [file]", "File to analyze") do |file|
    conf.file = file
  end
end
gpt2offset() click to toggle source
# File lib/resilience/cli/disk.rb, line 27
def gpt2offset
  return unless conf.gpt
  image.offset = 0
  image.offset = MBR.new.gpt_offset
  image.offset = conf.offset = GPT.new.refs_offset
end
header_output() click to toggle source
# File lib/resilience/cli/output.rb, line 62
def header_output
  image_output + vbr_output
end
image() click to toggle source
# File lib/resilience/cli/image.rb, line 41
def image
  Resilience::OnImage.image
end
image_options(option_parser) click to toggle source
# File lib/resilience/cli/image.rb, line 10
def image_options(option_parser)
  option_parser.on("-i", "--image path", "Path to the disk image to parse") do |path|
    conf.image_file = path
  end

  option_parser.on("-o", "--offset bytes", "Start of volume with ReFS filesystem") do |offset|
    conf.offset = offset.to_i
  end
end
image_output() click to toggle source
# File lib/resilience/cli/output.rb, line 57
def image_output
  "#{OUTPUT_LABELS[:image]} #{conf.image_file.green.bold} "\
  "#{OUTPUT_LABELS[:offset]} #{conf.offset.to_s.green.bold}\n"
end
mbr2offset() click to toggle source
# File lib/resilience/cli/disk.rb, line 20
def mbr2offset
  return unless conf.mbr
  image.offset  = 0
  offset        = MBR.new.refs_offset
  conf[:offset] = offset unless offset.nil?
end
metadata_options(option_parser) click to toggle source
# File lib/resilience/cli/metadata.rb, line 10
def metadata_options(option_parser)
  option_parser.on("-a", "--attributes", "Include attribute analysis in output") do
    conf.attributes   = true
  end

  option_parser.on("--table", "Include object table analysis in output") do
    conf.object_table = true
  end

  option_parser.on("--tree", "Include object tree analysis in output") do
    conf.object_tree  = true
  end
end
output_dir() click to toggle source
# File lib/resilience/cli/output.rb, line 44
def output_dir
  conf.dir
end
output_fs_options(option_parser) click to toggle source
# File lib/resilience/cli/output.rb, line 21
def output_fs_options(option_parser)
  option_parser.on("--write dir", "Write output to directory") do |dir|
    conf.dir = dir
  end
end
parse_image() click to toggle source
# File lib/resilience/cli/image.rb, line 35
def parse_image
  setup_image
  image.parse
  image
end
sectors_per_cluster_output() click to toggle source
# File lib/resilience/cli/output.rb, line 70
def sectors_per_cluster_output
  "#{image.sectors_per_cluster.indented.yellow.bold} (#{OUTPUT_LABELS[:spc]})"
end
setup_image() click to toggle source
# File lib/resilience/cli/image.rb, line 27
def setup_image
  file         = File.open(conf.image_file, 'rb')
  image.file   = file
  image.offset = conf.offset
  image.opts   = conf
  image
end
stdout_options(option_parser) click to toggle source
# File lib/resilience/cli/output.rb, line 27
def stdout_options(option_parser)
  option_parser.on("-f", "--files", "List files in output") do
    conf.files = true
  end

  option_parser.on("-d", "--dirs", "List dirs in output") do
    conf.dirs = true
  end
end
vbr_output() click to toggle source
# File lib/resilience/cli/output.rb, line 78
def vbr_output
  "#{OUTPUT_LABELS[:vbr]}: #{bytes_per_sector_output} * "    \
                          "#{sectors_per_cluster_output} = " \
                          "#{cluster_size_output}"
end
verify_file!() click to toggle source
# File lib/resilience/cli/file.rb, line 16
def verify_file!
  unless conf.file
    puts "--file param needed"
    exit 1
  end
end
verify_image!() click to toggle source
# File lib/resilience/cli/image.rb, line 20
def verify_image!
  unless conf.image && conf.offset
    puts "--image and --offset params needed"
    exit 1
  end
end
verify_output_dir!() click to toggle source
# File lib/resilience/cli/output.rb, line 37
def verify_output_dir!
  unless conf.dir
    puts "--write param needed"
    exit 1
  end
end
write_to_output_dir?() click to toggle source
# File lib/resilience/cli/output.rb, line 48
def write_to_output_dir?
  !!output_dir
end