headdesk 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1ddf0a2e8ea38b67658e264f0b0106aa7ae9bac
4
+ data.tar.gz: 7f05d112b8e454d3849e9a68a58be3c7dc5a9d2e
5
+ SHA512:
6
+ metadata.gz: 39ed6671b0c6f2482cbac6448cf5e7e50900a97ceeaa6fee3958431c333f764c68a894356cb6168a7e03a64fddb6f2d86901a1820a40f70a46b427127b736e99
7
+ data.tar.gz: e92144937a1ab2ec13911fdeee5e95e3c0bedfb4893c85f1ae9db60a7d4cfe299a787cc29c4e2e62e06297b6f75463469f0117a9c3e3d7f0d79cc816ce45ceac
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .DS_Store
data/.reek.yml ADDED
@@ -0,0 +1,10 @@
1
+ detectors:
2
+ DuplicateMethodCall:
3
+ max_calls: 3
4
+ allow_calls:
5
+ - 'apk.resources'
6
+ - 'Thor::Base.shell'
7
+ - 'CLI.command_help'
8
+ TooManyStatements:
9
+ exclude:
10
+ - 'Headdesk::Checks'
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ headdesk
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gem 'rubocop'
8
+
9
+ # Specify your gem's dependencies in headdesk.gemspec
10
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ headdesk (0.1.0)
5
+ awesome_print
6
+ nokogiri
7
+ thor
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ awesome_print (1.8.0)
14
+ axiom-types (0.1.1)
15
+ descendants_tracker (~> 0.0.4)
16
+ ice_nine (~> 0.11.0)
17
+ thread_safe (~> 0.3, >= 0.3.1)
18
+ codeclimate-engine-rb (0.4.1)
19
+ virtus (~> 1.0)
20
+ coercible (1.0.0)
21
+ descendants_tracker (~> 0.0.1)
22
+ descendants_tracker (0.0.4)
23
+ thread_safe (~> 0.3, >= 0.3.1)
24
+ diff-lcs (1.3)
25
+ equalizer (0.0.11)
26
+ ice_nine (0.11.2)
27
+ jaro_winkler (1.5.1)
28
+ kwalify (0.7.2)
29
+ mini_portile2 (2.3.0)
30
+ nokogiri (1.8.5)
31
+ mini_portile2 (~> 2.3.0)
32
+ parallel (1.12.1)
33
+ parser (2.5.3.0)
34
+ ast (~> 2.4.0)
35
+ powerpack (0.1.2)
36
+ rainbow (3.0.0)
37
+ rake (10.5.0)
38
+ reek (5.2.0)
39
+ codeclimate-engine-rb (~> 0.4.0)
40
+ kwalify (~> 0.7.0)
41
+ parser (>= 2.5.0.0, < 2.6, != 2.5.1.1)
42
+ rainbow (>= 2.0, < 4.0)
43
+ rspec (3.8.0)
44
+ rspec-core (~> 3.8.0)
45
+ rspec-expectations (~> 3.8.0)
46
+ rspec-mocks (~> 3.8.0)
47
+ rspec-core (3.8.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-expectations (3.8.2)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.8.0)
52
+ rspec-mocks (3.8.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.8.0)
55
+ rspec-support (3.8.0)
56
+ rubocop (0.60.0)
57
+ jaro_winkler (~> 1.5.1)
58
+ parallel (~> 1.10)
59
+ parser (>= 2.5, != 2.5.1.1)
60
+ powerpack (~> 0.1)
61
+ rainbow (>= 2.2.2, < 4.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (~> 1.4.0)
64
+ ruby-progressbar (1.10.0)
65
+ thor (0.20.3)
66
+ thread_safe (0.3.6)
67
+ unicode-display_width (1.4.0)
68
+ virtus (1.0.5)
69
+ axiom-types (~> 0.1)
70
+ coercible (~> 1.0)
71
+ descendants_tracker (~> 0.0, >= 0.0.3)
72
+ equalizer (~> 0.0, >= 0.0.9)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ bundler (~> 1.16)
79
+ headdesk!
80
+ rake (~> 10.0)
81
+ reek
82
+ rspec
83
+ rubocop
84
+
85
+ BUNDLED WITH
86
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Pat Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Headdesk
2
+
3
+ Because we've all been there with Android.
4
+
5
+ `headdesk` automatically detects common issues with Android APKs. These are errors that we (at Teak) commonly see in customer support. It's like unit testing for your build system.
6
+
7
+ This is output from the check that ensures that the version of the Facebook SDK (if present) has not been deprecated:
8
+
9
+ ✔ Facebook SDK version
10
+ ↳ ✔ APK contains class com.facebook.FacebookSdk
11
+ ↳ ✔ com.facebook.FacebookSdk contains getSdkVersion method
12
+ ↳ ✔ Found Facebook SDK version 4.33.0
13
+ ↳ ✔ Facebook SDK was released in the last 2 years (using 4.33.0, released 2018-05-01)
14
+ 💾 {"facebook_sdk":{"major":4,"minor":33,"patch":0,"version":"4.33.0","date":"2018-05-01"}}
15
+
16
+ `headdesk` can also output to JSON.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'headdesk'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install headdesk
33
+
34
+ ## Usage
35
+
36
+ Command line usage instruction:
37
+
38
+ $ bundle exec exe/headdesk
39
+
40
+ $ bundle exec exe/headdesk help [COMMAND]
41
+
42
+ Analize an APK
43
+
44
+ $ bundle exec exe/headdesk analize [APK]
45
+
46
+ This will unpack the APK to a temporary path, analize and print to STDOUT the results in plaintext. For JSON output pass `--json`.
47
+
48
+ $ bundle exec exe/headdesk analize --path [path to unpacked APK]
49
+
50
+ This will analize an already unpacked APK.
51
+
52
+ Unpack an APK
53
+
54
+ $ bundle exec exe/headdesk unpack APK [DESTINATION]
55
+
56
+ This will unpack an APK to the specified DESTINATION, or to the current working directory.
57
+
58
+ $ bundle exec exe/headdesk unpack APK [DESTINATION] --analize
59
+
60
+ This will unpack an APK to the specified DESTINATION, or to the current working directory, and then perform analysis.
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gocarrot/headdesk.
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'headdesk'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'headdesk'
5
+ require 'nokogiri'
6
+ require 'open-uri'
7
+ require 'yaml'
8
+
9
+ html_doc = Nokogiri::HTML(open('https://developers.facebook.com/docs/android/change-log-4x'))
10
+
11
+ facebook_sdk_versions = html_doc.xpath('//h2')
12
+ .select { |h2| h2.attributes['id'].value =~ /^\d+_\d+_\d+$/ }
13
+ .collect do |h2|
14
+ major, minor, patch, date = h2.text.match(/^(\d+)\.(\d+)\.?(\d+)? \- (.*)$/).captures
15
+ {
16
+ major: major.to_i || 0,
17
+ minor: minor.to_i || 0,
18
+ patch: patch.to_i || 0,
19
+ version: "#{major.to_i || 0}.#{minor.to_i || 0}.#{patch.to_i || 0}",
20
+ date: Date.parse(date)
21
+ }
22
+ end
23
+
24
+ File.write(Headdesk::FACEBOOK_SDK_VERSIONS_YAML, facebook_sdk_versions.to_yaml)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/headdesk ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'headdesk/cli'
5
+ Headdesk::CLI.start
Binary file
data/headdesk.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'headdesk/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'headdesk'
9
+ spec.version = Headdesk::VERSION
10
+ spec.authors = ['Pat Wilson']
11
+ spec.email = ['pat@teak.io']
12
+
13
+ spec.summary = 'headdesk helps identify and solve common issues in mobile development by analizing APKs and IPAs.'
14
+ spec.description = ''
15
+ spec.homepage = 'https://github.com/GoCarrot/headdesk'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ # 'public gem pushes.'
25
+ # end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.16'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'reek', '~> 0'
39
+ spec.add_development_dependency 'rspec', '~> 0'
40
+
41
+ spec.add_dependency 'awesome_print', '~> 0'
42
+ spec.add_dependency 'nokogiri', '~> 0'
43
+ spec.add_dependency 'thor', '~> 0'
44
+ end
data/lib/headdesk.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'headdesk/apktool'
4
+ require 'headdesk/version'
5
+ require 'headdesk/analize'
6
+ require 'headdesk/apk'
7
+
8
+ #
9
+ # headdesk - Because we've all been there with Android.
10
+ #
11
+ module Headdesk
12
+ FACEBOOK_SDK_VERSIONS_YAML = File.expand_path(File.join(
13
+ File.dirname(__FILE__),
14
+ 'headdesk',
15
+ 'data',
16
+ 'facebook_sdk_versions.yaml'
17
+ ))
18
+
19
+ #
20
+ # Error in CLI input
21
+ #
22
+ class CliError < StandardError
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'headdesk/apk'
4
+
5
+ module Headdesk
6
+ #
7
+ # Analize an APK/IPA
8
+ #
9
+ class Analize
10
+ def self.at(path)
11
+ Headdesk::Apk.new(path).analize
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require 'yaml'
5
+
6
+ require 'headdesk/apk/class'
7
+ require 'headdesk/apk/resources'
8
+ require 'headdesk/check'
9
+ require 'headdesk/report'
10
+
11
+ module Headdesk
12
+ #
13
+ # Representation of an APK file unpacked by apktool
14
+ #
15
+ # :reek:TooManyInstanceVariables
16
+ class Apk
17
+ attr_reader :yaml, :sdk_info, :android_manifest, :resources
18
+
19
+ # :reek:TooManyStatements
20
+ def initialize(path)
21
+ @path = path
22
+
23
+ android_manifest_xml = File.join(@path, 'AndroidManifest.xml').freeze
24
+ apktool_yml = File.join(@path, 'apktool.yml').freeze
25
+
26
+ unless File.exist?(android_manifest_xml) && File.exist?(apktool_yml)
27
+ throw CliError.new('Path did not contain AndroidManifest.xml and/or apktool.yml')
28
+ end
29
+
30
+ @yaml = YAML.load_file(apktool_yml)
31
+ @sdk_info = @yaml['sdkInfo']
32
+ @resources = Resources.new(@path)
33
+
34
+ @android_manifest = File.open(android_manifest_xml) do |file|
35
+ Nokogiri::XML(file)
36
+ end
37
+ end
38
+
39
+ def analize
40
+ report = Headdesk::APKReport.new(self)
41
+
42
+ Headdesk::Check.for_apk.each do |check_type|
43
+ check = check_type.new(self)
44
+ report << check.process
45
+ end
46
+
47
+ # TODO: Associated domains
48
+ report
49
+ end
50
+
51
+ def target_sdk_version
52
+ sdk_info['targetSdkVersion'].to_i
53
+ end
54
+
55
+ def min_sdk_version
56
+ sdk_info['minSdkVersion'].to_i
57
+ end
58
+
59
+ def targets_sdk(gt_eq)
60
+ target_sdk_version >= gt_eq
61
+ end
62
+
63
+ def min_sdk(gt_eq)
64
+ min_sdk_version >= gt_eq
65
+ end
66
+
67
+ def class?(decl)
68
+ find_class(decl) != false
69
+ end
70
+
71
+ def find_class(decl)
72
+ file_name = File.join(@path, 'smali', "#{Class.path_for(decl)}.smali")
73
+ return nil unless File.exist? file_name
74
+
75
+ Class.new(file_name)
76
+ end
77
+ end
78
+ end