Class: ApkAnalyzer::Analyzer
- Inherits:
-
Object
- Object
- ApkAnalyzer::Analyzer
- Defined in:
- lib/apk_analyzer/analyzer.rb
Constant Summary collapse
- HEX_FALSE =
'0x0'.freeze
- HEX_TRUE =
'0xffffffff'.freeze
- REQUIRED =
'required'.freeze
- GL_ES_VERSION =
'glEsVersion'- NAME =
'name'- ACTION =
'action'- CATEGORY =
'category'- ANDROID_MANIFEST_FILE =
'AndroidManifest.xml'
Instance Method Summary collapse
-
#collect_cert_info ⇒ Object
Certificate info.
- #collect_manifest_info ⇒ Object
-
#initialize(file_path) ⇒ Analyzer
constructor
A new instance of Analyzer.
Constructor Details
#initialize(file_path) ⇒ Analyzer
Returns a new instance of Analyzer.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/apk_analyzer/analyzer.rb', line 17 def initialize(file_path) # Deactivating invalid date warnings in zip for apktools gem and apk analyzer code Zip.warn_invalid_date = false @file_path = file_path raise 'File is not a valid file' unless valid_zip?(file_path) case File.extname(file_path) when ".apk" @manifest = ApkXml.new(file_path).parse_xml('AndroidManifest.xml', true, true) when ".aab" String bundle_tool_location = %x[ #{"which bundletool"} ] raise 'Bundletool is not installed & available in your path' if bundle_tool_location.nil? or bundle_tool_location.length == 0 cmd = "bundletool dump manifest --bundle #{file_path}" @manifest = %x[ #{cmd} ] else raise 'unknown platform technology' end end |
Instance Method Details
#collect_cert_info ⇒ Object
Certificate info. Issuer and dates
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/apk_analyzer/analyzer.rb', line 80 def collect_cert_info # Redirect keytool check error to /dev/null os_has_keytool = system('keytool 2>/dev/null') raise 'keytool dependency not satisfied. Make sure that JAVA keytool utility is installed' unless os_has_keytool cert_info = {} certificate_raw = `keytool -printcert -rfc -jarfile #{@file_path.shellescape}` certificate_content_regexp = /(-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----)/m matched_data = certificate_content_regexp.match(certificate_raw) if matched_data certificate_content = matched_data.captures[0] cert_info = { issuer_raw: nil, cn: nil, ou: nil, o: nil, st: nil, l: nil, c: nil, creation_date: nil, expiration_date: nil } cert_extract_dates(certificate_content, cert_info) cert_extract_issuer(certificate_content, cert_info) else puts 'Failed to find CERT.RSA file' end cert_info end |
#collect_manifest_info ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/apk_analyzer/analyzer.rb', line 35 def collect_manifest_info manifest_file_path = find_file(ANDROID_MANIFEST_FILE) raise 'Failed to find Manifest file' if manifest_file_path.nil? begin manifest_xml = Nokogiri::XML(@manifest) rescue => e puts "Failed to parse #{ANDROID_MANIFEST_FILE}" log_expection e end manifest_info = {} begin manifest_info[:path] = manifest_file_path content = {} # application content content[:application_info] = collect_application_info(manifest_xml) # intents content[:intents] = collect_intent_info(manifest_xml) # sdk infos sdk_infos = collect_sdk_info(manifest_xml) content[:uses_sdk] = { minimum_sdk_version: sdk_infos[0], target_sdk_version: sdk_infos[1] } # uses permission = (manifest_xml) content[:uses_permissions] = # uses features feature_list = collect_uses_feature_info(manifest_xml) content[:uses_features] = feature_list # screen compatibility supported_screens = collect_supported_screens(manifest_xml) content[:supports_screens] = supported_screens manifest_info[:content] = content rescue => e log_expection e raise "Invalid xml found" end manifest_info end |