dex-oracle 1.0.2

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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +56 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +102 -0
  6. data/bin/dex-oracle +98 -0
  7. data/dex-oracle.gemspec +43 -0
  8. data/driver/build.gradle +52 -0
  9. data/driver/gradle/wrapper/gradle-wrapper.jar +0 -0
  10. data/driver/gradle/wrapper/gradle-wrapper.properties +6 -0
  11. data/driver/gradlew +160 -0
  12. data/driver/gradlew.bat +90 -0
  13. data/driver/src/main/java/org/cf/oracle/Driver.java +134 -0
  14. data/driver/src/main/java/org/cf/oracle/FileUtils.java +35 -0
  15. data/driver/src/main/java/org/cf/oracle/StackSpoofer.java +42 -0
  16. data/driver/src/main/java/org/cf/oracle/options/InvocationTarget.java +40 -0
  17. data/driver/src/main/java/org/cf/oracle/options/TargetParser.java +121 -0
  18. data/lib/dex-oracle/driver.rb +255 -0
  19. data/lib/dex-oracle/logging.rb +32 -0
  20. data/lib/dex-oracle/plugin.rb +87 -0
  21. data/lib/dex-oracle/plugins/string_decryptor.rb +59 -0
  22. data/lib/dex-oracle/plugins/undexguard.rb +155 -0
  23. data/lib/dex-oracle/plugins/unreflector.rb +85 -0
  24. data/lib/dex-oracle/resources.rb +13 -0
  25. data/lib/dex-oracle/smali_field.rb +21 -0
  26. data/lib/dex-oracle/smali_file.rb +64 -0
  27. data/lib/dex-oracle/smali_input.rb +81 -0
  28. data/lib/dex-oracle/smali_method.rb +33 -0
  29. data/lib/dex-oracle/utility.rb +37 -0
  30. data/lib/dex-oracle/version.rb +3 -0
  31. data/lib/oracle.rb +61 -0
  32. data/res/driver.dex +0 -0
  33. data/res/dx.jar +0 -0
  34. data/spec/data/helloworld.apk +0 -0
  35. data/spec/data/helloworld.dex +0 -0
  36. data/spec/data/plugins/bytes_decrypt.smali +18 -0
  37. data/spec/data/plugins/class_forname.smali +14 -0
  38. data/spec/data/plugins/multi_bytes_decrypt.smali +28 -0
  39. data/spec/data/plugins/string_decrypt.smali +14 -0
  40. data/spec/data/plugins/string_lookup_1int.smali +14 -0
  41. data/spec/data/plugins/string_lookup_3int.smali +18 -0
  42. data/spec/data/smali/helloworld.smali +17 -0
  43. data/spec/dex-oracle/driver_spec.rb +82 -0
  44. data/spec/dex-oracle/plugins/string_decryptor_spec.rb +25 -0
  45. data/spec/dex-oracle/plugins/undexguard_spec.rb +69 -0
  46. data/spec/dex-oracle/plugins/unreflector_spec.rb +29 -0
  47. data/spec/dex-oracle/smali_field_spec.rb +15 -0
  48. data/spec/dex-oracle/smali_file_spec.rb +41 -0
  49. data/spec/dex-oracle/smali_input_spec.rb +90 -0
  50. data/spec/dex-oracle/smali_method_spec.rb +19 -0
  51. data/spec/spec_helper.rb +9 -0
  52. data/update_driver +5 -0
  53. metadata +195 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e65aeaf75e033e0ea78152e0b900016805c1442e
