Sha256: 7b20df52b664920527f47cb291eb742893e48da618a0b7a14c1073a6d8b7e1b3

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'open3'

module Headdesk
  #
  # Wrapper around using https://ibotpeaches.github.io/Apktool/
  #
  class ApkTool
    def self.apktool_jar
      "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

13 entries across 13 versions & 1 rubygems

Version Path
headdesk-0.11.0 lib/headdesk/apktool.rb
headdesk-0.10.0 lib/headdesk/apktool.rb
headdesk-0.9.0 lib/headdesk/apktool.rb
headdesk-0.8.0 lib/headdesk/apktool.rb
headdesk-0.7.0 lib/headdesk/apktool.rb
headdesk-0.6.0 lib/headdesk/apktool.rb
headdesk-0.5.2 lib/headdesk/apktool.rb
headdesk-0.5.1 lib/headdesk/apktool.rb
headdesk-0.5.0 lib/headdesk/apktool.rb
headdesk-0.4.0 lib/headdesk/apktool.rb
headdesk-0.3.0 lib/headdesk/apktool.rb
headdesk-0.2.0 lib/headdesk/apktool.rb
headdesk-0.1.0 lib/headdesk/apktool.rb