Sha256: 26216434ddc7de292d05b041f1905160d146712b62d46472d0a075d58909969c

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'openssl'

module MooTool
  # Module for Apple's IMG4 encryption and signing format
  module Img4
    # An instance of a IMG4 file
    class File
      attr_reader :payload, :manifest

      def initialize(path)
        @path = path
        der = ::File.binread(path)
        @data = OpenSSL::ASN1.decode(der)

        case @data.first.value
        when 'IM4P'
          @type = @data.value[1].value
          @build = @data.value[2].value
          @payload = @data.value[3].value
        when 'IMG4', 'IM4M'
          raise 'Not implemented'
        else
          raise "Unknown IMG4 type #{@data.first.value}"
        end
      end

      def payload?
        !@payload.nil?
      end

      def manifest?
        !@manifest.nil?
      end

      def basename
        basename = ::File.basename(@path)
        extension = ::File.extname(basename)
        "#{basename.chomp(extension)}.#{@type}"
      end

      def extract_payload
        output_path = ::File.join(::File.dirname(@path), basename)
        ::File.write(output_path, @payload)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mootool-0.2.3 lib/mootool/models/img4.rb
mootool-0.2.2 lib/mootool/models/img4.rb
mootool-0.2.1 lib/mootool/models/img4.rb
mootool-0.2 lib/mootool/models/img4.rb