apk_analyzer 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c9a78dc35d71f81551f39123658300a1b79d18dd
4
- data.tar.gz: f16422da7e2bccaaf082c12a83580f9041cceafa
2
+ SHA256:
3
+ metadata.gz: ac5bc2cca1e0b89f39f38992fffcca1c72aa6bfe38ce734a5429464559f4d054
4
+ data.tar.gz: ad820497901cb3a2af9c30879d8432ad9b4e2d794c02f9f596607b5c64094fe1
5
5
  SHA512:
6
- metadata.gz: 900e109f394f8e1caedca681c1916bc0124828aaf6f520a13e359a652f15d210d542d696b6277b8b100b819c5f03f345d28d721fbfde2dab316f8cf49987b890
7
- data.tar.gz: 0951645dc29a00dece264930df2c37026a91bee1b9e882f022941e11a819ada1191cc68df389114661e572c524f4e236f140ca34a59513db475f78650267d370
6
+ metadata.gz: '080a114de9e0c41bd4346e5551a4d29edec30eb90424303c0f5420f0a1dd5f4b93038c6d1c7c93ed4d5095978193f7956dc22041607b21a64623b4e2dfe6194f'
7
+ data.tar.gz: 5db6247edbf273a6c43bf7101c54adc2169f6d520d1b46ef83ac538ee1a1e8a1be95fdae657f73c753ac0e554929e3a3ca37f998f542ab4cbb1f02f087b1ca8f
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Apk Analyzer
4
4
 
5
- The aim of this gem is to extract some data from android apk files. Analysis results are printed in json. It can be used with CLI
5
+ The aim of this gem is to extract some data from android apk or aab files. Analysis results are printed in json. It can be used with CLI
6
6
 
7
7
  ## Installation
8
8
 
@@ -31,18 +31,18 @@ $ gem install apk_analyzer
31
31
  In a terminal use Apk analyzer like this:
32
32
 
33
33
  ```shell
34
- $ apk_analyzer --manifest --cert-info --file /path/to/apk
34
+ $ apk_analyzer --manifest --cert-info --file /path/to/file
35
35
  ```
36
36
 
37
37
  Script above will collect and print:
38
38
  * Android manifest informations
39
- * Apk certificate informations if it have been signed
39
+ * Certificate informations if it have been signed
40
40
 
41
41
  **Result**
42
42
  ```json
43
43
  {
44
44
  "manifest_info": {
45
- "path_in_apk": "AndroidManifest.xml",
45
+ "path": "AndroidManifest.xml",
46
46
  "content": {
47
47
  "application_info": {
48
48
  "theme": "13",
@@ -128,7 +128,7 @@ Script above will collect and print:
128
128
  require 'apk_analyzer'
129
129
 
130
130
  # Instantiate analyzer
131
- apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path('path/to/apk'))
131
+ apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path('path/to/file'))
132
132
 
133
133
  # Then collect data
134
134
  manifest_info = apk_analyzer.collect_manifest_info
data/bin/apk_analyzer CHANGED
@@ -6,7 +6,7 @@ require 'optparse'
6
6
  require 'json'
7
7
 
8
8
  options = {
9
- apk_path: nil,
9
+ file_path: nil,
10
10
  manifest: false,
11
11
  cert_info: false,
12
12
  all: false
@@ -18,8 +18,8 @@ apk_data = {
18
18
  }
19
19
 
20
20
  opts_parser = OptionParser.new do |opts|
21
- opts.on('-f', '--file=FILE_PATH', 'Apk file path') do |file_path|
22
- options[:apk_path] = file_path
21
+ opts.on('-f', '--file=FILE_PATH', 'File path') do |file_path|
22
+ options[:file_path] = file_path
23
23
  end
24
24
 
25
25
  opts.on('-m', '--manifest', 'Prints Manifest.xml information') do
@@ -30,7 +30,7 @@ opts_parser = OptionParser.new do |opts|
30
30
  options[:cert_info] = true
31
31
  end
32
32
 
33
- opts.on('-a', '--all', 'Prints available data on APK') do
33
+ opts.on('-a', '--all', 'Prints available data') do
34
34
  options[:all] = true
35
35
  end
36
36
 
@@ -45,8 +45,8 @@ exit_code = 0
45
45
 
46
46
  opts_parser.parse!
47
47
 
48
- raise 'File not specified' if options[:apk_path].nil?
49
- apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path(options[:apk_path]))
48
+ raise 'File not specified' if options[:file_path].nil?
49
+ apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path(options[:file_path]))
50
50
  apk_data = {}
51
51
  begin
52
52
  apk_data[:manifest_info] = apk_analyzer.collect_manifest_info if options[:manifest] || options[:all]
@@ -14,19 +14,29 @@ module ApkAnalyzer
14
14
  ANDROID_MANIFEST_FILE = 'AndroidManifest.xml'
15
15
 
16
16
 
17
- def initialize(apk_path)
17
+ def initialize(file_path)
18
18
  # Deactivating invalid date warnings in zip for apktools gem and apk analyzer code
19
19
  Zip.warn_invalid_date = false
20
- @apk_path = apk_path
21
- raise 'File is not a valid apk file' unless valid_zip?(apk_path)
22
- @apk_xml = ApkXml.new(apk_path)
20
+ @file_path = file_path
21
+ raise 'File is not a valid file' unless valid_zip?(file_path)
22
+ case File.extname(file_path)
23
+ when ".apk"
24
+ @manifest = ApkXml.new(file_path).parse_xml('AndroidManifest.xml', true, true)
25
+ when ".aab"
26
+ String bundle_tool_location = %x[ #{"which bundletool"} ]
27
+ raise 'Bundletool is not installed & available in your path' if bundle_tool_location.nil? or bundle_tool_location.length == 0
28
+ cmd = "bundletool dump manifest --bundle #{file_path}"
29
+ @manifest = %x[ #{cmd} ]
30
+ else
31
+ raise 'unknown platform technology'
32
+ end
23
33
  end
24
34
 
25
35
  def collect_manifest_info
26
- manifest_file_path = find_file_in_apk(ANDROID_MANIFEST_FILE)
27
- raise 'Failed to find Manifest file in apk' if manifest_file_path.nil?
36
+ manifest_file_path = find_file(ANDROID_MANIFEST_FILE)
37
+ raise 'Failed to find Manifest file' if manifest_file_path.nil?
28
38
  begin
29
- manifest_xml = Nokogiri::XML(@apk_xml.parse_xml('AndroidManifest.xml', true, true))
39
+ manifest_xml = Nokogiri::XML(@manifest)
30
40
  rescue => e
31
41
  puts "Failed to parse #{ANDROID_MANIFEST_FILE}"
32
42
  log_expection e
@@ -34,7 +44,7 @@ module ApkAnalyzer
34
44
 
35
45
  manifest_info = {}
36
46
  begin
37
- manifest_info[:path_in_apk] = manifest_file_path
47
+ manifest_info[:path] = manifest_file_path
38
48
  content = {}
39
49
  # application content
40
50
  content[:application_info] = collect_application_info(manifest_xml)
@@ -72,7 +82,7 @@ module ApkAnalyzer
72
82
  os_has_keytool = system('keytool 2>/dev/null')
73
83
  raise 'keytool dependency not satisfied. Make sure that JAVA keytool utility is installed' unless os_has_keytool
74
84
  cert_info = {}
75
- certificate_raw = `keytool -printcert -rfc -jarfile #{@apk_path.shellescape}`
85
+ certificate_raw = `keytool -printcert -rfc -jarfile #{@file_path.shellescape}`
76
86
  certificate_content_regexp = /(-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----)/m
