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 +5 -5
- data/README.md +5 -5
- data/bin/apk_analyzer +6 -6
- data/lib/apk_analyzer/analyzer.rb +31 -21
- data/lib/apk_analyzer/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac5bc2cca1e0b89f39f38992fffcca1c72aa6bfe38ce734a5429464559f4d054
|
4
|
+
data.tar.gz: ad820497901cb3a2af9c30879d8432ad9b4e2d794c02f9f596607b5c64094fe1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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
|
-
*
|
39
|
+
* Certificate informations if it have been signed
|
40
40
|
|
41
41
|
**Result**
|
42
42
|
```json
|
43
43
|
{
|
44
44
|
"manifest_info": {
|
45
|
-
"
|
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/
|
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
|
-
|
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', '
|
22
|
-
options[:
|
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
|
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[:
|
49
|
-
apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path(options[:
|
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(
|
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
|
-
@
|
21
|
-
raise 'File is not a valid
|
22
|
-
|
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 =
|
27
|
-
raise 'Failed to find Manifest file
|
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(@
|
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[:
|
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 #{@
|
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
|
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
|
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
|
271
|
+
def find_file(file_name)
|
261
272
|
begin
|
262
|
-
|
263
|
-
apk_zipfile = Zip::File.open(@apk_path)
|
273
|
+
zipfile = Zip::File.open(@file_path)
|
264
274
|
|
265
275
|
# Search at the root
|
266
|
-
|
267
|
-
return
|
276
|
+
file_path = zipfile.find_entry(file_name)
|
277
|
+
return file_path.name unless file_path.nil?
|
268
278
|
|
269
279
|
# Search deeply
|
270
|
-
|
271
|
-
|
272
|
-
break unless
|
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
|
-
|
284
|
+
file_path.nil? ? nil : file_path
|
275
285
|
rescue => e
|
276
286
|
log_expection e
|
277
287
|
ensure
|
278
|
-
|
288
|
+
zipfile.close
|
279
289
|
end
|
280
290
|
end
|
281
291
|
|
data/lib/apk_analyzer/version.rb
CHANGED
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.
|
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:
|
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
|
-
|
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
|