apk_unpack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTY1MGUxMzg3NWEwMjFhMTNkMzM2MmM5MTlhMDdhZGVlYTQ0YjczNw==
5
+ data.tar.gz: !binary |-
6
+ YjNlNmE0MmYyMTU3ZGIxNzhmNDRlODU0YmU0YmU3MDliODRkZTA1ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDMzZmM0MzI1OGEyOWFjMzRhYjE2NzNhNWMwMTliOWIwYzYzZjYxNjA2YzRh
10
+ OTM4OGE1N2RmZjgwYzgwYWYxMTQ1MGQwMzZhZTVhMTJjNDI4MDE1MDUyZWY2
11
+ YjI5MzllYTRjOThmMmY4YWQ1MGI5YzRhZjI4NGJiMWM1ZjUzYTA=
12
+ data.tar.gz: !binary |-
13
+ MjY4ZTZlZWMzZGZiNGMyNTMxZWYyMDgyNWY2Y2VjMjJhZTdkZGFiM2YzMGFm
14
+ ODZkNTY3MzMyNDU5ZmIwMjQzM2ExZDQ1OGVlMDNlYWQ1OTM1Mjc3Y2NmMWJj
15
+ ZGMyOWUzMzI5Y2E2NjkxZTJjNGNmOWU2ZDQ2ZTVjYzE0MjYwZmU=
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 nVisium
2
+
3
+ MIT License
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,3 @@
1
+ # ApkUnpack
2
+
3
+ Ruby Gem to Unpack APK(s)
data/bin/apk_unpack ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lib/apk_unpack'
4
+
5
+
6
+ ApkUnpack.run
data/lib/apk_unpack.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'utilities/string'
2
+ require 'utilities/parsing'
3
+ require 'decompiler/decompiler'
4
+ require 'optparse'
5
+
6
+ class ApkUnpack
7
+ def self.run
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: example.rb [options]"
11
+
12
+ opts.on("-c", "--config [Config File]", "Configuration file in YAML format") do |c|
13
+ options[:config_file] = c
14
+ end
15
+
16
+ opts.on("-h", "--help", "Displays help information") do
17
+ puts opts
18
+ exit
19
+ end
20
+ end.parse!
21
+ if !options.empty?
22
+ Parsing.parse(options[:config_file])
23
+ else
24
+ Decompiler.run
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
1
+
2
+ class Decompiler
3
+ def self.my_hash
4
+ {
5
+ "apk" => "file",
6
+ "apktool" => "file",
7
+ "output directory" => "dir",
8
+ "d2j-dex2jar .sh or .bat" => "file"
9
+ }
10
+ end
11
+
12
+ def self.run
13
+ my_hash.each do |k,v|
14
+ puts "Please specify the absolute location of the #{k}"
15
+ instance_variable_set("@#{k}".underscore, gets.chomp)
16
+ unless self.exists(v,k)
17
+ redo
18
+ end
19
+ end
20
+ execute
21
+ rescue ::Interrupt
22
+ puts "\nGoodbye"
23
+ end
24
+
25
+ def self.exists(data_type, entity)
26
+ val = instance_variable_get ("@#{entity}".underscore)
27
+ case data_type
28
+ when "dir"
29
+ Dir.exists?(val)
30
+ when "file"
31
+ File.exists?(val)
32
+ end
33
+ end
34
+
35
+ def self.set_static_vars(opts={})
36
+ raise "NoOptionsProvidedFromConfigFile" if opts.empty?
37
+ @apktool = opts[:apktool]
38
+ @output_directory = opts[:output_directory]
39
+ @d2j_dex2jar_sh_or_bat = opts[:d2j]
40
+ end
41
+
42
+ # This method defines the instance variable @apk as the location
43
+ # of the APK file that the user has provided.
44
+ def self.set_apk_var(apk_loc = "")
45
+ raise "NotAValidApkLocationValue" if !(apk_loc.kind_of?(String))
46
+ raise "NoAPKProvidedFromConfigFile" if apk_loc.empty?
47
+ @apk = apk_loc
48
+ end
49
+
50
+ def self.execute
51
+ run_apktool
52
+ run_dex2jar
53
+ end
54
+
55
+ def self.convert_apkname_to_underscore
56
+ file_name = File.basename(@apk).underscore.tr(".", "_")
57
+ end
58
+
59
+ def self.convert_apk_to_jar
60
+ file_name = File.basename(@apk).sub(/.apk/, ".jar")
61
+ end
62
+
63
+ def self.run_apktool
64
+ system "java", "-jar", @apktool, "d", "-f", @apk, "#{@output_directory}/apktool_output/#{self.convert_apkname_to_underscore}"
65
+ end
66
+
67
+ def self.run_dex2jar
68
+ path = "#{@output_directory}/dex2jar_output"
69
+ Dir.mkdir path if not Dir.exist? path
70
+ system @d2j_dex2jar_sh_or_bat, @apk, "-f", "-o", "#{path}/#{convert_apk_to_jar}"
71
+ end
72
+
73
+ end
74
+
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+
3
+ class Parsing
4
+
5
+ def self.parse(file_location=nil, test=false)
6
+ raise "NoFileProvidedForParsing" if !(file_location)
7
+ yaml_c = test ? modify_yaml_attrs : parse_config_file(file_location)
8
+ opts = generate_options_from_yaml(yaml_c)
9
+ variable_set(opts)
10
+ end
11
+
12
+ def self.parse_config_file(file_location)
13
+ yaml_c = YAML.load_file(file_location)
14
+ end
15
+
16
+ def self.modify_yaml_attrs
17
+ yaml_c = {
18
+ "apk" => ENV["APK"],
19
+ "apktool" => ENV["APKTOOL"],
20
+ "output_directory" => ENV["OUTPUT_DIR"],
21
+ "d2j" => ENV["DEX2JAR"]
22
+ }
23
+ end
24
+
25
+ def self.generate_options_from_yaml(yaml_c)
26
+ options = {}
27
+ options[:apk] = yaml_c["apk"]
28
+ options[:apktool] = yaml_c["apktool"]
29
+ options[:output_directory] = yaml_c["output_directory"]
30
+ options[:d2j] = yaml_c["d2j"]
31
+ return options
32
+ end
33
+
34
+ def self.variable_set(options={})
35
+ Decompiler.set_static_vars(options)
36
+ apk_loc = options[:apk]
37
+ if apk_loc.kind_of?(String)
38
+ Decompiler.set_apk_var(apk_loc)
39
+ Decompiler.execute
40
+ elsif apk_loc.kind_of?(Array)
41
+ apk_loc.each do |apkl|
42
+ Decompiler.set_apk_var(apkl)
43
+ Decompiler.execute
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,12 @@
1
+ class String
2
+ def underscore
3
+ self.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ tr("-", "_").
7
+ tr(" ", "_").
8
+ tr(".", "_").
9
+ tr("__", "_")
10
+ downcase
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apk_unpack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Abdullah Munawar
8
+ - Marcus Richardson
9
+ - Riandi Wiguna
10
+ - Ken Johnson
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2014-02-27 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.5'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ description: ! "\n The APKUnpack tool is used to quickly decompile
45
+ one or more APK applications essentially automating a simple but time consuming
46
+ task. This tool requires that you have the APKTool and Dex2Jar applications on your
47
+ machine.\n "
48
+ email:
49
+ - abdullah.munawar@nvisiumsecurity.com
50
+ executables:
51
+ - apk_unpack
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - LICENSE.txt
56
+ - README.md
57
+ - bin/apk_unpack
58
+ - lib/apk_unpack.rb
59
+ - lib/decompiler/decompiler.rb
60
+ - lib/utilities/parsing.rb
61
+ - lib/utilities/string.rb
62
+ homepage: http://nvisium.github.io/ruby_apk_unpack/
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - .
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A ruby gem intended to simplify decompiling APK files.
86
+ test_files: []