apkToJava 0.0.1

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: 6a1c7e769b3f6557281ab944d2fca67f28b35f1f
4
+ data.tar.gz: 6654d7f23bafa4f3909ed72060f98c5045e4b273
5
+ SHA512:
6
+ metadata.gz: 236c01ab63ac641ffcea291b0fcc8f3b4f8e5ec9957e79668fa1970ccdc3d06b248fe1a2184996b25477ff39ad78ea77db43b071fb7e16ca913978da75c953ed
7
+ data.tar.gz: ab0c1ba80f63b1e59dabc8a02990cdb3f17b111e043db433caa66c69adf6cd5e6a75f0a861f48a27f9f2446d0fe68027e4f61c6903f4fc5e8e79ab3f93b00a70
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ajit Singh
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # apkToJava
2
+ A ruby gem to view android apk as java code in GUI
3
+
4
+ Before starting the process it checks wether the env is setup or not.
5
+ If not it downloads the required tools and continues with the process.
data/apkToJava.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative './lib/apk_to_java/version.rb'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'apkToJava'
8
+ s.version = ApkToJava::VERSION
9
+ s.date = '2016-01-28'
10
+ s.summary = 'View android apk as as java in GUI'
11
+ s.description = s.summary
12
+ s.authors = ['Ajit Singh']
13
+ s.email = 'jeetsingh.ajit@gamil.com'
14
+ s.license = 'MIT'
15
+ s.homepage = 'https://github.com/ajitsing/apkToJava'
16
+
17
+ s.files = `git ls-files -z`.split("\x0")
18
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.require_paths = ["lib"]
21
+ end
data/bin/apkToJava ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/apk_to_java.rb'
4
+ include ApkToJava::Operations
5
+ include ApkToJava::Setup
6
+ include ApkToJava::PrettyPrinter
7
+
8
+ def apk_exists?
9
+ File.exists? ARGV[0]
10
+ end
11
+
12
+ def has_apk_extension?
13
+ ARGV[0].split('/').last.split('.').last == 'apk'
14
+ end
15
+
16
+ def wrong_usage
17
+ print_info "Wrong Usage! Right usage is -"
18
+ print_success "apkToJava path/to/apk/file"
19
+ print_info "To install required tools -"
20
+ print_success "apkToJava setup"
21
+ end
22
+
23
+ def valid_usage?
24
+ apk_file = ARGV[0]
25
+ if ARGV.size > 1 || ARGV.empty?
26
+ wrong_usage
27
+ false
28
+ elsif !apk_exists?
29
+ print_error "#{apk_file} file does not exists!"
30
+ false
31
+ elsif !has_apk_extension?
32
+ print_error "#{apk_file} is not an APK file!"
33
+ false
34
+ else
35
+ true
36
+ end
37
+ end
38
+
39
+ def execute
40
+ if ARGV[0] == 'setup'
41
+ initialize_setup
42
+ elsif valid_usage?
43
+ initialize_setup if !env_setup?
44
+ view_as_java_code ARGV[0]
45
+ end
46
+ end
47
+
48
+ execute
@@ -0,0 +1,106 @@
1
+ require_relative 'apk_to_java/pretty_printer'
2
+
3
+ module ApkToJava
4
+ include ApkToJava::PrettyPrinter
5
+ DEX_TO_JAR = '/usr/local/Cellar/dex2jar/2.0/bin/d2j-dex2jar'
6
+ JADX = '/usr/local/Cellar/jadx/bin/jadx-gui'
7
+
8
+ module Setup
9
+ def install_dex2jar
10
+ print_info("Installing dex2jar..")
11
+ `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null && brew install dex2jar`
12
+ print_success "Done!"
13
+ end
14
+
15
+ def install_jadx
16
+ print_info("Installing jadx..")
17
+ `cd /usr/local/Cellar && wget https://github.com/skylot/jadx/releases/download/v0.6.0/jadx-0.6.0.zip && unzip jadx-0.6.0.zip -d jadx/ && rm jadx-0.6.0.zip && cd -`
18
+ print_success "Done!"
19
+ end
20
+
21
+ def jadx_installed?
22
+ File.exists? ApkToJava::JADX
23
+ end
24
+
25
+ def dex_to_jar_installed?
26
+ File.exists? ApkToJava::DEX_TO_JAR
27
+ end
28
+
29
+ def env_setup?
30
+ dex_to_jar_installed? && jadx_installed?
31
+ end
32
+
33
+ def initialize_setup
34
+ print_info("Initializing setup!!")
35
+ install_dex2jar if !dex_to_jar_installed?
36
+ install_jadx if !jadx_installed?
37
+ print_success("Setup done :)")
38
+ end
39
+ end
40
+
41
+ module Operations
42
+ TEMP_DIR = 'apkToJavaTmp'
43
+
44
+ def copy_apk(apk)
45
+ `mkdir #{TEMP_DIR}`
46
+ `cp #{apk} #{TEMP_DIR}/`
47
+ end
48
+
49
+ def unzip(apk_name)
50
+ `mv #{TEMP_DIR}/#{apk_name}.apk #{TEMP_DIR}/#{apk_name}.zip`
51
+ `unzip #{TEMP_DIR}/#{apk_name}.zip -d #{TEMP_DIR}/`
52
+ end
53
+
54
+ def create_dex
55
+ `#{ApkToJava::DEX_TO_JAR} #{TEMP_DIR}/classes.dex`
56
+ end
57
+
58
+ def path_to_dex
59
+ `pwd`.chomp + "/#{TEMP_DIR}/classes.dex"
60
+ end
61
+
62
+ def create_jar(dex_file)
63
+ `#{ApkToJava::DEX_TO_JAR} #{dex_file} --force`
64
+ end
65
+
66
+ def path_to_jar
67
+ `pwd`.chomp + '/classes-dex2jar.jar'
68
+ end
69
+
70
+ def clean_up
71
+ print_info "Cleaning the mess.."
72
+ `rm -rf #{TEMP_DIR}`
73
+ print_success "done!"
74
+ end
75
+
76
+ def open_code_in_gui(jar_file)
77
+ `#{ApkToJava::JADX} #{jar_file} &`
78
+ end
79
+
80
+ def convert_to_dex(apk)
81
+ print_info "Converting to dex.."
82
+ copy_apk apk
83
+ apk_name = apk.split('/').last.split('.').first
84
+ unzip apk_name
85
+ create_dex
86
+ print_success "Done!"
87
+ path_to_dex
88
+ end
89
+
90
+ def dex_to_jar(apk)
91
+ dex_file = convert_to_dex apk
92
+ print_info "Converting dex to jar.."
93
+ create_jar dex_file
94
+ print_success "Done!"
95
+ path_to_jar
96
+ end
97
+
98
+ def view_as_java_code(apk)
99
+ jar_file = dex_to_jar apk
100
+ clean_up
101
+ print_info "Opening in gui interface.."
102
+ print_success "Please be patient, apkToJava might take some time to load your project in gui interface"
103
+ open_code_in_gui jar_file
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,23 @@
1
+ module ApkToJava
2
+ module PrettyPrinter
3
+ def colorize(text, color_code)
4
+ "#{color_code}#{text}\e[0m"
5
+ end
6
+
7
+ def red(text); colorize(text, "\e[31m"); end
8
+ def green(text); colorize(text, "\e[32m"); end
9
+ def yellow(text); colorize(text, "\e[1m\e[33m"); end
10
+
11
+ def print_info(msg)
12
+ STDOUT.write yellow(msg+"\n")
13
+ end
14
+
15
+ def print_error(msg)
16
+ STDOUT.write red(msg+"\n")
17
+ end
18
+
19
+ def print_success(msg)
20
+ STDOUT.write green(msg+"\n")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ApkToJava
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apkToJava
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ajit Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: View android apk as as java in GUI
14
+ email: jeetsingh.ajit@gamil.com
15
+ executables:
16
+ - apkToJava
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - apkToJava.gemspec
23
+ - bin/apkToJava
24
+ - lib/apk_to_java.rb
25
+ - lib/apk_to_java/pretty_printer.rb
26
+ - lib/apk_to_java/version.rb
27
+ homepage: https://github.com/ajitsing/apkToJava
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.2.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: View android apk as as java in GUI
51
+ test_files: []