Writing Ronin Ruby Scripts - Archives

Table of Contents

Tar

ronin-support provides methods for reading and writing .tar archives:

File.untar('file.tar') do |tar|
  tar.each do |entry|
    puts entry.full_name
    puts '-' * 80
    puts entry.read
    puts '-' * 80
  end
end

File.tar('output.tar') do |tar|
  tar.mkdir('foo')
  tar.add_file('foo/bar.txt','Hello World!')
end

See the documentation for File for a complete list of available methods.

Zip

ronin-support provides methods for reading and writing .zip archives:

File.unzip('file.zip') do |zip|
  zip.each do |entry|
    puts entry.name
    puts '-' * 80
    puts entry.read
    puts '-' * 80
  end
end

File.zip('output.zip') do |zip|
  zip.add_file('foo/bar.txt','Hello World!')
end

See the documentation for File for a complete list of available methods.

Mixin module

If you prefer using functions instead of the String or File methods, you can include the Ronin::Support::Archive::Mixin module.

require 'ronin/support/archive/mixin'
include Ronin::Support::Archive::Mixin

tar = tar_stream(io)
tar = tar_stream(io, mode: 'w')

tar = tar_open(path)
tar = tar_open(path, mode: 'w')

tar = untar('file.tar') # alias for tar_open(path)
tar = tar('output.tar') # alias for tar_open(path, mode: 'w')

zip = zip_open(path)
zip = zip_open(path, mode: 'w')

zip = unzip('file.zip') # alias for zip_open(path)
zip = zip('output.zip') # alias for zip_open(path, mode: 'w')