Sha256: 0b2e2aa1a25a422900accb37919b62634d8d8971ad875e7c38cbab3b54bf21e8

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

class SmcUtil::FileExtractor
  OUTPUT_FILE_FLAGS = File::CREAT | File::TRUNC | File::WRONLY

  def initialize(file_reader)
    @file_reader = file_reader
  end


  def extract_to(path)
    File.open(path, OUTPUT_FILE_FLAGS) do |file|
      @file_reader.regions.each do |region|
        range_bytes = region.offset - file.pos
        file.write "\0" * range_bytes if range_bytes > 0
        file.seek region.offset
        file.write region.data
      end
    end
  end

  def shred_to(path)
    Dir.mkdir(path) unless Dir.exists? path

    pass = position = 0

    @file_reader.regions.each do |region|
      pass += 1 if region.offset < position
      position = region.offset

      filename = File.join(path, "#{region.offset.to_s(16)}_pass#{pass}.bin")

      File.open(filename, OUTPUT_FILE_FLAGS) do |file|
        file.write region.data
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smcutil-0.1.5 lib/smcutil/file_extractor.rb