android_parser 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +45 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +92 -0
- data/LICENSE.txt +22 -0
- data/README.md +158 -0
- data/Rakefile +44 -0
- data/android_parser.gemspec +64 -0
- data/lib/android/apk.rb +220 -0
- data/lib/android/axml_parser.rb +239 -0
- data/lib/android/axml_writer.rb +49 -0
- data/lib/android/dex/access_flag.rb +74 -0
- data/lib/android/dex/dex_object.rb +475 -0
- data/lib/android/dex/info.rb +151 -0
- data/lib/android/dex/utils.rb +45 -0
- data/lib/android/dex.rb +92 -0
- data/lib/android/layout.rb +44 -0
- data/lib/android/manifest.rb +350 -0
- data/lib/android/resource.rb +621 -0
- data/lib/android/utils.rb +55 -0
- data/lib/ruby_apk.rb +8 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a338a6e092fc1dc50e3c1688f165109dbb900397e51b968b0397877aa4f6a030
|
4
|
+
data.tar.gz: 5fbbb6f2630a3a4d2a7b090106c53dd45ac9b8ec6b4be9cb37477d1c5615c594
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c270a031fc08369c7afa11e274da90c3aa732b86cade0b10066a227de49bafb30b0dd8b14ce7b77a3a347fda85bfefcf5796c55f8b2a5c645309d625030f01c
|
7
|
+
data.tar.gz: e850a3d98e71801a57686f8b890d45fa1d65d3459805b6855f9451990a960ba6f608ed147c88ea9ded54fb40ab8c49b4d89d19e014172aa24b8a36ba329dc7d9
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# rvm
|
15
|
+
.ruby-version
|
16
|
+
|
17
|
+
# jeweler generated
|
18
|
+
#pkg # upload gem file to server
|
19
|
+
|
20
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
21
|
+
#
|
22
|
+
# * Create a file at ~/.gitignore
|
23
|
+
# * Include files you want ignored
|
24
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
25
|
+
#
|
26
|
+
# After doing this, these files will be ignored in all your git projects,
|
27
|
+
# saving you from having to 'pollute' every project you touch with them
|
28
|
+
#
|
29
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
30
|
+
#
|
31
|
+
# For MacOS:
|
32
|
+
#
|
33
|
+
.DS_Store
|
34
|
+
.idea
|
35
|
+
|
36
|
+
# For TextMate
|
37
|
+
#*.tmproj
|
38
|
+
#tmtags
|
39
|
+
|
40
|
+
# For emacs:
|
41
|
+
#*~
|
42
|
+
#\#*
|
43
|
+
#.\#*
|
44
|
+
|
45
|
+
# For vim:
|
46
|
+
*.swp
|
47
|
+
|
48
|
+
# For redcar:
|
49
|
+
#.redcar
|
50
|
+
|
51
|
+
# For rubinius:
|
52
|
+
#*.rbc
|
53
|
+
|
54
|
+
pkg/
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# ChangeLog
|
2
|
+
## 0.7.0
|
3
|
+
* implement Apk#signs, Apk#certificates and Manifest#version_name (#14, #15)
|
4
|
+
* bugfix
|
5
|
+
|
6
|
+
## 0.6.0
|
7
|
+
* implement Android::Apk#layouts(#10), Android::Apk#icon(#11), Android::Apk#label(#12),
|
8
|
+
* fix bug (#13)
|
9
|
+
|
10
|
+
## 0.5.1
|
11
|
+
* [#8] add Android::Manifest#label
|
12
|
+
* [#7] fix wrong boolean value in manifest parser
|
13
|
+
* [#6] add accessor Android::Manifest#doc
|
14
|
+
|
15
|
+
## 0.5.0
|
16
|
+
* [issue #1] implement Android::Resource#find, #res_readable_id, #res_hex_id methods
|
17
|
+
|
18
|
+
## 0.4.2
|
19
|
+
* fix bugs(#2, #3)
|
20
|
+
* divide change log from readme
|
21
|
+
|
22
|
+
## 0.4.1
|
23
|
+
* fix typo
|
24
|
+
* add document
|
25
|
+
|
26
|
+
## 0.4.0
|
27
|
+
* add resource parser
|
28
|
+
* enhance dex parser
|
29
|
+
|
30
|
+
## 0.3.0
|
31
|
+
* add and change name space
|
32
|
+
* add Android::Utils module and some util methods
|
33
|
+
* add Apk#entry, Apk#each_entry, and Apk#time methods,
|
34
|
+
|
35
|
+
## 0.2.0
|
36
|
+
* update documents
|
37
|
+
* add Apk::Dex#each_strings, Apk::Dex#each_class_names
|
38
|
+
|
39
|
+
## 0.1.2
|
40
|
+
* fix bug(improve android binary xml parser)
|
41
|
+
|
42
|
+
## 0.1.1
|
43
|
+
* fix bug(failed to initialize Apk::Manifest::Meta class)
|
44
|
+
* replace iconv to String#encode(for ruby1.9)
|
45
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "rubyzip", ">=1.0.0"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec-its", ">= 1.2.0"
|
11
|
+
gem "rspec-collection_matchers", ">= 1.1.0"
|
12
|
+
gem "rspec-mocks", ">= 3.6.0"
|
13
|
+
gem "bundler", ">= 1.1.5"
|
14
|
+
gem "jeweler"
|
15
|
+
gem "yard", require: false
|
16
|
+
gem "redcarpet"
|
17
|
+
gem "simplecov", require: false
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.4.0)
|
5
|
+
builder (3.2.3)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
8
|
+
diff-lcs (1.3)
|
9
|
+
docile (1.1.5)
|
10
|
+
faraday (0.9.2)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
git (1.3.0)
|
13
|
+
github_api (0.16.0)
|
14
|
+
addressable (~> 2.4.0)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
16
|
+
faraday (~> 0.8, < 0.10)
|
17
|
+
hashie (>= 3.4)
|
18
|
+
mime-types (>= 1.16, < 3.0)
|
19
|
+
oauth2 (~> 1.0)
|
20
|
+
hashie (3.5.7)
|
21
|
+
highline (1.7.10)
|
22
|
+
jeweler (2.3.9)
|
23
|
+
builder
|
24
|
+
bundler
|
25
|
+
git (>= 1.2.5)
|
26
|
+
github_api (~> 0.16.0)
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (>= 1.5.10)
|
29
|
+
psych
|
30
|
+
rake
|
31
|
+
rdoc
|
32
|
+
semver2
|
33
|
+
json (2.1.0)
|
34
|
+
jwt (1.5.6)
|
35
|
+
mime-types (2.99.3)
|
36
|
+
mini_portile2 (2.3.0)
|
37
|
+
multi_json (1.13.1)
|
38
|
+
multi_xml (0.6.0)
|
39
|
+
multipart-post (2.0.0)
|
40
|
+
nokogiri (1.8.2)
|
41
|
+
mini_portile2 (~> 2.3.0)
|
42
|
+
oauth2 (1.4.0)
|
43
|
+
faraday (>= 0.8, < 0.13)
|
44
|
+
jwt (~> 1.0)
|
45
|
+
multi_json (~> 1.3)
|
46
|
+
multi_xml (~> 0.5)
|
47
|
+
rack (>= 1.2, < 3)
|
48
|
+
psych (3.0.2)
|
49
|
+
rack (2.0.4)
|
50
|
+
rake (12.3.0)
|
51
|
+
rdoc (6.0.1)
|
52
|
+
redcarpet (3.4.0)
|
53
|
+
rspec-collection_matchers (1.1.3)
|
54
|
+
rspec-expectations (>= 2.99.0.beta1)
|
55
|
+
rspec-core (3.6.0)
|
56
|
+
rspec-support (~> 3.6.0)
|
57
|
+
rspec-expectations (3.6.0)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.6.0)
|
60
|
+
rspec-its (1.2.0)
|
61
|
+
rspec-core (>= 3.0.0)
|
62
|
+
rspec-expectations (>= 3.0.0)
|
63
|
+
rspec-mocks (3.6.0)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.6.0)
|
66
|
+
rspec-support (3.6.0)
|
67
|
+
rubyzip (1.2.1)
|
68
|
+
semver2 (3.4.2)
|
69
|
+
simplecov (0.15.1)
|
70
|
+
docile (~> 1.1.0)
|
71
|
+
json (>= 1.8, < 3)
|
72
|
+
simplecov-html (~> 0.10.0)
|
73
|
+
simplecov-html (0.10.2)
|
74
|
+
thread_safe (0.3.6)
|
75
|
+
yard (0.9.12)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
bundler (>= 1.1.5)
|
82
|
+
jeweler
|
83
|
+
redcarpet
|
84
|
+
rspec-collection_matchers (>= 1.1.0)
|
85
|
+
rspec-its (>= 1.2.0)
|
86
|
+
rspec-mocks (>= 3.6.0)
|
87
|
+
rubyzip (>= 1.0.0)
|
88
|
+
simplecov
|
89
|
+
yard
|
90
|
+
|
91
|
+
BUNDLED WITH
|
92
|
+
1.15.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Securebrain
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
# ruby_apk
|
2
|
+
Android Apk static analysis library for Ruby.
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ruby_apk.png)](http://badge.fury.io/rb/ruby_apk)
|
5
|
+
[![Build Status](https://travis-ci.org/playtestcloud/ruby_apk.svg?branch=master)](https://travis-ci.org/playtestcloud/ruby_apk)
|
6
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/playtestcloud/ruby_apk.png)](https://gemnasium.com/github.com/playtestcloud/ruby_apk)
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
- ruby(>=2.2.2)
|
10
|
+
|
11
|
+
## Install
|
12
|
+
$ gem install ruby_apk
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
### Initialize
|
16
|
+
```ruby
|
17
|
+
require 'ruby_apk'
|
18
|
+
apk = Android::Apk.new('sample.apk') # set apk file path
|
19
|
+
```
|
20
|
+
|
21
|
+
### Apk
|
22
|
+
#### Listing files in Apk
|
23
|
+
```ruby
|
24
|
+
# listing files in apk
|
25
|
+
apk = Android::Apk.new('sample.apk')
|
26
|
+
apk.each_file do |name, data|
|
27
|
+
puts "#{name}: #{data.size}bytes" # puts file name and data size
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
#### Find files in Apk
|
32
|
+
```ruby
|
33
|
+
apk = Android::Apk.new('sample.apk')
|
34
|
+
elf_files = apk.find{|name, data| data[0..3] == [0x7f, 0x45, 0x4c, 0x46] } # ELF magic number
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Extract icon data in Apk (since 0.6.0)
|
38
|
+
```ruby
|
39
|
+
apk = Android::Apk.new('sample.apk')
|
40
|
+
icons = apk.icon # { "res/drawable-hdpi/ic_launcher.png" => "\x89PNG\x0D\x0A...", ... }
|
41
|
+
icons.each do |name, data|
|
42
|
+
File.open(File.basename(name), 'wb') {|f| f.write data } # save to file.
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Extract signature and certificate information from Apk (since v0.7.0)
|
47
|
+
```ruby
|
48
|
+
apk = Android::Apk.new('sample.apk')
|
49
|
+
signs = apk.signs # retrun Hash(key: signature file path, value: OpenSSL::PKCS7)
|
50
|
+
signs.each do |path, sign|
|
51
|
+
puts path # => "MATA-INF/CERT.RSA" or ...
|
52
|
+
puts sign # => "-----BEGIN PKCS7-----\n..." PKCS7 object
|
53
|
+
end
|
54
|
+
|
55
|
+
certs = apk.certificates # retrun Hash(key: signature file path, value: OpenSSL::X509::Certificate)
|
56
|
+
certs.each do |path, cert|
|
57
|
+
puts path # => "MATA-INF/CERT.RSA" or ...
|
58
|
+
puts cert # => "-----BEGIN CERTIFICATE-----\n..." # X509::Certificate object
|
59
|
+
end
|
60
|
+
```
|
61
|
+
Note: Most apks have only one signature and cerficate.
|
62
|
+
|
63
|
+
### Manifest
|
64
|
+
#### Get readable xml
|
65
|
+
```ruby
|
66
|
+
apk = Android::Apk.new('sample.apk')
|
67
|
+
manifest = apk.manifest
|
68
|
+
puts manifest.to_xml
|
69
|
+
```
|
70
|
+
|
71
|
+
#### Listing components and permissions
|
72
|
+
```ruby
|
73
|
+
apk = Android::Apk.new('sample.apk')
|
74
|
+
manifest = apk.manifest
|
75
|
+
# listing components
|
76
|
+
manifest.components.each do |c| # 'c' is Android::Manifest::Component object
|
77
|
+
puts "#{c.type}: #{c.name}"
|
78
|
+
c.intent_filters.each do |filter|
|
79
|
+
puts "\t#{filter.type}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# listing use-permission tag
|
84
|
+
manifest.use_permissions.each do |permission|
|
85
|
+
puts permission
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Extract application label string
|
90
|
+
```ruby
|
91
|
+
apk = Android::Apk.new('sample.apk')
|
92
|
+
puts apk.manifest.label
|
93
|
+
```
|
94
|
+
|
95
|
+
### Resource
|
96
|
+
#### Extract resource strings from apk
|
97
|
+
```ruby
|
98
|
+
apk = Android::Apk.new('sample.apk')
|
99
|
+
rsc = apk.resource
|
100
|
+
rsc.strings.each do |str|
|
101
|
+
puts str
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
#### Parse resource file directly
|
106
|
+
```ruby
|
107
|
+
rsc_data = File.open('resources.arsc', 'rb').read{|f| f.read }
|
108
|
+
rsc = Android::Resource.new(rsc_data)
|
109
|
+
```
|
110
|
+
|
111
|
+
### Resolve resource id
|
112
|
+
This feature supports only srting resources for now.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
apk = Android::Apk.new('sample.apk')
|
116
|
+
rsc = apk.resource
|
117
|
+
|
118
|
+
# assigns readable resource id
|
119
|
+
puts rsc.find('@string/app_name') # => 'application name'
|
120
|
+
|
121
|
+
# assigns hex resource id
|
122
|
+
puts rsc.find('@0x7f040000') # => 'application name'
|
123
|
+
|
124
|
+
# you can set lang attribute.
|
125
|
+
puts rsc.find('@0x7f040000', :lang => 'ja')
|
126
|
+
```
|
127
|
+
|
128
|
+
|
129
|
+
### Dex
|
130
|
+
#### Extract dex information
|
131
|
+
```ruby
|
132
|
+
apk = Android::Apk.new('sample.apk')
|
133
|
+
dex = apk.dex
|
134
|
+
# listing string table in dex
|
135
|
+
dex.strings.each do |str|
|
136
|
+
puts str
|
137
|
+
end
|
138
|
+
|
139
|
+
# listing all class names
|
140
|
+
dex.classes.each do |cls| # cls is Android::Dex::ClassInfo
|
141
|
+
puts "class: #{cls.name}"
|
142
|
+
cls.virtual_methods.each do |m| # Android::Dex::MethodInfo
|
143
|
+
puts "\t#{m.definition}" # puts method definition
|
144
|
+
end
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
#### Parse dex file directly
|
149
|
+
```ruby
|
150
|
+
dex_data = File.open('classes.dex','rb').read{|f| f.read }
|
151
|
+
dex = Android::Dex.new(dex_data)
|
152
|
+
```
|
153
|
+
|
154
|
+
|
155
|
+
## Copyright
|
156
|
+
|
157
|
+
Copyright (c) 2012 SecureBrain. See LICENSE.txt for further details.
|
158
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
require 'bundler/gem_tasks'
|
14
|
+
|
15
|
+
# require 'jeweler'
|
16
|
+
# Jeweler::Tasks.new do |gem|
|
17
|
+
# # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
# gem.name = "android_parser"
|
19
|
+
# gem.homepage = "https://github.com/icyleaf/ruby_apk"
|
20
|
+
# gem.license = "MIT"
|
21
|
+
# gem.summary = %Q{static analysis tool for android apk}
|
22
|
+
# gem.description = %Q{static analysis tool for android apk}
|
23
|
+
# gem.email = "info@securebrain.co.jp"
|
24
|
+
# gem.authors = ["SecureBrain"]
|
25
|
+
# # dependencies defined in Gemfile
|
26
|
+
# end
|
27
|
+
# Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
# require 'yard'
|
39
|
+
# require 'yard/rake/yardoc_task'
|
40
|
+
# YARD::Rake::YardocTask.new do |t|
|
41
|
+
# t.files = ['lib/**/*.rb']
|
42
|
+
# t.options = []
|
43
|
+
# t.options << '--debug' << '--verbose' if $trace
|
44
|
+
# end
|