class DroidAdbs::Apkanalyzer

Attributes

apk_path[R]

Public Class Methods

new(apk_path) click to toggle source
# File lib/droid_adbs/apkanalyzer.rb, line 7
def initialize(apk_path)
  raise RuntimeError, "should set path to aapt, android-sdks/build-tools/xxxx" if `which apkanalyzer`.empty?

  @apk_path = apk_path
end

Public Instance Methods

apk_compare_print(with) click to toggle source

Compares the sizes of two APKs.

# File lib/droid_adbs/apkanalyzer.rb, line 131
def apk_compare_print(with)
  puts `#{command_apk} features #{@apk_path} #{with}`.strip
end
apk_download_size() click to toggle source

Prints an estimate of the download size of the APK.

@example

apk_download_size #=> 7313000
# File lib/droid_adbs/apkanalyzer.rb, line 116
def apk_download_size
  `#{command_apk} download-size #{@apk_path}`.strip
end
apk_features() click to toggle source

Prints features used by the APK.

@example

apk_features #=> "android.hardware.faketouch implied: default feature for all apps"
# File lib/droid_adbs/apkanalyzer.rb, line 126
def apk_features
  puts `#{command_apk} features #{@apk_path}`.strip
end
apk_file_size() click to toggle source

Prints the file size of the APK. 7_414_686 (byte)

# File lib/droid_adbs/apkanalyzer.rb, line 106
def apk_file_size
  `#{command_apk} file-size #{@apk_path}`.strip
end
apk_summary() click to toggle source

Prints the application Id, version code and version name.

@example

apk_summary #=> ["com.vodqareactnative", "1", "1.0"]
# File lib/droid_adbs/apkanalyzer.rb, line 100
def apk_summary
  `#{command_apk} summary #{@apk_path}`.strip.split("\t")
end
dex_code() click to toggle source

Prints the bytecode of a class or method in smali format

# File lib/droid_adbs/apkanalyzer.rb, line 163
def dex_code
  `#{command_dex} code #{@apk_path}`.strip
end
dex_list() click to toggle source

Prints a list of dex files in the APK

# File lib/droid_adbs/apkanalyzer.rb, line 146
def dex_list
  `#{command_dex} list #{@apk_path}`.strip.split("\n")
end
dex_packages(options = "") click to toggle source

Prints the class tree from DEX. P,C,M,F: indicates packages, classes methods, fields x,k,r,d: indicates removed, kept, referenced and defined nodes

# File lib/droid_adbs/apkanalyzer.rb, line 158
def dex_packages(options = "")
  `#{command_dex} packages #{options} #{@apk_path}`.strip
end
dex_references(options = "") click to toggle source

Prints number of references in dex files

# File lib/droid_adbs/apkanalyzer.rb, line 151
def dex_references(options = "")
  `#{command_dex} references #{options} #{@apk_path}`.strip
end
file_list() click to toggle source

Lists all files in the zip.

@example

file_list #=> "android.hardware.faketouch implied: default feature for all apps"
# File lib/droid_adbs/apkanalyzer.rb, line 141
def file_list
  `apkanalyzer files list #{@apk_path}`.strip.split("\n")
end
manifest_debuggable() click to toggle source

@return [Bool] Debuggable or not

@example

manifest_debuggable #=> true
# File lib/droid_adbs/apkanalyzer.rb, line 88
def manifest_debuggable
  result = `#{command_manifest} debuggable #{@apk_path}`.strip
  return true if result == "true"
  false
end
manifest_min_sdk() click to toggle source

@return [String] A number of min sdk by string

@example

manifest_min_sdk #=> "16"
# File lib/droid_adbs/apkanalyzer.rb, line 58
def manifest_min_sdk
  `#{command_manifest} min-sdk #{@apk_path}`.strip
end
manifest_package_id() click to toggle source

@return [String] package name

@example

