Sha256: 6fecb6e7dcb3a197ce30d6a1ba3ffa3c209da502c75fecd425777ead08bc73ae

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require 'open3'

module Headdesk
  #
  # Wrapper around using https://ibotpeaches.github.io/Apktool/
  #
  class ApkTool
    def self.apktool_jar
      File.join(File.dirname(__FILE__), '..', '..',
                "ext/apktool_#{APKTOOL_VERSION}.jar")
    end

    #
    # Run apktool command
    #
    # :reek:TooManyStatements
    def self.cmd(*args)
      _stdin, stdout, stderr, wait_thr = Open3.popen3('java', '-jar', apktool_jar, *args)
      r_stdout = stdout.gets(nil)
      stdout.close
      r_stderr = stderr.gets(nil)
      stderr.close
      r_exit_code = wait_thr.value

      [r_stdout, r_stderr, r_exit_code]
    end

    #
    # Unpacks an APK to the specified path
    #
    # :reek:TooManyStatements
    def self.unpack_to(path, destination)
      throw CliError.new("File not found: #{path}") unless File.exist?(path)
      throw CliError.new("Path not found: #{destination}") unless Dir.exist?(destination)

      args = ['d', '--force', '--output', destination]

      stdout, stderr, exit_code = Headdesk::ApkTool.cmd(*args, path)
      raise stderr unless exit_code.to_i.zero?

      stdout
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
headdesk-0.17.0 lib/headdesk/apktool.rb
headdesk-0.16.2 lib/headdesk/apktool.rb
headdesk-0.16.1 lib/headdesk/apktool.rb
headdesk-0.16.0 lib/headdesk/apktool.rb
headdesk-0.15.1 lib/headdesk/apktool.rb
headdesk-0.15.0 lib/headdesk/apktool.rb
headdesk-0.14.0 lib/headdesk/apktool.rb
headdesk-0.13.0 lib/headdesk/apktool.rb