77
87
  matched_data = certificate_content_regexp.match(certificate_raw)
78
88
  if matched_data
@@ -91,7 +101,7 @@ module ApkAnalyzer
91
101
  cert_extract_dates(certificate_content, cert_info)
92
102
  cert_extract_issuer(certificate_content, cert_info)
93
103
  else
94
- puts 'Failed to find CERT.RSA file in APK'
104
+ puts 'Failed to find CERT.RSA file'
95
105
  end
96
106
  cert_info
97
107
  end
@@ -190,8 +200,9 @@ module ApkAnalyzer
190
200
  end
191
201
 
192
202
  def cert_extract_issuer(certificate_content, result)
203
+ print(certificate_content)
193
204
  subject = `echo "#{certificate_content}" | openssl x509 -noout -in /dev/stdin -subject -nameopt -esc_msb,utf8`
194
- # All APK certificate fields are not manadatory. At least one is needed.So to remove trailing carrier return
205
+ # All certificate fields are not manadatory. At least one is needed.So to remove trailing carrier return
195
206
  # character, we apply gsub method on the raw subject, and we use it after.
196
207
  raw = subject.gsub(/\n/,'')
197
208
  result[:issuer_raw] = raw
@@ -257,25 +268,24 @@ module ApkAnalyzer
257
268
  zip.close if zip
258
269
  end
259
270
 
260
- def find_file_in_apk(file_name)
271
+ def find_file(file_name)
261
272
  begin
262
- file_path_in_apk = nil
263
- apk_zipfile = Zip::File.open(@apk_path)
273
+ zipfile = Zip::File.open(@file_path)
264
274
 
265
275
  # Search at the root
266
- file_path_in_apk = apk_zipfile.find_entry(file_name)
267
- return file_path_in_apk.name unless file_path_in_apk.nil?
276
+ file_path = zipfile.find_entry(file_name)
277
+ return file_path.name unless file_path.nil?
268
278
 
269
279
  # Search deeply
270
- apk_zipfile.each do |entry|
271
- file_path_in_apk = entry.name if entry.name.match(file_name)
272
- break unless file_path_in_apk.nil?
280
+ zipfile.each do |entry|
281
+ file_path = entry.name if entry.name.match(file_name)
282
+ break unless file_path.nil?
273
283
  end
274
- file_path_in_apk.nil? ? nil : file_path_in_apk
284
+ file_path.nil? ? nil : file_path
275
285
  rescue => e
276
286
  log_expection e
277
287
  ensure
278
- apk_zipfile.close
288
+ zipfile.close
279
289
  end
280
290
  end
281
291
 
@@ -1,3 +1,3 @@
1
1
  module ApkAnalyzer
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apk_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BACKELITE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apktools
@@ -138,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.4.5.1
141
+ rubygems_version: 3.0.3
143
142
  signing_key:
144
143
  specification_version: 4
145
144
  summary: Android apk files analyzer