├── settings.gradle ├── src ├── main │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── org │ │ └── example │ │ ├── Main.java │ │ ├── SmaliUtils.java │ │ └── DexPatch.java └── test │ └── java │ └── test.java ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── vcs.xml ├── encodings.xml ├── misc.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── artifacts │ └── JiaguCleaner_jar.xml └── workspace.xml ├── .gitignore ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'JiaguCleaner' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.example.Main 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 一键修复360加固脱壳后的简单dex。自动移除stub/*相关的冗余代码。自动替换native onCreate方法为简单的默认方法。可修复某些不依赖onCreatea加载组件的App。 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeilongTest/JiaguCleaner/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 19 21:26:48 HKT 2023 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/java/org/example/Main.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.antlr.runtime.RecognitionException; 4 | import java.io.IOException; 5 | 6 | public class Main { 7 | public static void main(String[] args) throws IOException, RecognitionException { 8 | String dexPath = args[0]; 9 | 10 | boolean fix = false; 11 | if(args.length >= 2){ 12 | if(args[1].equals("fix")){ 13 | fix = true; 14 | } 15 | } 16 | DexPatch dexPatch = new DexPatch(); 17 | dexPatch.parseDex(dexPath,fix); 18 | } 19 | } -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/**/build/ 5 | !**/src/test/**/build/ 6 | 7 | ### IntelliJ IDEA ### 8 | .idea/modules.xml 9 | .idea/jarRepositories.xml 10 | .idea/compiler.xml 11 | .idea/libraries/ 12 | *.iws 13 | *.iml 14 | *.ipr 15 | out/ 16 | !**/src/main/**/out/ 17 | !**/src/test/**/out/ 18 | 19 | ### Eclipse ### 20 | .apt_generated 21 | .classpath 22 | .factorypath 23 | .project 24 | .settings 25 | .springBeans 26 | .sts4-cache 27 | bin/ 28 | !**/src/main/**/bin/ 29 | !**/src/test/**/bin/ 30 | 31 | ### NetBeans ### 32 | /nbproject/private/ 33 | /nbbuild/ 34 | /dist/ 35 | /nbdist/ 36 | /.nb-gradle/ 37 | 38 | ### VS Code ### 39 | .vscode/ 40 | 41 | ### Mac OS ### 42 | .DS_Store -------------------------------------------------------------------------------- /src/test/java/test.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.Test; 2 | 3 | public class test { 4 | public static void main(String[] args) { 5 | String source = ".method public final b()Lcom/alipay/android/phone/mrpc/core/ab;\n" + 6 | " .registers 2\n" + 7 | "\n" + 8 | " iget-object v0, p0, Lcom/alipay/android/phone/mrpc/core/i;->b:Lcom/alipay/android/phone/mrpc/core/h;\n" + 9 | "\n" + 10 | " invoke-static {v0}, Lcom/alipay/android/phone/mrpc/core/h;->a(Lcom/alipay/android/phone/mrpc/core/h;)Landroid/content/Context;\n" + 11 | "\n" + 12 | " move-result-object v0\n" + 13 | "\n" + 14 | " invoke-virtual {v0}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;\n" + 15 | "\n" + 16 | " move-result-object v0\n" + 17 | "\n" + 18 | " invoke-static/range {v0 .. v0}, Lcom/stub/StubApp;->getOrigApplicationContext(Landroid/content/Context;)Landroid/content/Context;\n" + 19 | "\n" + 20 | " move-result-object v0\n" + 21 | "\n" + 22 | " invoke-static {v0}, Lcom/alipay/android/phone/mrpc/core/l;->a(Landroid/content/Context;)Lcom/alipay/android/phone/mrpc/core/l;\n" + 23 | "\n" + 24 | " move-result-object v0\n" + 25 | "\n" + 26 | " return-object v0\n" + 27 | ".end method"; 28 | source = source.replaceAll("\n\n invoke-virtual \\{(.*)}, Landroid/content/Context;->getApplicationContext\\(\\)Landroid/content/Context;\n\n move-result-object (.*)",""); 29 | source = source.replaceAll("\n\n invoke-static/range \\{(.*)}, Lcom/stub/StubApp;->getOrigApplicationContext\\(Landroid/content/Context;\\)Landroid/content/Context;\n\n move-result-object (.*)", 30 | ""); 31 | System.out.println(source); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/example/SmaliUtils.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import com.google.common.collect.Iterables; 4 | import org.antlr.runtime.CommonTokenStream; 5 | import org.antlr.runtime.RecognitionException; 6 | import org.antlr.runtime.TokenSource; 7 | import org.antlr.runtime.tree.CommonTree; 8 | import org.antlr.runtime.tree.CommonTreeNodeStream; 9 | import org.jf.dexlib2.Opcodes; 10 | import org.jf.dexlib2.dexbacked.DexBackedClassDef; 11 | import org.jf.dexlib2.dexbacked.DexBackedDexFile; 12 | import org.jf.dexlib2.writer.builder.DexBuilder; 13 | import org.jf.dexlib2.writer.io.MemoryDataStore; 14 | import org.jf.smali.LexerErrorInterface; 15 | import org.jf.smali.smaliFlexLexer; 16 | import org.jf.smali.smaliParser; 17 | import org.jf.smali.smaliTreeWalker; 18 | 19 | import java.io.IOException; 20 | import java.io.Reader; 21 | import java.io.StringReader; 22 | 23 | public class SmaliUtils { 24 | 25 | public static DexBackedClassDef compileSmali(String smaliText) throws RecognitionException, IOException { 26 | return compileSmali(smaliText, 15); 27 | } 28 | 29 | public static DexBackedClassDef compileSmali(String smaliText, int apiLevel) throws RecognitionException, IOException { 30 | DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(apiLevel)); 31 | Reader reader = new StringReader(smaliText); 32 | LexerErrorInterface lexer = new smaliFlexLexer(reader, apiLevel); 33 | //LexerErrorInterface lexer = new smaliFlexLexer(reader); 34 | CommonTokenStream tokens = new CommonTokenStream((TokenSource)lexer); 35 | smaliParser parser = new smaliParser(tokens); 36 | parser.setVerboseErrors(true); 37 | parser.setAllowOdex(false); 38 | parser.setApiLevel(apiLevel); 39 | smaliParser.smali_file_return result = parser.smali_file(); 40 | if (parser.getNumberOfSyntaxErrors() <= 0 && lexer.getNumberOfSyntaxErrors() <= 0) { 41 | CommonTree t = result.getTree(); 42 | CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t); 43 | treeStream.setTokenStream(tokens); 44 | smaliTreeWalker dexGen = new smaliTreeWalker(treeStream); 45 | dexGen.setApiLevel(apiLevel); 46 | dexGen.setVerboseErrors(true); 47 | dexGen.setDexBuilder(dexBuilder); 48 | dexGen.smali_file(); 49 | if (dexGen.getNumberOfSyntaxErrors() > 0) { 50 | throw new RuntimeException("Error occurred while compiling text"); 51 | } else { 52 | MemoryDataStore dataStore = new MemoryDataStore(); 53 | dexBuilder.writeTo(dataStore); 54 | DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.forApi(apiLevel), dataStore.getBuffer()); 55 | return (DexBackedClassDef) Iterables.getFirst(dexFile.getClasses(), (Object)null); 56 | } 57 | } else { 58 | throw new RuntimeException("Error occurred while compiling text"); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /.idea/artifacts/JiaguCleaner_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/JiaguCleaner_jar 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/org/example/DexPatch.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import javafx.scene.SubScene; 4 | import jdk.nashorn.internal.runtime.regexp.joni.Regex; 5 | import org.antlr.runtime.RecognitionException; 6 | import org.jf.baksmali.Adaptors.ClassDefinition; 7 | import org.jf.baksmali.BaksmaliOptions; 8 | import org.jf.baksmali.formatter.BaksmaliWriter; 9 | import org.jf.dexlib2.Opcodes; 10 | import org.jf.dexlib2.dexbacked.DexBackedClassDef; 11 | import org.jf.dexlib2.dexbacked.DexBackedDexFile; 12 | import org.jf.dexlib2.writer.io.MemoryDataStore; 13 | import org.jf.dexlib2.writer.pool.DexPool; 14 | 15 | import java.io.*; 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | public class DexPatch { 23 | 24 | public void parseDex(String dexPath,boolean fix) throws IOException, RecognitionException { 25 | if (dexPath.equals("")){ 26 | System.out.println("please input dexPath!"); 27 | return; 28 | } 29 | String outPath = dexPath.replace(".dex","_out.dex"); 30 | FileInputStream dex = new FileInputStream(dexPath); 31 | DexBackedDexFile dexBackedDexFile = DexBackedDexFile.fromInputStream( 32 | Opcodes.getDefault(), 33 | new BufferedInputStream(dex) 34 | ); 35 | boolean isJiagu = false; 36 | int nativeActivityCount = 0; 37 | List activities = new ArrayList<>(); 38 | DexPool dexPool = new DexPool(Opcodes.getDefault()); 39 | System.out.println("patching..."); 40 | for(DexBackedClassDef classDef: dexBackedDexFile.getClasses()){ 41 | StringWriter stringWriter = new StringWriter(); 42 | BaksmaliWriter writer = new BaksmaliWriter(stringWriter); 43 | ClassDefinition classDefinition = new ClassDefinition(new BaksmaliOptions(), classDef); 44 | classDefinition.writeTo(writer); 45 | writer.close(); 46 | String smali = stringWriter.toString(); 47 | if(smali.contains("stub/Stub")){ 48 | isJiagu = true; 49 | smali = smali.replaceAll("\r\n\r\n invoke-static \\{}, Lcom/stub/StubApp;->mark\\(\\)V",""); 50 | smali = smali.replaceAll("\r\n invoke-static \\{.*}, Lcom/stub/StubApp;->interface.*\\(I\\[Ljava/lang/String;\\[I\\)V",""); 51 | smali = smali.replaceAll("invoke-static \\{.*}, Lcom/stub/StubApp;->interface.*\\(I\\)V", 52 | ""); 53 | smali = smali.replaceAll("\r\n\r\n invoke-static \\{.*}, Lcom/stub/StubApp;->interface.*\\(I\\[Ljava/lang/String;\\[I\\)V", 54 | ""); 55 | smali = smali.replaceAll("\r\n\r\n invoke-static/range \\{(.*)}, Lcom/stub/StubApp;->getOrigApplicationContext\\(Landroid/content/Context;\\)Landroid/content/Context;\r\n\r\n move-result-object (.*)" ,""); 56 | if (smali.contains("stub/Stub")){ 57 | System.out.println("This class has unfix 'stub/Stub' Code:\n" + classDef.toString().substring(1,classDef.toString().length()-1).replaceAll("/",".")); 58 | break; 59 | } 60 | if(smali.contains("native onCreate") || smali.contains("native onRequestPermissionsResult")){ 61 | nativeActivityCount++; 62 | activities.add(classDef.toString()); 63 | if(fix){ 64 | String fixCode = ".method protected onCreate(Landroid/os/Bundle;)V\r\n" + 65 | " .registers 5\n\n" + 66 | " invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V\n\n" + 67 | " return-void\n" + 68 | ".end method"; 69 | String matcher1 = "\\.method (.*) native onCreate\\(Landroid/os/Bundle;\\)V\r\n\\.end method"; 70 | String matcher2 = "\\.method (.*) native onCreate\\(Landroid/os/Bundle;\\)V\r\n \\.param .* # Landroid/os/Bundle;\r\n \\.annotation build Landroidx/annotation/Nullable;\r\n \\.end annotation\r\n \\.end param\r\n\\.end method"; 71 | 72 | 73 | 74 | smali = smali.replaceAll(matcher1,fixCode); 75 | smali = smali.replaceAll(matcher2,fixCode); 76 | 77 | //修复onRequestPermissionsResult 78 | smali = smali.replaceAll("\\.method public native onRequestPermissionsResult([\\s\\S]*)param([\\s\\S]*) \\.end param\r\n\\.end method",""); 79 | 80 | 81 | if (smali.contains("native onCreate") || smali.contains("native onRequestPermissionsResult")){ 82 | System.out.println("This class has unfix native onCreate or onRequestPermissionsResult:\n" + classDef.toString().substring(1,classDef.toString().length()-1).replaceAll("/",".")); 83 | System.out.println(smali); 84 | break; 85 | } 86 | } 87 | } 88 | 89 | //修改的Class写入新Dex 90 | dexPool.internClass(SmaliUtils.compileSmali(smali)); 91 | }else{ 92 | dexPool.internClass(classDef); 93 | } 94 | 95 | 96 | } 97 | if(isJiagu){ 98 | MemoryDataStore dataStore = new MemoryDataStore(); 99 | dexPool.writeTo(dataStore); 100 | byte[] newDexByte = Arrays.copyOf(dataStore.getBuffer(), dataStore.getSize()); 101 | File file = new File(outPath); 102 | FileOutputStream outputStream = null; 103 | outputStream = new FileOutputStream(file); 104 | outputStream.write(newDexByte); 105 | outputStream.close(); 106 | dataStore.close(); 107 | if(!fix){ 108 | System.out.printf("This dex has %d protected Activity! Activities List:\n",nativeActivityCount); 109 | for (String activity : activities) { 110 | System.out.println(activity.substring(1,activity.length()-1).replaceAll("/",".")); 111 | } 112 | } 113 | if(fix){ 114 | System.out.println("This dex is fixed!"); 115 | } 116 | } 117 | } 118 | } 119 | 120 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 44 | { 45 | "keyToString": { 46 | "RunOnceActivity.OpenProjectViewOnStart": "true", 47 | "RunOnceActivity.ShowReadmeOnStart": "true", 48 | "SHARE_PROJECT_CONFIGURATION_FILES": "true", 49 | "git-widget-placeholder": "master", 50 | "last_opened_file_path": "F:/Java android/JiaguCleaner/src/main/java", 51 | "project.structure.last.edited": "工件", 52 | "project.structure.proportion": "0.15", 53 | "project.structure.side.proportion": "0.2", 54 | "settings.editor.selected.configurable": "preferences.pluginManager" 55 | } 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 85 | 86 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 1687181206450 104 | 108 | 109 | 1687877137575 110 | 115 | 118 | 119 | 128 | 129 | 130 | 131 | 133 | 134 | 135 | org.example.* 136 | 137 | 138 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | --------------------------------------------------------------------------------