Module: Resilience::CLI
- Defined in:
- lib/resilience/cli/conf.rb,
lib/resilience/cli/disk.rb,
lib/resilience/cli/file.rb,
lib/resilience/cli/image.rb,
lib/resilience/cli/output.rb,
lib/resilience/cli/default.rb,
lib/resilience/cli/metadata.rb
Constant Summary collapse
- OUTPUT_LABELS =
{ :bps => "(bytes per sector)", :spc => "(sectors per cluster)", :bpc => "(bytes per cluster)", :vbr => "VBR", :image => "Analyzed ReFS filesystem on", :offset => "starting at" }
Instance Method Summary collapse
- #boot2offset ⇒ Object
- #bytes_per_sector_output ⇒ Object
- #cluster_size_output ⇒ Object
- #conf ⇒ Object
- #create_output_dir! ⇒ Object
- #default_options(option_parser) ⇒ Object
- #disk_options(option_parser) ⇒ Object
- #file_select_options(option_parser) ⇒ Object
- #gpt2offset ⇒ Object
- #header_output ⇒ Object
- #image ⇒ Object
- #image_options(option_parser) ⇒ Object
- #image_output ⇒ Object
- #mbr2offset ⇒ Object
- #metadata_options(option_parser) ⇒ Object
- #output_dir ⇒ Object
- #output_fs_options(option_parser) ⇒ Object
- #parse_image ⇒ Object
- #sectors_per_cluster_output ⇒ Object
- #setup_image ⇒ Object
- #stdout_options(option_parser) ⇒ Object
- #vbr_output ⇒ Object
- #verify_file! ⇒ Object
- #verify_image! ⇒ Object
- #verify_output_dir! ⇒ Object
- #write_to_output_dir? ⇒ Boolean
Instance Method Details
#boot2offset ⇒ Object
34 35 36 37 38 |
# 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 ⇒ Object
66 67 68 |
# 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 ⇒ Object
74 75 76 |
# File 'lib/resilience/cli/output.rb', line 74 def cluster_size_output "#{image.cluster_size.indented.yellow.bold} (#{OUTPUT_LABELS[:bpc]})\n" end |
#conf ⇒ Object
10 11 12 |
# File 'lib/resilience/cli/conf.rb', line 10 def conf Conf end |
#create_output_dir! ⇒ Object
52 53 54 55 |
# 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) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/resilience/cli/default.rb', line 10 def (option_parser) option_parser.on('-h', '--help', 'Print help message') do puts option_parser exit end end |
#disk_options(option_parser) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/resilience/cli/disk.rb', line 10 def (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) ⇒ Object
10 11 12 13 14 |
# File 'lib/resilience/cli/file.rb', line 10 def (option_parser) option_parser.on("-f", "--file [file]", "File to analyze") do |file| conf.file = file end end |
#gpt2offset ⇒ Object
27 28 29 30 31 32 |
# 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 ⇒ Object
62 63 64 |
# File 'lib/resilience/cli/output.rb', line 62 def header_output image_output + vbr_output end |
#image ⇒ Object
41 42 43 |
# File 'lib/resilience/cli/image.rb', line 41 def image Resilience::OnImage.image end |
#image_options(option_parser) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/resilience/cli/image.rb', line 10 def (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 ⇒ Object
57 58 59 60 |
# 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 ⇒ Object
20 21 22 23 24 25 |
# 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) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/resilience/cli/metadata.rb', line 10 def (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 ⇒ Object
44 45 46 |
# File 'lib/resilience/cli/output.rb', line 44 def output_dir conf.dir end |
#output_fs_options(option_parser) ⇒ Object
21 22 23 24 25 |
# File 'lib/resilience/cli/output.rb', line 21 def (option_parser) option_parser.on("--write dir", "Write output to directory") do |dir| conf.dir = dir end end |
#parse_image ⇒ Object
35 36 37 38 39 |
# File 'lib/resilience/cli/image.rb', line 35 def parse_image setup_image image.parse image end |
#sectors_per_cluster_output ⇒ Object
70 71 72 |
# 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 ⇒ Object
27 28 29 30 31 32 33 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/resilience/cli/output.rb', line 27 def (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 ⇒ Object
78 79 80 81 82 |
# 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! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/resilience/cli/file.rb', line 16 def verify_file! unless conf.file puts "--file param needed" exit 1 end end |
#verify_image! ⇒ Object
20 21 22 23 24 25 |
# 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! ⇒ Object
37 38 39 40 41 42 |
# 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? ⇒ Boolean
48 49 50 |
# File 'lib/resilience/cli/output.rb', line 48 def write_to_output_dir? !!output_dir end |