-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
643 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
*.gem | ||
|
||
\.idea/ | ||
|
||
*.log | ||
|
||
test_binaries\.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sudo: false | ||
language: ruby | ||
rvm: | ||
- 2.2.5 | ||
before_install: gem install bundler -v 1.14.4 | ||
script: rake build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in apk_analyzer.gemspec | ||
gemspec | ||
|
||
# Added when debugging apktools RubyZip issue locally | ||
# Waiting for PR on apktools to be accepted (2017/04/03) | ||
#gem 'apktools', '~>0.7.2', path: '../apktools/apktools' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Backelite | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,155 @@ | ||
# apk_analyzer | ||
[![Build Status](https://travis-ci.org/Backelite/apk_analyzer.svg?branch=master)](https://travis-ci.org/Backelite/apk_analyzer) | ||
|
||
# Apk Analyzer | ||
|
||
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 | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'apk_analyzer' | ||
``` | ||
|
||
And then execute: | ||
|
||
```shell | ||
$ bundle | ||
``` | ||
|
||
Or install it yourself as: | ||
|
||
```shell | ||
$ gem install apk_analyzer | ||
``` | ||
|
||
## Usage | ||
|
||
1. **CLI Usage** | ||
|
||
In a terminal use Apk analyzer like this: | ||
|
||
```shell | ||
$ apk_analyzer --manifest --cert-info --file /path/to/apk | ||
``` | ||
|
||
Script above will collect and print: | ||
* Android manifest informations | ||
* Apk certificate informations if it have been signed | ||
|
||
**Result** | ||
```json | ||
{ | ||
"manifest_info": { | ||
"path_in_apk": "AndroidManifest.xml", | ||
"content": { | ||
"application_info": { | ||
"theme": "13", | ||
"label": "E.app.label", | ||
"icon": "@drawable/ic_launcher", | ||
"name": "com.package.xxxx.xxxx", | ||
"debuggable": true, | ||
"allowBackup": true, | ||
"hardwareAccelerated": true, | ||
"application_id": "com.xxxxxxx.xxxx.xxx" | ||
}, | ||
"intents": [ | ||
{ | ||
"actions": [ | ||
"android.intent.action.MAIN" | ||
], | ||
"category": "android.intent.category.LAUNCHER" | ||
}, | ||
{ | ||
"actions": [ | ||
"com.android.vending.INSTALL_REFERRER" | ||
] | ||
}, | ||
{ | ||
"actions": [ | ||
"com.google.android.c2dm.intent.RECEIVE", | ||
"com.google.android.c2dm.intent.REGISTRATION" | ||
], | ||
"category": "com.xxxxxx.xxx.rec" | ||
}, | ||
{ | ||
"actions": [ | ||
"com.google.firebase.INSTANCE_ID_EVENT" | ||
] | ||
} | ||
], | ||
"uses_sdk": { | ||
"minimum_sdk_version": 14, | ||
"target_sdk_version": 23 | ||
}, | ||
"uses_permissions": [ | ||
"android.permission.INTERNET", | ||
"android.permission.CAMERA", | ||
"android.permission.WRITE_EXTERNAL_STORAGE", | ||
"android.permission.READ_EXTERNAL_STORAGE", | ||
"android.permission.VIBRATE", | ||
"com.google.android.c2dm.permission.RECEIVE", | ||
"android.permission.ACCESS_NETWORK_STATE", | ||
"android.permission.WAKE_LOCK", | ||
"com.modulotech.xxxxxxx.xxxx.permission.C2D_MESSAGE" | ||
], | ||
"uses_features": [ | ||
{ | ||
"name": "android.hardware.camera", | ||
"required": true | ||
} | ||
], | ||
"supports_screens": [ | ||
"anyDensity", | ||
"normalScreens", | ||
"largeScreens", | ||
"xlargeScreens" | ||
] | ||
} | ||
}, | ||
"cert_info": { | ||
"issuer_raw": "subject= C=US, O=Android, CN=Android Debug", | ||
"cn": "Android Debug", | ||
"ou": null, | ||
"o": "Android", | ||
"st": null, | ||
"l": null, | ||
"c": "US", | ||
"creation_date": "Sep 15 07:06:03 2011 GMT", | ||
"expiration_date": "Sep 7 07:06:03 2041 GMT" | ||
} | ||
} | ||
``` | ||
|
||
2. **Inside Ruby code** | ||
|
||
```ruby | ||
require 'apk_analyzer' | ||
|
||
# Instantiate analyzer | ||
apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path('path/to/apk')) | ||
|
||
# Then collect data | ||
manifest_info = apk_analyzer.collect_manifest_info | ||
certificate_info = apk_analyzer.collect_cert_info | ||
``` | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/Backelite/apk_analyzer. | ||
|
||
## Requirements | ||
|
||
* Java keytool: Java and its keytool utility must be installed and set in the PATH on your OS | ||
* OpenSSL: version 1.0.2g (1 Mar 2016) or greater | ||
|
||
## Known issues | ||
|
||
To avoid rubyzip 'Invalid date/time in zip entry' message logged by rubzip dependency on [apktools](https://github.com/devunwired/apktools) gem we updated it in our gem and set | ||
warn_invalid_date to false. | ||
A [pull request](https://github.com/devunwired/apktools/pull/20) is pending to correct this on apkxml gem too. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "bundler/gem_tasks" | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << "test" | ||
t.libs << "lib" | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
task :default => :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'apk_analyzer/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'apk_analyzer' | ||
spec.version = ApkAnalyzer::VERSION | ||
spec.authors = 'BACKELITE' | ||
spec.email = '[email protected]' | ||
|
||
spec.summary = %q{Android apk files analyzer} | ||
spec.description = %q{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} | ||
spec.homepage = 'https://github.com/Backelite/apk_analyzer' | ||
spec.license = 'MIT' | ||
|
||
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' | ||
# to allow pushing to a single host or delete this section to allow pushing to any host. | ||
if spec.respond_to?(:metadata) | ||
spec.metadata['allowed_push_host'] = 'https://rubygems.org' | ||
else | ||
raise 'RubyGems 2.0 or newer is required to protect against ' \ | ||
'public gem pushes.' | ||
end | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject do |f| | ||
f.match(%r{^(test|spec|features)/}) | ||
end | ||
spec.bindir = 'bin' | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_runtime_dependency 'apktools', '~>0.7' | ||
spec.add_runtime_dependency 'nokogiri', '~>1.5' | ||
spec.add_runtime_dependency 'rubyzip', '~>1.2' | ||
|
||
spec.add_development_dependency "bundler", "~> 1.14" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_development_dependency "minitest", "~> 5.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$LOAD_PATH.push File.expand_path('../../lib', __FILE__) | ||
require 'apk_analyzer' | ||
require 'optparse' | ||
require 'json' | ||
|
||
options = { | ||
apk_path: nil, | ||
manifest: false, | ||
cert_info: false, | ||
all: false | ||
} | ||
|
||
apk_data = { | ||
manifest_info: nil, | ||
cert_info: nil | ||
} | ||
|
||
opts_parser = OptionParser.new do |opts| | ||
opts.on('-f', '--file=FILE_PATH', 'Apk file path') do |file_path| | ||
options[:apk_path] = file_path | ||
end | ||
|
||
opts.on('-m', '--manifest', 'Prints Manifest.xml information') do | ||
options[:manifest] = true | ||
end | ||
|
||
opts.on('-c', '--cert-info', 'Prints Certificate issuer and related dates') do | ||
options[:cert_info] = true | ||
end | ||
|
||
opts.on('-a', '--all', 'Prints available data on APK') do | ||
options[:all] = true | ||
end | ||
|
||
opts.on('-h', '--help', 'Prints help message') do | ||
puts opts_parser | ||
puts "\t ex: bin/apk_analyzer -m -c -f [FILE_PATH]" | ||
exit 0 | ||
end | ||
end | ||
|
||
exit_code = 0 | ||
|
||
opts_parser.parse! | ||
|
||
raise 'File not specified' if options[:apk_path].nil? | ||
apk_analyzer = ApkAnalyzer::Analyzer.new(File.expand_path(options[:apk_path])) | ||
apk_data = {} | ||
begin | ||
apk_data[:manifest_info] = apk_analyzer.collect_manifest_info if options[:manifest] || options[:all] | ||
apk_data[:cert_info] = apk_analyzer.collect_cert_info if options[:cert_info] || options[:all] | ||
puts JSON.pretty_generate(apk_data) | ||
rescue => e | ||
puts e.message | ||
puts e.backtrace | ||
exit_code = 1 | ||
end | ||
|
||
exit exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "bundler/setup" | ||
require "apk_analyzer" | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
# (If you use this, don't forget to add pry to your Gemfile!) | ||
# require "pry" | ||
# Pry.start | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here | ||
chmod +x bin/apk_analyzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'apk_analyzer/version' | ||
require 'apk_analyzer/analyzer' |
Oops, something went wrong.