4
+ data.tar.gz: c6c43b249f3eecae4abf0db9b31de4f3c986604f
5
+ SHA512:
6
+ metadata.gz: 5fd0973fec7576356a4865717d40c225c3abbba2c841e23f94a3be071fe0f8b621823663a6bd51b2651055be9d55a79aadc3963850fda92259617b76105b4e1d
7
+ data.tar.gz: 91287ad0c88ddd3083ac78eb09e05d5e5149ccaca2fb74bf4d2b7e84fcb6e1b541de30056737fa1c96ab4b9e8aee62cb419b2d1f7c25877d980b1a1fa2a8732b
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec name: 'dex-oracle'
3
+
4
+ gem 'rubocop', require: false
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dex-oracle (1.0.1)
5
+ rubyzip (~> 1.1, >= 1.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ diff-lcs (1.2.5)
14
+ parser (2.2.3.0)
15
+ ast (>= 1.1, < 3.0)
16
+ powerpack (0.1.1)
17
+ rainbow (2.0.0)
18
+ rspec (3.4.0)
19
+ rspec-core (~> 3.4.0)
20
+ rspec-expectations (~> 3.4.0)
21
+ rspec-mocks (~> 3.4.0)
22
+ rspec-core (3.4.1)
23
+ rspec-support (~> 3.4.0)
24
+ rspec-expectations (3.4.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.4.0)
27
+ rspec-its (1.2.0)
28
+ rspec-core (>= 3.0.0)
29
+ rspec-expectations (>= 3.0.0)
30
+ rspec-mocks (3.4.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.4.0)
33
+ rspec-support (3.4.1)
34
+ rubocop (0.35.1)
35
+ astrolabe (~> 1.3)
36
+ parser (>= 2.2.3.0, < 3.0)
37
+ powerpack (~> 0.1)
38
+ rainbow (>= 1.99.1, < 3.0)
39
+ ruby-progressbar (~> 1.7)
40
+ tins (<= 1.6.0)
41
+ ruby-progressbar (1.7.5)
42
+ rubyzip (1.1.7)
43
+ tins (1.6.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ dex-oracle!
50
+ rspec (~> 3.4, >= 3.4.0)
51
+ rspec-its (~> 1.2, >= 1.2.0)
52
+ rspec-mocks (~> 3.4, >= 3.4.0)
53
+ rubocop
54
+
55
+ BUNDLED WITH
56
+ 1.11.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Caleb Fenton
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.
@@ -0,0 +1,102 @@
1
+ # Oracle
2
+ A pattern based Dalvik deobfuscator which uses limited execution to improve semantic analysis. Also, the inspiration for another Android deobfuscator: [Simplify](https://github.com/CalebFenton/simplify).
3
+
4
+ **Before**
5
+ ![before](http://i.imgur.com/nICE4N4.png)
6
+
7
+ **After**
8
+ ![after](http://i.imgur.com/aFFd9eM.png)
9
+
10
+ Bitcoin: 133bmAUshC5VxntCcusWJdT8Sq3BFsaGce
11
+
12
+ ## Installation
13
+
14
+ ### Step 1. Install Smali / Baksmali
15
+ I'm sure since you're an elite Android reverser you already have smali and baksmali on your path.
16
+
17
+ ### Step 2. Install Android SDK / ADB
18
+ Make sure `adb` is on your path.
19
+
20
+ ### Step 3. Install the Gem
21
+ ```
22
+ gem install dex-oracle
23
+ ```
24
+
25
+ Or, if you prefer to build from source:
26
+ ```
27
+ git clone https://github.com/CalebFenton/dex-oracle.git
28
+ cd dex-oracle
29
+ gem install bundler
30
+ bundle install
31
+ ```
32
+
33
+ ### Step 4. Connect a Device or Emulator
34
+ _You must have either an emulator running or a device plugged in for Oracle to work._
35
+
36
+ Oracle needs to execute methods on an live Android system. This can either be on a device or an emulator (preferred). If it's a device, _make sure you don't mind running potentially hostile code on it_.
37
+
38
+ If you'd like to use an emulator, and already have the Android SDK installed, you can create and start emulator images with:
39
+ ```
40
+ android avd
41
+ ```
42
+
43
+ ## Usage
44
+ ```
45
+ Usage: dex-oracle [opts] <APK / DEX / Smali Directory>
46
+ -h, --help Display this screen
47
+ -s ANDROID_SERIAL, Device ID for driver execution, default=""
48
+ --specific-device
49
+ -t, --timeout N ADB command execution timeout in seconds, default="120"
50
+ -i, --include PATTERN Only optimize methods and classes matching the pattern, e.g. Ldune;->melange\(\)V
51
+ -e, --exclude PATTERN Exclude these types from optimization; including overrides
52
+ --disable-plugins STRING[,STRING]*
53
+ Disable plugins, e.g. stringdecryptor,unreflector
54
+ --list-plugins List available plugins
55
+ -v, --verbose Be verbose
56
+ -V, --vverbose Be very verbose
57
+ ```
58
+
59
+ For example, to only deobfuscate methods in a class called `Lcom/android/system/admin/CCOIoll;` inside of an APK called `obad.apk`:
60
+
61
+ ```
62
+ dex-oracle -i com/android/system/admin/CCOIoll obad.apk
63
+ ```
64
+
65
+ ## How it Works
66
+ Oracle takes Android apps (APK), Dalvik executables (DEX), and Smali files as inputs. First, if the input is an APK or DEX, it is disassembled into Smali files. Then, the Smali files are passed to various plugins which perform analysis and modifications. Plugins search for patterns which can be transformed into something easier to read. In order to understand what the code is doing, some Dalvik methods are actually executed with and the output is collected. This way, some method calls can be replaced with constants. After that, all of the Smali files are updated. Finally, if the input was an APK or a DEX file, the modified Smali files are recompiled and an updated APK or DEX is created.
67
+
68
+ Method execution is performed by the [Driver](driver/src/main/java/org/cf/oracle/Driver.java). The input APK, DEX, or Smali is combined with the Driver into a single DEX using dexmerge and pushed onto a device or emulator. Oracle then sends method execution information to Driver whenever a plugin requests it. Driver uses Java reflection to execute methods within its own DEX with the arguments provided by Oracle and returns any output or exceptions. This is especially useful for many string decryption methods, which usually take an encrypted string or some One limitation is that execution is limited to static methods.
69
+
70
+ ## Hacking
71
+
72
+ ### Creating Your Own Plugin
73
+ There are three [plugins](lib/dex-oracle/plugins) which come with Oracle:
74
+
75
+ 1. [Undexguard](lib/dex-oracle/plugins/undexguard.rb) - removes certain types of Dexguard obfuscations
76
+ 2. [Unreflector](lib/dex-oracle/plugins/unreflector.rb) - removes some Java reflection
77
+ 3. [String Decryptor](lib/dex-oracle/plugins/string_decryptor.rb) - simple plugin which removes a common type of string encryption
78
+
79
+ If you encounter a new type of obfuscation, it may be possible to deobfuscate with Oracle. Look at the Smali and figure out if the code can either be:
80
+
81
+ 1. rearranged
82
+ 2. understood by executing some static methods
83
+
84
+ If either of these two are the case, you should try and write your own plugin. There are four steps to building your own plugin:
85
+
86
+ 1. identify Smali patterns
87
+ 2. figure out how to simplify the patterns
88
+ 3. figure out how to interact with driver and invoke methods
89
+ 4. figure out how to apply modifications directly
90
+
91
+ The included plugins should be a good guide for understanding steps #3 and #4. Driver is designed to help with step #2.
92
+
93
+ Of course, you're always welcome to share whatever obfuscation you come across and someone may eventually get to it.
94
+
95
+ ### Updating Driver
96
+ First, ensure `dx` is on your path. This is part of the Android SDK, but it's probably not on your path unless you're hardcore.
97
+
98
+ The [driver](driver) folder is a Java project managed by Gradle. Import it into Eclipse, IntelliJ, etc. and make any changes you like. To finish updating the driver, run `./update_driver`. This will rebuild the driver and convert the output JAR into a DEX.
99
+
100
+ ## More Information
101
+
102
+ [TetCon 2016 Android Deobfuscation Presentation](http://www.slideshare.net/tekproxy/tetcon-2016)
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ require_relative '../lib/oracle'
5
+ require_relative '../lib/dex-oracle/smali_input'
6
+ require_relative '../lib/dex-oracle/driver'
7
+ require_relative '../lib/dex-oracle/utility'
8
+ require_relative '../lib/dex-oracle/logging'
9
+
10
+ include Logging
11
+
12
+ options = {
13
+ device_id: ENV['ANDROID_SERIAL'] || '',
14
+ timeout: 60 * 2,
15
+ include_types: nil,
16
+ exclude_types: nil,
17
+ disable_plugins: [],
18
+ }
19
+
20
+ optparse = OptionParser.new do |opts|
21
+ opts.banner = "Usage: #{File.basename(__FILE__)} [opts] <APK / DEX / Smali Directory>"
22
+ opts.on('-h', '--help', 'Display this screen') do
23
+ puts opts
24
+ exit
25
+ end
26
+
27
+ opts.on('-s', '--specific-device ANDROID_SERIAL',
28
+ "Device ID for driver execution, default=\"#{options[:device_id]}\"") do |id|
29
+ options[:device_id] = id
30
+ end
31
+
32
+ opts.on('-t', '--timeout N',
33
+ "ADB command execution timeout in seconds, default=\"#{options[:timeout]}\"") do |id|
34
+ options[:timeout] = id
35
+ end
36
+
37
+ opts.on('-i', '--include PATTERN', Regexp,
38
+ 'Only optimize methods and classes matching the pattern, e.g. Ldune;->melange\(\)V') do |regex|
39
+ options[:include_types] = regex
40
+ end
41
+
42
+ opts.on('-e', '--exclude PATTERN', Regexp,
43
+ 'Exclude these types from optimization; including overrides') do |regex|
44
+ options[:exclude_types] = regex
45
+ end
46
+
47
+ opts.on('--disable-plugins STRING[,STRING]*', String,
48
+ 'Disable plugins, e.g. stringdecryptor,unreflector') do |str|
49
+ options[:disable_plugins] = str.downcase.delete(' ').split(',')
50
+ end
51
+
52
+ opts.on('--list-plugins', 'List available plugins') do
53
+ require_relative '../lib/dex-oracle/plugin'
54
+ puts 'Available plugins:'
55
+ Plugin.plugin_classes.each { |c| puts " #{c}" }
56
+ exit
57
+ end
58
+
59
+ opts.on('-v', '--verbose', 'Be verbose') do
60
+ logger.level = Logger::INFO
61
+ end
62
+
63
+ opts.on('-V', '--vverbose', 'Be very verbose') do
64
+ logger.level = Logger::DEBUG
65
+ end
66
+ end
67
+ optparse.parse!
68
+
69
+ if ARGV.size < 1
70
+ puts optparse.help
71
+ exit(-1)
72
+ end
73
+
74
+ unless Utility.which('adb')
75
+ logger.error 'Unable to find adb command on path. Please make sure you have adb installed and setup.'
76
+ exit(-1)
77
+ end
78
+
79
+ unless `adb devices`.strip != 'List of devices attached'
80
+ logger.error 'It appears you have no devices running. Please start an emulator or plug in a test device.'
81
+ exit(-1)
82
+ end
83
+
84
+ start = Time.now
85
+ input = ARGV[0]
86
+ smali_input = SmaliInput.new(input)
87
+
88
+ driver = Driver.new(options[:device_id], options[:timeout])
89
+ driver.install(smali_input.out_dex)
90
+
91
+ oracle = Oracle.new(
92
+ smali_input.dir, driver, options[:include_types], options[:exclude_types], options[:disable_plugins]
93
+ )
94
+ oracle.divine
95
+
96
+ smali_input.finish
97
+
98
+ puts "Time elapsed #{Time.now - start} seconds"
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push('lib')
3
+ require 'dex-oracle/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'dex-oracle'
7
+ s.version = DexOracle::VERSION.dup
8
+ s.date = '2015-11-28'
9
+ s.license = 'MIT'
10
+ s.summary = 'Pattern based Dalvik deobfuscator'
11
+ s.email = 'calebjfenton@gmail.com'
12
+ s.homepage = 'https://github.com/CalebFenton/dex-oracle'
13
+ s.authors = ['Caleb Fenton']
14
+ s.description = <<-EOF
15
+ A pattern based Dalvik deobfuscator which uses limited execution to improve semantic analysis.
16
+ EOF
17
+
18
+ dependencies = [
19
+ [:runtime, 'rubyzip', '~> 1.1', '>= 1.1.0'],
20
+ [:development, 'rspec', '~> 3.4', '>= 3.4.0'],
21
+ [:development, 'rspec-its', '~> 1.2', '>= 1.2.0'],
22
+ [:development, 'rspec-mocks', '~> 3.4', '>= 3.4.0'],
23
+ ]
24
+
25
+ exclude_files = Dir['driver/build/**/*'] + Dir['driver/bin/**/*'] + Dir['sandbox/**/*'] + ['driver/build', 'driver/bin', 'sandbox']
26
+ s.files = Dir['**/*'] - exclude_files
27
+ s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
28
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
29
+ s.require_paths = %w(lib res)
30
+
31
+ ## Make sure you can build the gem on older versions of RubyGems too:
32
+ s.rubygems_version = '2.2'
33
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
34
+ s.specification_version = 3 if s.respond_to? :specification_version
35
+
36
+ dependencies.each do |type, name, pversion, version|
37
+ if s.respond_to?("add_#{type}_dependency")
38
+ s.send("add_#{type}_dependency", name, pversion, version)
39
+ else
40
+ s.add_dependency(name, pversion, version)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ project.version = '1.0.0'
2
+ version = '1.0.0'
3
+ def jarVersion = version
4
+
5
+ apply plugin: 'application'
6
+ mainClassName = 'org.cf.driver.OracleDriver'
7
+
8
+ repositories {
9
+ mavenCentral()
10
+ }
11
+
12
+ dependencies {
13
+ compile 'com.google.code.gson:gson:2.5'
14
+ // testCompile 'junit:junit:4.12-beta-3'
15
+ }
16
+
17
+ gradle.projectsEvaluated {
18
+ tasks.withType(JavaCompile) {
19
+ options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
20
+ }
21
+ }
22
+
23
+ apply plugin: 'java'
24
+ apply plugin: 'eclipse'
25
+ apply plugin: 'idea'
26
+
27
+ group = 'org.cf'
28
+ sourceCompatibility = 1.7
29
+
30
+ jar {
31
+ version = jarVersion
32
+ }
33
+
34
+ // Build a separate jar that contains all dependencies
35
+ task fatJar(type: Jar) {
36
+ from sourceSets.main.output
37
+ from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
38
+
39
+ manifest {
40
+ attributes('Main-Class': mainClassName)
41
+ }
42
+
43
+ doLast {
44
+ if (!System.getProperty('os.name').toLowerCase().contains('windows')) {
45
+ ant.symlink(link: file("${destinationDir}/driver.jar"), resource: archivePath, overwrite: true)
46
+ }
47
+ }
48
+ }
49
+
50
+ task wrapper(type: Wrapper) {
51
+ gradleVersion = '2.7'
52
+ }
@@ -0,0 +1,6 @@
1
+ #Sun Nov 29 17:30:49 PST 2015
2
+ distributionBase=GRADLE_USER_HOME
3
+ distributionPath=wrapper/dists
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ ##
5
+ ## Gradle start up script for UN*X
6
+ ##
7
+ ##############################################################################
8
+
9
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10
+ DEFAULT_JVM_OPTS=""
11
+
12
+ APP_NAME="Gradle"
13
+ APP_BASE_NAME=`basename "$0"`
14
+
15
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
16
+ MAX_FD="maximum"
17
+
18
+ warn ( ) {
19
+ echo "$*"
20
+ }
21
+
22
+ die ( ) {
23
+ echo
24
+ echo "$*"
25
+ echo
26
+ exit 1
27
+ }
28
+
29
+ # OS specific support (must be 'true' or 'false').
30
+ cygwin=false
31
+ msys=false
32
+ darwin=false
33
+ case "`uname`" in
34
+ CYGWIN* )
35
+ cygwin=true
36
+ ;;
37
+ Darwin* )
38
+ darwin=true
39
+ ;;
40
+ MINGW* )
41
+ msys=true
42
+ ;;
43
+ esac
44
+
45
+ # Attempt to set APP_HOME
46
+ # Resolve links: $0 may be a link
47
+ PRG="$0"
48
+ # Need this for relative symlinks.
49
+ while [ -h "$PRG" ] ; do
50
+ ls=`ls -ld "$PRG"`
51
+ link=`expr "$ls" : '.*-> \(.*\)$'`
52
+ if expr "$link" : '/.*' > /dev/null; then
53
+ PRG="$link"
54
+ else
55
+ PRG=`dirname "$PRG"`"/$link"
56
+ fi
57
+ done
58
+ SAVED="`pwd`"
59
+ cd "`dirname \"$PRG\"`/" >/dev/null
60
+ APP_HOME="`pwd -P`"
61
+ cd "$SAVED" >/dev/null
62
+
63
+ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64
+
65
+ # Determine the Java command to use to start the JVM.
66
+ if [ -n "$JAVA_HOME" ] ; then
67
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68
+ # IBM's JDK on AIX uses strange locations for the executables
69
+ JAVACMD="$JAVA_HOME/jre/sh/java"
70
+ else
71
+ JAVACMD="$JAVA_HOME/bin/java"
72
+ fi
73
+ if [ ! -x "$JAVACMD" ] ; then
74
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75
+
76
+ Please set the JAVA_HOME variable in your environment to match the
77
+ location of your Java installation."
78
+ fi
79
+ else
80
+ JAVACMD="java"
81
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82
+
83
+ Please set the JAVA_HOME variable in your environment to match the
84
+ location of your Java installation."
85
+ fi
86
+
87
+ # Increase the maximum file descriptors if we can.
88
+ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89
+ MAX_FD_LIMIT=`ulimit -H -n`
90
+ if [ $? -eq 0 ] ; then
91
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92
+ MAX_FD="$MAX_FD_LIMIT"
93
+ fi
94
+ ulimit -n $MAX_FD
95
+ if [ $? -ne 0 ] ; then
96
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
97
+ fi
98
+ else
99
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100
+ fi
101
+ fi
102
+
103
+ # For Darwin, add options to specify how the application appears in the dock
104
+ if $darwin; then
105
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106
+ fi
107
+
108
+ # For Cygwin, switch paths to Windows format before running java
109
+ if $cygwin ; then
110
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112
+ JAVACMD=`cygpath --unix "$JAVACMD"`
113
+
114
+ # We build the pattern for arguments to be converted via cygpath
115
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116
+ SEP=""
117
+ for dir in $ROOTDIRSRAW ; do
118
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
119
+ SEP="|"
120
+ done
121
+ OURCYGPATTERN="(^($ROOTDIRS))"
122
+ # Add a user-defined pattern to the cygpath arguments
123
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125
+ fi
126
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
127
+ i=0
128
+ for arg in "$@" ; do
129
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131
+
132
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134
+ else
135
+ eval `echo args$i`="\"$arg\""
136
+ fi
137
+ i=$((i+1))
138
+ done
139
+ case $i in
140
+ (0) set -- ;;
141
+ (1) set -- "$args0" ;;
142
+ (2) set -- "$args0" "$args1" ;;
143
+ (3) set -- "$args0" "$args1" "$args2" ;;
144
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150
+ esac
151
+ fi
152
+
153
+ # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154
+ function splitJvmOpts() {
155
+ JVM_OPTS=("$@")
156
+ }
157
+ eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158
+ JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159
+
160
+ exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"