Sha256: bf61d213ec1e5638df4f11a27c8822bd28232b74b5ade5a0867d874be9d00f70

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 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

4 entries across 4 versions & 1 rubygems

Version Path
headdesk-0.12.0 lib/headdesk/apktool.rb
headdesk-0.11.3 lib/headdesk/apktool.rb
headdesk-0.11.2 lib/headdesk/apktool.rb
headdesk-0.11.1 lib/headdesk/apktool.rb