manifest_package_id #=> "io.appium.android.apis"
# File lib/droid_adbs/apkanalyzer.rb, line 19
def manifest_package_id
  `#{command_manifest} application-id #{@apk_path}`.strip
end
manifest_permissions() click to toggle source

@return [[String]] A list of permissions

@example

manifest_permissions #=> ["android.permission.INTERNET", "android.permission.SYSTEM_ALERT_WINDOW", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_PHONE_STATE"]
# File lib/droid_adbs/apkanalyzer.rb, line 78
def manifest_permissions
  `#{command_manifest} permissions #{@apk_path}`.strip.split("\n")
end
manifest_print(out_path = './manifest_print.xml') click to toggle source

@param [String] out_path A path to output the result @return [Integer] A number of file size

# File lib/droid_adbs/apkanalyzer.rb, line 27
def manifest_print(out_path = './manifest_print.xml')
  result = `#{command_manifest} print #{@apk_path}`.strip
  File.write out_path, result
end
manifest_target_sdk() click to toggle source

@return [String] A number of target sdk by string

@example

manifest_target_sdk #=> "22"
# File lib/droid_adbs/apkanalyzer.rb, line 68
def manifest_target_sdk
  `#{command_manifest} target-sdk #{@apk_path}`.strip
end
manifest_version_code() click to toggle source

@return [String] A number of version code by string

@example

manifest_version_code #=> "1"
# File lib/droid_adbs/apkanalyzer.rb, line 48
def manifest_version_code
  `#{command_manifest} version-code #{@apk_path}`.strip
end
manifest_version_name() click to toggle source

@return [String] A number of version name by string

@example

manifest_version_name #=> "1.0"
# File lib/droid_adbs/apkanalyzer.rb, line 38
def manifest_version_name
  `#{command_manifest} version-name #{@apk_path}`.strip
end
resources_configs(type, package = "") click to toggle source

Prints a list of configurations for the specified type. @param [String] type The type is a resource type such as string. @param [String] package Include the –package option if you want to specify the resource table package name,

otherwise the first defined package will be used.
# File lib/droid_adbs/apkanalyzer.rb, line 177
def resources_configs(type, package = "")
  `#{command_resources} configs --type #{type} #{package} #{@apk_path}`.strip
end
resources_packages() click to toggle source

Prints a list of packages in resources table

# File lib/droid_adbs/apkanalyzer.rb, line 168
def resources_packages
  `#{command_resources} packages #{@apk_path}`.strip
end
resources_value(config, name, type, package = "") click to toggle source

Prints the value of the resource specified by config, name, and type. @param [String] config @param [String] name @param [String] type The type option is the type of the resource, such as string. @param [String] package Include the –package option if you want to specify the resource table package name,

otherwise the first defined package will be used.

@example

resources_value "default", "revision_hash", "string"
# File lib/droid_adbs/apkanalyzer.rb, line 192
def resources_value(config, name, type, package = "")
  `#{command_resources} value --config #{config} --name #{name} --type #{type} #{package} #{@apk_path}`.strip
end
resources_xml(xml_file) click to toggle source

Prints the human-readable form of a binary XML file. Include the file option to specify the path to the file.

# File lib/droid_adbs/apkanalyzer.rb, line 197
def resources_xml(xml_file)
  `#{command_resources} xml --file #{xml_file} #{@apk_path}`.strip
end

Private Instance Methods

command_apk() click to toggle source
# File lib/droid_adbs/apkanalyzer.rb, line 207
def command_apk
  'apkanalyzer apk'
end
command_dex() click to toggle source
# File lib/droid_adbs/apkanalyzer.rb, line 211
def command_dex
  'apkanalyzer dex'
end
command_manifest() click to toggle source
# File lib/droid_adbs/apkanalyzer.rb, line 203
def command_manifest
  'apkanalyzer manifest'
end
command_resources() click to toggle source
# File lib/droid_adbs/apkanalyzer.rb, line 215
def command_resources
  'apkanalyzer resources'
end