class Headdesk::ApkTool

Wrapper around using ibotpeaches.github.io/Apktool/

Public Class Methods

apktool_jar() click to toggle source
# File lib/headdesk/apktool.rb, line 10
def self.apktool_jar
  File.join(File.dirname(__FILE__), '..', '..',
            "ext/apktool_#{APKTOOL_VERSION}.jar")
end
cmd(*args) click to toggle source

Run apktool command

:reek: TooManyStatements

# File lib/headdesk/apktool.rb, line 19
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
unpack_to(path, destination) click to toggle source

Unpacks an APK to the specified path

:reek: TooManyStatements

# File lib/headdesk/apktool.rb, line 34
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