Flutter 开启混淆打包apk,并反编译apk确认源码是否被混淆

第一步:开启混淆并打包apk

flutter build apk --obfuscate --split-debug-info=./out/android/app.android-arm64.symbols

第二步:从dex2jar download | SourceForge.net 官网下载dex2jar

下载完终端进入该文件夹,然后运行以下命令就会在该文件夹下生成你apk名字的一个jar文件,把该jar文件直接拖入JD-GUI就能看到源码了

sh d2j-dex2jar.sh -f yourapk.apk   

第三步:从网站上下载JD-GUI   Java Decompiler

mac上下载后打开会显示jdk报错,先将下载下来的 jd-gui-osx-1.6.6.tar 解压,然后将 JD-GUI.app 文件拷贝到 Applications 目录下
右击 JD-GUI.app 点击显示包内容

将 Contents/MacOS/universalJavaApplicationStub.sh 文件的内容替换为以下内容,然后重新打开就可以了。

#!/bin/bash
##################################################################################
#                                                                                #
# universalJavaApplicationStub                                                   #
#                                                                                #
# A BASH based JavaApplicationStub for Java Apps on Mac OS X                     #
# that works with both Apple's and Oracle's plist format.                        #
#                                                                                #
# Inspired by Ian Roberts stackoverflow answer                                   #
# at http://stackoverflow.com/a/17546508/1128689                                 #
#                                                                                #
# @author    Tobias Fischer                                                      #
# @url       https://github.com/tofi86/universalJavaApplicationStub              #
# @date      2021-02-21                                                          #
# @version   3.2.0                                                               #
#                                                                                #
##################################################################################
#                                                                                #
# The MIT License (MIT)                                                          #
#                                                                                #
# Copyright (c) 2014-2021 Tobias Fischer                                         #
#                                                                                #
# Permission is hereby granted, free of charge, to any person obtaining a copy   #
# of this software and associated documentation files (the "Software"), to deal  #
# in the Software without restriction, including without limitation the rights   #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      #
# copies of the Software, and to permit persons to whom the Software is          #
# furnished to do so, subject to the following conditions:                       #
#                                                                                #
# The above copyright notice and this permission notice shall be included in all #
# copies or substantial portions of the Software.                                #
#                                                                                #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  #
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  #
# SOFTWARE.                                                                      #
#                                                                                #
################################################################################### function 'stub_logger()'
#
# A logger which logs to the macOS Console.app using the 'syslog' command
#
# @param1  the log message
# @return  void
################################################################################
function stub_logger() {syslog -s -k \Facility com.apple.console \Level Notice \Sender "$(basename "$0")" \Message "[$$][${CFBundleName:-$(basename "$0")}] $1"
}# set the directory abspath of the current
# shell script with symlinks being resolved
############################################PRG=$0
while [ -h "$PRG" ]; dols=$(ls -ld "$PRG")link=$(expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null)if expr "$link" : '^/' 2> /dev/null >/dev/null; thenPRG="$link"elsePRG="$(dirname "$PRG")/$link"fi
done
PROGDIR=$(dirname "$PRG")
stub_logger "[StubDir] $PROGDIR"# set files and folders
############################################# the absolute path of the app package
cd "$PROGDIR"/../../ || exit 11
AppPackageFolder=$(pwd)# the base path of the app package
cd .. || exit 12
AppPackageRoot=$(pwd)# set Apple's Java folder
AppleJavaFolder="${AppPackageFolder}"/Contents/Resources/Java# set Apple's Resources folder
AppleResourcesFolder="${AppPackageFolder}"/Contents/Resources# set Oracle's Java folder
OracleJavaFolder="${AppPackageFolder}"/Contents/Java# set Oracle's Resources folder
OracleResourcesFolder="${AppPackageFolder}"/Contents/Resources# set path to Info.plist in bundle
InfoPlistFile="${AppPackageFolder}"/Contents/Info.plist# set the default JVM Version to a null string
JVMVersion=""
JVMMaxVersion=""# function 'plist_get()'
#
# read a specific Plist key with 'PlistBuddy' utility
#
# @param1  the Plist key with leading colon ':'
# @return  the value as String or Array
################################################################################
plist_get(){/usr/libexec/PlistBuddy -c "print $1" "${InfoPlistFile}" 2> /dev/null
}# function 'plist_get_java()'
#
# read a specific Plist key with 'PlistBuddy' utility
# in the 'Java' or 'JavaX' dictionary (<dict>)
#
# @param1  the Plist :Java(X):Key with leading colon ':'
# @return  the value as String or Array
################################################################################
plist_get_java(){plist_get ${JavaKey:-":Java"}$1
}# read Info.plist and extract JVM options
############################################# read the program name from CFBundleName
CFBundleName=$(plist_get ':CFBundleName')# read the icon file name
CFBundleIconFile=$(plist_get ':CFBundleIconFile')# check Info.plist for Apple style Java keys -> if key :Java is present, parse in apple mode
/usr/libexec/PlistBuddy -c "print :Java" "${InfoPlistFile}" > /dev/null 2>&1
exitcode=$?
JavaKey=":Java"# if no :Java key is present, check Info.plist for universalJavaApplication style JavaX keys -> if key :JavaX is present, parse in apple mode
if [ $exitcode -ne 0 ]; then/usr/libexec/PlistBuddy -c "print :JavaX" "${InfoPlistFile}" > /dev/null 2>&1exitcode=$?JavaKey=":JavaX"
fi# read 'Info.plist' file in Apple style if exit code returns 0 (true, ':Java' key is present)
if [ $exitcode -eq 0 ]; thenstub_logger "[PlistStyle] Apple"# set Java and Resources folderJavaFolder="${AppleJavaFolder}"ResourcesFolder="${AppleResourcesFolder}"# set expandable variablesAPP_ROOT="${AppPackageFolder}"APP_PACKAGE="${AppPackageFolder}"JAVAROOT="${AppleJavaFolder}"USER_HOME="$HOME"# read the Java WorkingDirectoryJVMWorkDir=$(plist_get_java ':WorkingDirectory' | xargs)# set Working Directory based upon PList valueif [[ ! -z ${JVMWorkDir} ]]; thenWorkingDirectory="${JVMWorkDir}"else# AppPackageRoot is the standard WorkingDirectory when the script is startedWorkingDirectory="${AppPackageRoot}"fi# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOMEWorkingDirectory=$(eval echo "${WorkingDirectory}")# read the MainClass nameJVMMainClass="$(plist_get_java ':MainClass')"# read the SplashFile nameJVMSplashFile=$(plist_get_java ':SplashFile')# read the JVM Properties as an array and retain spacesIFS=$'\t\n'JVMOptions=($(xargs -n1 <<<$(plist_get_java ':Properties' | grep " =" | sed 's/^ */-D/g' | sed -E 's/ = (.*)$/="\1"/g')))unset IFS# post processing of the array follows further below...# read the ClassPath in either Array or String styleJVMClassPath_RAW=$(plist_get_java ':ClassPath' | xargs)if [[ $JVMClassPath_RAW == *Array* ]] ; thenJVMClassPath=.$(plist_get_java ':ClassPath' | grep "    " | sed 's/^ */:/g' | tr -d '\n' | xargs)elseJVMClassPath=${JVMClassPath_RAW}fi# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOMEJVMClassPath=$(eval echo "${JVMClassPath}")# read the JVM Options in either Array or String styleJVMDefaultOptions_RAW=$(plist_get_java ':VMOptions' | xargs)if [[ $JVMDefaultOptions_RAW == *Array* ]] ; thenJVMDefaultOptions=$(plist_get_java ':VMOptions' | grep "    " | sed 's/^ */ /g' | tr -d '\n' | xargs)elseJVMDefaultOptions=${JVMDefaultOptions_RAW}fi# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME (#84)JVMDefaultOptions=$(eval echo "${JVMDefaultOptions}")# read StartOnMainThread and add as -XstartOnFirstThreadJVMStartOnMainThread=$(plist_get_java ':StartOnMainThread')if [ "${JVMStartOnMainThread}" == "true" ]; thenJVMDefaultOptions+=" -XstartOnFirstThread"fi# read the JVM Arguments in either Array or String style (#76) and retain spacesIFS=$'\t\n'MainArgs_RAW=$(plist_get_java ':Arguments' | xargs)if [[ $MainArgs_RAW == *Array* ]] ; thenMainArgs=($(xargs -n1 <<<$(plist_get_java ':Arguments' | tr -d '\n' | sed -E 's/Array \{ *(.*) *\}/\1/g' | sed 's/  */ /g')))elseMainArgs=($(xargs -n1 <<<$(plist_get_java ':Arguments')))fiunset IFS# post processing of the array follows further below...# read the Java version we want to findJVMVersion=$(plist_get_java ':JVMVersion' | xargs)# post processing of the version string follows below...# read 'Info.plist' file in Oracle style
elsestub_logger "[PlistStyle] Oracle"# set Working Directory and Java and Resources folderJavaFolder="${OracleJavaFolder}"ResourcesFolder="${OracleResourcesFolder}"WorkingDirectory="${OracleJavaFolder}"# set expandable variablesAPP_ROOT="${AppPackageFolder}"APP_PACKAGE="${AppPackageFolder}"JAVAROOT="${OracleJavaFolder}"USER_HOME="$HOME"# read the MainClass nameJVMMainClass="$(plist_get ':JVMMainClassName')"# read the SplashFile nameJVMSplashFile=$(plist_get ':JVMSplashFile')# read the JVM Options as an array and retain spacesIFS=$'\t\n'JVMOptions=($(plist_get ':JVMOptions' | grep "    " | sed 's/^ *//g'))unset IFS# post processing of the array follows further below...# read the ClassPath in either Array or String styleJVMClassPath_RAW=$(plist_get ':JVMClassPath')if [[ $JVMClassPath_RAW == *Array* ]] ; thenJVMClassPath=.$(plist_get ':JVMClassPath' | grep "    " | sed 's/^ */:/g' | tr -d '\n' | xargs)# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOMEJVMClassPath=$(eval echo "${JVMClassPath}")elif [[ ! -z ${JVMClassPath_RAW} ]] ; thenJVMClassPath=${JVMClassPath_RAW}# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOMEJVMClassPath=$(eval echo "${JVMClassPath}")else#default: fallback to OracleJavaFolderJVMClassPath="${JavaFolder}/*"# Do NOT expand the default 'AppName.app/Contents/Java/*' classpath (#42)fi# read the JVM Default Options by parsing the :JVMDefaultOptions <dict># and pulling all <string> values starting with a dash (-)JVMDefaultOptions=$(plist_get ':JVMDefaultOptions' | grep -o " \-.*" | tr -d '\n' | xargs)# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME (#99)JVMDefaultOptions=$(eval echo "${JVMDefaultOptions}")# read the Main Arguments from JVMArguments key as an array and retain spaces (see #46 for naming details)IFS=$'\t\n'MainArgs=($(xargs -n1 <<<$(plist_get ':JVMArguments' | tr -d '\n' | sed -E 's/Array \{ *(.*) *\}/\1/g' | sed 's/  */ /g')))unset IFS# post processing of the array follows further below...# read the Java version we want to findJVMVersion=$(plist_get ':JVMVersion' | xargs)# post processing of the version string follows below...
fi# (#75) check for undefined icons or icon names without .icns extension and prepare
# an osascript statement for those cases when the icon can be shown in the dialog
DialogWithIcon=""
if [ ! -z ${CFBundleIconFile} ]; thenif [[ ${CFBundleIconFile} == *.icns ]] && [[ -f "${ResourcesFolder}/${CFBundleIconFile}" ]] ; thenDialogWithIcon=" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"elif [[ ${CFBundleIconFile} != *.icns ]] && [[ -f "${ResourcesFolder}/${CFBundleIconFile}.icns" ]] ; thenCFBundleIconFile+=".icns"DialogWithIcon=" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"fi
fi# JVMVersion: post processing and optional splitting
if [[ ${JVMVersion} == *";"* ]]; thenminMaxArray=(${JVMVersion//;/ })JVMVersion=${minMaxArray[0]//+}JVMMaxVersion=${minMaxArray[1]//+}
fi
stub_logger "[JavaRequirement] JVM minimum version: ${JVMVersion}"
stub_logger "[JavaRequirement] JVM maximum version: ${JVMMaxVersion}"# MainArgs: expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
MainArgsArr=()
for i in "${MainArgs[@]}"
doMainArgsArr+=("$(eval echo "$i")")
done# JVMOptions: expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
JVMOptionsArr=()
for i in "${JVMOptions[@]}"
doJVMOptionsArr+=("$(eval echo "$i")")
done# internationalized messages
############################################# supported languages / available translations
stubLanguages="^(fr|de|zh|es|en)-"# read user preferred languages as defined in macOS System Preferences (#101)
stub_logger '[LanguageSearch] Checking preferred languages in macOS System Preferences...'
appleLanguages=($(defaults read -g AppleLanguages | grep '\s"' | tr -d ',' | xargs))
stub_logger "[LanguageSearch] ... found [${appleLanguages[*]}]"language=""
for i in "${appleLanguages[@]}"
dolangValue="${i%-*}"if [[ "$i" =~ $stubLanguages ]]; then stub_logger "[LanguageSearch] ... selected '$i' ('$langValue') as the default language for the launcher stub"language=${langValue}breakfi
done
if [ -z "${language}" ]; thenlanguage="en"stub_logger "[LanguageSearch] ... selected fallback 'en' as the default language for the launcher stub"
fi
stub_logger "[Language] $language"case "${language}" in
# French
fr)MSG_ERROR_LAUNCHING="ERREUR au lancement de '${CFBundleName}'."MSG_MISSING_MAINCLASS="'MainClass' n'est pas spécifié.\nL'application Java ne peut pas être lancée."MSG_JVMVERSION_REQ_INVALID="La syntaxe de la version de Java demandée est invalide: %s\nVeuillez contacter le développeur de l'application."MSG_NO_SUITABLE_JAVA="La version de Java installée sur votre système ne convient pas.\nCe programme nécessite Java %s"MSG_JAVA_VERSION_OR_LATER="ou ultérieur"MSG_JAVA_VERSION_LATEST="(dernière mise à jour)"MSG_JAVA_VERSION_MAX="à %s"MSG_NO_SUITABLE_JAVA_CHECK="Merci de bien vouloir installer la version de Java requise."MSG_INSTALL_JAVA="Java doit être installé sur votre système.\nRendez-vous sur java.com et suivez les instructions d'installation..."MSG_LATER="Plus tard"MSG_VISIT_JAVA_DOT_COM="Java by Oracle"MSG_VISIT_ADOPTOPENJDK="Java by AdoptOpenJDK";;# German
de)MSG_ERROR_LAUNCHING="FEHLER beim Starten von '${CFBundleName}'."MSG_MISSING_MAINCLASS="Die 'MainClass' ist nicht spezifiziert!\nDie Java-Anwendung kann nicht gestartet werden!"MSG_JVMVERSION_REQ_INVALID="Die Syntax der angeforderten Java-Version ist ungültig: %s\nBitte kontaktieren Sie den Entwickler der App."MSG_NO_SUITABLE_JAVA="Es wurde keine passende Java-Version auf Ihrem System gefunden!\nDieses Programm benötigt Java %s"MSG_JAVA_VERSION_OR_LATER="oder neuer"MSG_JAVA_VERSION_LATEST="(neuste Unterversion)"MSG_JAVA_VERSION_MAX="bis %s"MSG_NO_SUITABLE_JAVA_CHECK="Stellen Sie sicher, dass die angeforderte Java-Version installiert ist."MSG_INSTALL_JAVA="Auf Ihrem System muss die 'Java'-Software installiert sein.\nBesuchen Sie java.com für weitere Installationshinweise."MSG_LATER="Später"MSG_VISIT_JAVA_DOT_COM="Java von Oracle"MSG_VISIT_ADOPTOPENJDK="Java von AdoptOpenJDK";;# Simplified Chinese
zh)MSG_ERROR_LAUNCHING="无法启动 '${CFBundleName}'."MSG_MISSING_MAINCLASS="没有指定 'MainClass'!\nJava程序无法启动!"MSG_JVMVERSION_REQ_INVALID="Java版本参数语法错误: %s\n请联系该应用的开发者。"MSG_NO_SUITABLE_JAVA="没有在系统中找到合适的Java版本!\n必须安装Java %s才能够使用该程序!"MSG_JAVA_VERSION_OR_LATER="及以上版本"MSG_JAVA_VERSION_LATEST="(最新版本)"MSG_JAVA_VERSION_MAX="最高为 %s"MSG_NO_SUITABLE_JAVA_CHECK="请确保系统中安装了所需的Java版本"MSG_INSTALL_JAVA="你需要在Mac中安装Java运行环境!\n访问 java.com 了解如何安装。"MSG_LATER="稍后"MSG_VISIT_JAVA_DOT_COM="Java by Oracle"MSG_VISIT_ADOPTOPENJDK="Java by AdoptOpenJDK";;# Spanish
es)MSG_ERROR_LAUNCHING="ERROR iniciando '${CFBundleName}'."MSG_MISSING_MAINCLASS="¡'MainClass' no especificada!\n¡La aplicación Java no puede iniciarse!"MSG_JVMVERSION_REQ_INVALID="La sintaxis de la versión Java requerida no es válida: %s\nPor favor, contacte con el desarrollador de la aplicación."MSG_NO_SUITABLE_JAVA="¡No se encontró una versión de Java adecuada en su sistema!\nEste programa requiere Java %s"MSG_JAVA_VERSION_OR_LATER="o posterior"MSG_JAVA_VERSION_LATEST="(ultima actualización)"MSG_JAVA_VERSION_MAX="superior a %s"MSG_NO_SUITABLE_JAVA_CHECK="Asegúrese de instalar la versión Java requerida."MSG_INSTALL_JAVA="¡Necesita tener JAVA instalado en su Mac!\nVisite java.com para consultar las instrucciones para su instalación..."MSG_LATER="Más tarde"MSG_VISIT_JAVA_DOT_COM="Java de Oracle"MSG_VISIT_ADOPTOPENJDK="Java de AdoptOpenJDK";;# English | default
en|*)MSG_ERROR_LAUNCHING="ERROR launching '${CFBundleName}'."MSG_MISSING_MAINCLASS="'MainClass' isn't specified!\nJava application cannot be started!"MSG_JVMVERSION_REQ_INVALID="The syntax of the required Java version is invalid: %s\nPlease contact the App developer."MSG_NO_SUITABLE_JAVA="No suitable Java version found on your system!\nThis program requires Java %s"MSG_JAVA_VERSION_OR_LATER="or later"MSG_JAVA_VERSION_LATEST="(latest update)"MSG_JAVA_VERSION_MAX="up to %s"MSG_NO_SUITABLE_JAVA_CHECK="Make sure you install the required Java version."MSG_INSTALL_JAVA="You need to have JAVA installed on your Mac!\nVisit java.com for installation instructions..."MSG_LATER="Later"MSG_VISIT_JAVA_DOT_COM="Java by Oracle"MSG_VISIT_ADOPTOPENJDK="Java by AdoptOpenJDK";;
esac# function 'get_java_version_from_cmd()'
#
# returns Java version string from 'java -version' command
# works for both old (1.8) and new (9) version schema
#
# @param1  path to a java JVM executable
# @return  the Java version number as displayed in 'java -version' command
################################################################################
function get_java_version_from_cmd() {# second sed command strips " and -ea from the version stringecho $("$1" -version 2>&1 | awk '/version/{print $3}' | sed -E 's/"//g;s/-ea//g')
}# function 'extract_java_major_version()'
#
# extract Java major version from a version string
#
# @param1  a Java version number ('1.8.0_45') or requirement string ('1.8+')
# @return  the major version (e.g. '7', '8' or '9', etc.)
################################################################################
function extract_java_major_version() {echo $(echo "$1" | sed -E 's/^1\.//;s/^([0-9]+)(-ea|(\.[0-9_.]{1,7})?)(-b[0-9]+-[0-9]+)?[+*]?$/\1/')
}# function 'get_comparable_java_version()'
#
# return comparable version for a Java version number or requirement string
#
# @param1  a Java version number ('1.8.0_45') or requirement string ('1.8+')
# @return  an 8 digit numeral ('1.8.0_45'->'08000045'; '9.1.13'->'09001013')
################################################################################
function get_comparable_java_version() {# cleaning: 1) remove leading '1.'; 2) remove build string (e.g. '-b14-468'); 3) remove 'a-Z' and '-*+' (e.g. '-ea'); 4) replace '_' with '.'local cleaned=$(echo "$1" | sed -E 's/^1\.//g;s/-b[0-9]+-[0-9]+$//g;s/[a-zA-Z+*\-]//g;s/_/./g')# splitting at '.' into an arraylocal arr=( ${cleaned//./ } )# echo a string with left padded version numbersecho "$(printf '%02s' ${arr[0]})$(printf '%03s' ${arr[1]})$(printf '%03s' ${arr[2]})"
}# function 'is_valid_requirement_pattern()'
#
# check whether the Java requirement is a valid requirement pattern
#
# supported requirements are for example:
# - 1.6       requires Java 6 (any update)      [1.6, 1.6.0_45, 1.6.0_88]
# - 1.6*      requires Java 6 (any update)      [1.6, 1.6.0_45, 1.6.0_88]
# - 1.6+      requires Java 6 or higher         [1.6, 1.6.0_45, 1.8, 9, etc.]
# - 1.6.0     requires Java 6 (any update)      [1.6, 1.6.0_45, 1.6.0_88]
# - 1.6.0_45  requires Java 6u45                [1.6.0_45]
# - 1.6.0_45+ requires Java 6u45 or higher      [1.6.0_45, 1.6.0_88, 1.8, etc.]
# - 9         requires Java 9 (any update)      [9.0.*, 9.1, 9.3, etc.]
# - 9*        requires Java 9 (any update)      [9.0.*, 9.1, 9.3, etc.]
# - 9+        requires Java 9 or higher         [9.0, 9.1, 10, etc.]
# - 9.1       requires Java 9.1 (any update)    [9.1.*, 9.1.2, 9.1.13, etc.]
# - 9.1*      requires Java 9.1 (any update)    [9.1.*, 9.1.2, 9.1.13, etc.]
# - 9.1+      requires Java 9.1 or higher       [9.1, 9.2, 10, etc.]
# - 9.1.3     requires Java 9.1.3               [9.1.3]
# - 9.1.3*    requires Java 9.1.3 (any update)  [9.1.3]
# - 9.1.3+    requires Java 9.1.3 or higher     [9.1.3, 9.1.4, 9.2.*, 10, etc.]
# - 10-ea     requires Java 10 (early access release)
#
# unsupported requirement patterns are for example:
# - 1.2, 1.3, 1.9       Java 2, 3 are not supported
# - 1.9                 Java 9 introduced a new versioning scheme
# - 6u45                known versioning syntax, but unsupported
# - 9-ea*, 9-ea+        early access releases paired with */+
# - 9., 9.*, 9.+        version ending with a .
# - 9.1., 9.1.*, 9.1.+  version ending with a .
# - 9.3.5.6             4 part version number is unsupported
#
# @param1  a Java requirement string ('1.8+')
# @return  boolean exit code: 0 (is valid), 1 (is not valid)
################################################################################
function is_valid_requirement_pattern() {local java_req=$1java8pattern='1\.[4-8](\.[0-9]+)?(\.0_[0-9]+)?[*+]?'java9pattern='(9|1[0-9])(-ea|[*+]|(\.[0-9]+){1,2}[*+]?)?'# test matches either old Java versioning scheme (up to 1.8) or new scheme (starting with 9)if [[ ${java_req} =~ ^(${java8pattern}|${java9pattern})$ ]]; thenreturn 0elsereturn 1fi
}# determine which JVM to use
############################################# default Apple JRE plugin path (< 1.6)
apple_jre_plugin="/Library/Java/Home/bin/java"
apple_jre_version=$(get_java_version_from_cmd "${apple_jre_plugin}")
# default Oracle JRE plugin path (>= 1.7)
oracle_jre_plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
oracle_jre_version=$(get_java_version_from_cmd "${oracle_jre_plugin}")# first check system variable "$JAVA_HOME" -> has precedence over any other System JVM
stub_logger '[JavaSearch] Checking for $JAVA_HOME ...'
if [ -n "$JAVA_HOME" ] ; thenstub_logger "[JavaSearch] ... found JAVA_HOME with value $JAVA_HOME"# PR 26: Allow specifying "$JAVA_HOME" relative to "$AppPackageFolder"# which allows for bundling a custom version of Java inside your app!if [[ $JAVA_HOME == /* ]] ; then# if "$JAVA_HOME" starts with a Slash it's an absolute pathJAVACMD="$JAVA_HOME/bin/java"stub_logger "[JavaSearch] ... parsing JAVA_HOME as absolute path to the executable '$JAVACMD'"else# otherwise it's a relative path to "$AppPackageFolder"JAVACMD="$AppPackageFolder/$JAVA_HOME/bin/java"stub_logger "[JavaSearch] ... parsing JAVA_HOME as relative path inside the App bundle to the executable '$JAVACMD'"fiJAVACMD_version=$(get_comparable_java_version $(get_java_version_from_cmd "${JAVACMD}"))
elsestub_logger "[JavaSearch] ... haven't found JAVA_HOME"
fi# check for any other or a specific Java version
# also if $JAVA_HOME exists but isn't executable
if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then# add a warning in the syslog if JAVA_HOME is not executable or not found (#100)if [ -n "$JAVA_HOME" ] ; thenstub_logger "[JavaSearch] ... but no 'java' executable was found at the JAVA_HOME location!"fistub_logger "[JavaSearch] Searching for JavaVirtualMachines on the system ..."# reset variablesJAVACMD=""JAVACMD_version=""# first check whether JVMVersion string is a valid requirement stringif [ ! -z "${JVMVersion}" ] && ! is_valid_requirement_pattern ${JVMVersion} ; thenMSG_JVMVERSION_REQ_INVALID_EXPANDED=$(printf "${MSG_JVMVERSION_REQ_INVALID}" "${JVMVersion}")# log exit causestub_logger "[EXIT 4] ${MSG_JVMVERSION_REQ_INVALID_EXPANDED}"# display error message with AppleScriptosascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1${DialogWithIcon}"# exit with errorexit 4fi# then check whether JVMMaxVersion string is a valid requirement stringif [ ! -z "${JVMMaxVersion}" ] && ! is_valid_requirement_pattern ${JVMMaxVersion} ; thenMSG_JVMVERSION_REQ_INVALID_EXPANDED=$(printf "${MSG_JVMVERSION_REQ_INVALID}" "${JVMMaxVersion}")# log exit causestub_logger "[EXIT 5] ${MSG_JVMVERSION_REQ_INVALID_EXPANDED}"# display error message with AppleScriptosascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1${DialogWithIcon}"# exit with errorexit 5fi# find installed JavaVirtualMachines (JDK + JRE)allJVMs=()# read JDK's from '/usr/libexec/java_home --xml' command with PlistBuddy and a custom Dict iterator# idea: https://stackoverflow.com/a/14085460/1128689 and https://scriptingosx.com/2018/07/parsing-dscl-output-in-scripts/javaXml=$(/usr/libexec/java_home --xml)javaCounter=$(/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< $javaXml | grep "Dict" | wc -l | tr -d ' ')# iterate over all Dict entries# but only if there are any JVMs at all (#93)if [ "$javaCounter" -gt "0" ] ; thenfor idx in $(seq 0 $((javaCounter - 1)))doversion=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)path+="/bin/java"allJVMs+=("$version:$path")done# unset for loop variablesunset version pathfi# add SDKMAN! java versions (#95)if [ -d ~/.sdkman/candidates/java/ ] ; thenfor sdkjdk in ~/.sdkman/candidates/java/*/doif [[ ${sdkjdk} =~ /current/$ ]] ; thencontinuefisdkjdkcmd="${sdkjdk}bin/java"version=$(get_java_version_from_cmd "${sdkjdkcmd}")allJVMs+=("$version:$sdkjdkcmd")done# unset for loop variablesunset versionfi# add Apple JRE if availableif [ -x "${apple_jre_plugin}" ] ; thenallJVMs+=("$apple_jre_version:$apple_jre_plugin")fi# add Oracle JRE if availableif [ -x "${oracle_jre_plugin}" ] ; thenallJVMs+=("$oracle_jre_version:$oracle_jre_plugin")fi# debug outputfor i in "${allJVMs[@]}"dostub_logger "[JavaSearch] ... found JVM: $i"done# determine JVMs matching the min/max version requirementstub_logger "[JavaSearch] Filtering the result list for JVMs matching the min/max version requirement ..."minC=$(get_comparable_java_version ${JVMVersion})maxC=$(get_comparable_java_version ${JVMMaxVersion})matchingJVMs=()for i in "${allJVMs[@]}"do# split JVM string at ':' delimiter to retain spaces in $path substringIFS=: arr=($i) ; unset IFS# [0] JVM version numberver=${arr[0]}# comparable JVM version numbercomp=$(get_comparable_java_version $ver)# [1] JVM pathpath="${arr[1]}"# construct string item for adding to the "matchingJVMs" arrayitem="$comp:$ver:$path"# pre-requisite: current version number needs to be greater than min version numberif [ "$comp" -ge "$minC" ] ; then# perform max version checks if max version requirement is presentif [ ! -z ${JVMMaxVersion} ] ; then# max version requirement ends with '*' modifierif [[ ${JVMMaxVersion} == *\* ]] ; then# use the '*' modifier from the max version string as wildcard for a 'starts with' comparison# and check whether the current version number starts with the max version wildcard stringif [[ ${ver} == ${JVMMaxVersion} ]]; thenmatchingJVMs+=("$item")# or whether the current comparable version is lower than the comparable max versionelif [ "$comp" -le "$maxC" ] ; thenmatchingJVMs+=("$item")fi# max version requirement ends with '+' modifier -> always add this version if it's greater than $min# because a max requirement with + modifier doesn't make senseelif [[ ${JVMMaxVersion} == *+ ]] ; thenmatchingJVMs+=("$item")# matches 6 zeros at the end of the max version string (e.g. for 1.8, 9)# -> then the max version string should be treated like with a '*' modifier at the end#elif [[ ${maxC} =~ ^[0-9]{2}0{6}$ ]] && [ "$comp" -le $(( ${maxC#0} + 999 )) ] ; then#	matchingJVMs+=("$item")# matches 3 zeros at the end of the max version string (e.g. for 9.1, 10.3)# -> then the max version string should be treated like with a '*' modifier at the end#elif [[ ${maxC} =~ ^[0-9]{5}0{3}$ ]] && [ "$comp" -le "${maxC}" ] ; then#	matchingJVMs+=("$item")# matches standard requirements without modifierelif [ "$comp" -le "$maxC" ]; thenmatchingJVMs+=("$item")fi# no max version requirement:# min version requirement ends with '+' modifier# -> always add the current version because it's greater than $minelif [[ ${JVMVersion} == *+ ]] ; thenmatchingJVMs+=("$item")# min version requirement ends with '*' modifier# -> use the '*' modifier from the min version string as wildcard for a 'starts with' comparison#    and check whether the current version number starts with the min version wildcard stringelif [[ ${JVMVersion} == *\* ]] ; thenif [[ ${ver} == ${JVMVersion} ]] ; thenmatchingJVMs+=("$item")fi# compare the min version against the current version with an additional * wildcard for a 'starts with' comparison# -> e.g. add 1.8.0_44 when the requirement is 1.8elif [[ ${ver} == ${JVMVersion}* ]] ; thenmatchingJVMs+=("$item")fifidone# unset for loop variablesunset arr ver comp path item# debug outputfor i in "${matchingJVMs[@]}"dostub_logger "[JavaSearch] ... matches all requirements: $i"done# sort the matching JavaVirtualMachines by version number# https://stackoverflow.com/a/11789688/1128689IFS=$'\n' matchingJVMs=($(sort -nr <<<"${matchingJVMs[*]}"))unset IFS# get the highest matching JVMfor ((i = 0; i < ${#matchingJVMs[@]}; i++));do# split JVM string at ':' delimiter to retain spaces in $path substringIFS=: arr=(${matchingJVMs[$i]}) ; unset IFS# [0] comparable JVM version numbercomp=${arr[0]}# [1] JVM version numberver=${arr[1]}# [2] JVM pathpath="${arr[2]}"# use current value as JAVACMD if it's executableif [ -x "$path" ] ; thenJAVACMD="$path"JAVACMD_version=$compbreakfidone# unset for loop variablesunset arr comp ver path
fi# log the Java Command and the extracted version number
stub_logger "[JavaCommand] '$JAVACMD'"
stub_logger "[JavaVersion] $(get_java_version_from_cmd "${JAVACMD}")${JAVACMD_version:+ / $JAVACMD_version}"if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then# different error messages when a specific JVM was requiredif [ ! -z "${JVMVersion}" ] ; then# display human readable java version (#28)java_version_hr=$(echo ${JVMVersion} | sed -E 's/^1\.([0-9+*]+)$/ \1/g' | sed "s/+/ ${MSG_JAVA_VERSION_OR_LATER}/;s/*/ ${MSG_JAVA_VERSION_LATEST}/")MSG_NO_SUITABLE_JAVA_EXPANDED=$(printf "${MSG_NO_SUITABLE_JAVA}" "${java_version_hr}").if [ ! -z "${JVMMaxVersion}" ] ; thenjava_version_hr=$(extract_java_major_version ${JVMVersion})java_version_max_hr=$(echo ${JVMMaxVersion} | sed -E 's/^1\.([0-9+*]+)$/ \1/g' | sed "s/+//;s/*/ ${MSG_JAVA_VERSION_LATEST}/")MSG_NO_SUITABLE_JAVA_EXPANDED="$(printf "${MSG_NO_SUITABLE_JAVA}" "${java_version_hr}") $(printf "${MSG_JAVA_VERSION_MAX}" "${java_version_max_hr}")"fi# log exit causestub_logger "[EXIT 3] ${MSG_NO_SUITABLE_JAVA_EXPANDED}"# display error message with AppleScriptosascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_NO_SUITABLE_JAVA_EXPANDED}\n${MSG_NO_SUITABLE_JAVA_CHECK}\" with title \"${CFBundleName}\"  buttons {\" OK \", \"${MSG_VISIT_JAVA_DOT_COM}\", \"${MSG_VISIT_ADOPTOPENJDK}\"} default button 1${DialogWithIcon}" \-e "set response to button returned of the result" \-e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"https://www.java.com/download/\"" \-e "if response is \"${MSG_VISIT_ADOPTOPENJDK}\" then open location \"https://adoptopenjdk.net/releases.html\""# exit with errorexit 3else# log exit causestub_logger "[EXIT 1] ${MSG_ERROR_LAUNCHING}"# display error message with AppleScriptosascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_INSTALL_JAVA}\" with title \"${CFBundleName}\" buttons {\"${MSG_LATER}\", \"${MSG_VISIT_JAVA_DOT_COM}\", \"${MSG_VISIT_ADOPTOPENJDK}\"} default button 1${DialogWithIcon}" \-e "set response to button returned of the result" \-e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"https://www.java.com/download/\"" \-e "if response is \"${MSG_VISIT_ADOPTOPENJDK}\" then open location \"https://adoptopenjdk.net/releases.html\""# exit with errorexit 1fi
fi# MainClass check
############################################if [ -z "${JVMMainClass}" ]; then# log exit causestub_logger "[EXIT 2] ${MSG_MISSING_MAINCLASS}"# display error message with AppleScriptosascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_MISSING_MAINCLASS}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1${DialogWithIcon}"# exit with errorexit 2
fi# execute $JAVACMD and do some preparation
############################################# enable drag&drop to the dock icon
export CFProcessPath="$0"# remove Apples ProcessSerialNumber from passthru arguments (#39)
if [[ "$*" == -psn* ]] ; thenArgsPassthru=()
elseArgsPassthru=("$@")
fi# change to Working Directory based upon Apple/Oracle Plist info
cd "${WorkingDirectory}" || exit 13
stub_logger "[WorkingDirectory] ${WorkingDirectory}"# execute Java and set
# - classpath
# - splash image
# - dock icon
# - app name
# - JVM options / properties (-D)
# - JVM default options (-X)
# - main class
# - main class arguments
# - passthrough arguments from Terminal or Drag'n'Drop to Finder icon
stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" ${JVMSplashFile:+ -splash:\"${ResourcesFolder}/${JVMSplashFile}\"} -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptionsArr:+$(printf "'%s' " "${JVMOptionsArr[@]}") }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgsArr:+ $(printf "'%s' " "${MainArgsArr[@]}")}${ArgsPassthru:+ $(printf "'%s' " "${ArgsPassthru[@]}")}"
exec "${JAVACMD}" \-cp "${JVMClassPath}" \${JVMSplashFile:+ -splash:"${ResourcesFolder}/${JVMSplashFile}"} \-Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \-Xdock:name="${CFBundleName}" \${JVMOptionsArr:+"${JVMOptionsArr[@]}" }\${JVMDefaultOptions:+$JVMDefaultOptions }\"${JVMMainClass}"\${MainArgsArr:+ "${MainArgsArr[@]}"}\${ArgsPassthru:+ "${ArgsPassthru[@]}"}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/43622.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

分享五款软件,成为高效生活的好助手

​ 给大家分享一些优秀的软件工具,是一件让人很愉悦的事情&#xff0c;今天继续带来5款优质软件。 1.图片放大——Bigjpg ​ Bigjpg是一款图片放大软件&#xff0c;采用先进的AI算法&#xff0c;能够在不损失图片质量的前提下&#xff0c;将低分辨率图片放大至所需尺寸。无论…

Windows10 企业版 LTSC 2021发布:一键点击获取!

Windows10企业版 LTSC 2021是微软发布的长达5年技术支持的Win10稳定版本&#xff0c;追求稳定的企业或者个人特别适合安装该系统版本。该版本离线制作而成&#xff0c;安全性高&#xff0c;兼容性出色&#xff0c;适合新老机型安装&#xff0c;力求带给用户更稳定、高效的操作系…

【第24章】MyBatis-Plus之SQL注入器

文章目录 前言一、概述1. 使用场景2. 功能 二、注入器配置三、自定义全局方法攻略1. 定义SQL2. 注册自定义方法3.定义BaseMapper4.配置SqlInjector 四、注意事项五、更多示例六、实战1. 定义SQL2. 注册自定义方法3.定义BaseMapper4.配置SqlInjector5. 测试类6. 结果 总结 前言 …

Linux开机自启动连接wifi

&#x1f308;个人主页&#xff1a;Rookie Maker &#x1f525; 系列专栏&#xff1a;Linux &#x1f3c6;&#x1f3c6;关注博主&#xff0c;随时获取更多关于IT的优质内容&#xff01;&#x1f3c6;&#x1f3c6; &#x1f600;欢迎来到我的代码世界~ &#x1f601; 喜欢的…

P8306 【模板】字典树

题目描述 给定 n 个模式串 s1​,s2​,…,sn​ 和 q 次询问&#xff0c;每次询问给定一个文本串 ti​&#xff0c;请回答 s1​∼sn​ 中有多少个字符串 sj​ 满足 ti​ 是 sj​ 的前缀。 一个字符串 t 是 s 的前缀当且仅当从 s 的末尾删去若干个&#xff08;可以为 0 个&#…

2.贪心算法.基础

2.贪心算法.基础 基础知识题目1.分发饼干2.摆动序列3.最大子序和4.买股票的最佳时机24.2.买股票的最佳时机5.跳跃游戏5.1.跳跃游戏26.K次取反后最大化的数组和7.加油站8.分发糖果 基础知识 什么是贪心? 贪心的本质是选择每一阶段的局部最优&#xff0c;从而达到全局最优。 贪…

面试经典 106. 从中序与后序遍历序列构造二叉树

最近小胖开始找工作了&#xff0c;又来刷苦逼的算法了 555 废话不多说&#xff0c;看这一题&#xff0c;上链接&#xff1a;https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/description/?envTypestudy-plan-v2&envIdtop-inte…

CentOS 8升级gcc版本

1、查看gcc版本 gcc -v发现gcc版本为8.x.x&#xff0c;而跑某个项目的finetune需要gcc-9&#xff0c;之前搜索过很多更新gcc版本的方式&#xff0c;例如https://blog.csdn.net/xunye_dream/article/details/108918316?spm1001.2014.3001.5506&#xff0c;但执行指令 sudo yu…

如何从 Vue 2 无痛升级到 Vue 3,一文搞定!

大家好,我是CodeQi! 一位热衷于技术分享的码仔。 随着 Vue 3 的发布,许多开发者都面临着从 Vue 2 升级到 Vue 3 的挑战。 本文将详细介绍如何从 Vue 2 无痛升级到 Vue 3,包括每个步骤的详细说明与代码示例。 让我们开始吧! 准备工作 在正式开始升级之前,请确保你已经…

纳米级材料尺寸如何测量?

在纳米显微测量领域&#xff0c;基于纳米传动与扫描技术、白光干涉与高精度3D重建技术、共聚焦测量等技术积累&#xff0c;具有自主知识产权的白光干涉仪&#xff08;Z向分辨率可高达0.1纳米&#xff09;和共聚焦显微镜&#xff0c;广泛应用于半导体、3C电子、高校科研等行业领…

VMware安装centos9详细教程(保姆级)

前言 centos9最新的centos版本&#xff0c;在近期的使用中发现它的操作界面与以往的centos7/8更加舒适&#xff0c;界面优化更加精细 项目终止日期&#xff08;EOL&#xff09; 从公告可知&#xff0c;CentOS 项目重心从 CentOS Linux 转移到了 CentOS Stream。下面是各个项…

机场公厕厕位指引屏,布线简单,安装便捷

在人潮涌动的机场&#xff0c;公厕不仅是旅客的必需设施&#xff0c;更是衡量机场服务质量的重要指标。然而&#xff0c;传统机场公厕往往存在信息不透明、清洁维护滞后、高峰期拥挤等问题&#xff0c;严重影响了旅客的使用体验。近年来&#xff0c;随着智慧机场理念的兴起&…

【方法】如何打开设置了密码的ZIP文件?

对于重要的ZIP文件&#xff0c;很多人会设置密码保护&#xff0c;那要如何打开设置了密码的ZIP文件呢&#xff1f;今天我们一起来看下&#xff0c;在记得密码和忘记密码的情况下&#xff0c;如何打开ZIP文件。 情况1&#xff1a; 如果知道ZIP文件原本设置的密码&#xff0c;我…

Excel第28享:如何新建一个Excel表格

一、背景需求 小姑电话说&#xff1a;要新建一个表格&#xff0c;并实现将几个单元格进行合并的需求。 二、解决方案 1、在电脑桌面上空白地方&#xff0c;点击鼠标右键&#xff0c;在下拉的功能框中选择“XLS工作表”或“XLSX工作表”都可以&#xff0c;如下图所示。 之后&…

用LangGraph、 Ollama,构建个人的 AI Agent

如果你还记得今年的 Google I/O大会&#xff0c;你肯定注意到了他们今年发布的 Astra&#xff0c;一个人工智能体&#xff08;AI Agent&#xff09;。事实上&#xff0c;目前最新的 GPT-4o 也是个 AI Agent。 现在各大科技公司正在投入巨额资金来创建人工智能体&#xff08;AI …

Mysql数据库两表连接进行各种操作

一&#xff0c;创建两个表emp和dept&#xff0c;并给它们插入数据 1.创建表emp create table dept (dept1 int ,dept_name varchar(11)) charsetutf8; 2.创建表dept create table emp (sid int ,name varchar(11),age int,worktime_start date,incoming int,dept2 int) cha…

数据库基础复习

数据库简介 关系型数据库&#xff1a;Mysql 、Oracle 、SqlServer.... DB2 达梦 非关系型数据库&#xff1a;Redis 、MongoDB... MySQL是一个关系型数据库管理系统&#xff0c;由瑞典MySQL AB 公司开发&#xff0c;属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管…

化妆品3D虚拟三维数字化营销展示更加生动、真实、高效!

随着人们越来越追求高速便捷的生活工作方式&#xff0c;企业在营销市场也偏国际化&#xff0c;借助VR全景制作技术&#xff0c;将企业1:1复刻到云端数字化世界&#xff0c;能带来高沉浸式的逼真、震撼效果。 通过我们独特的漫游点自然场景过渡技术&#xff0c;您将置身于一个真…

产品推荐| 立錡低耗电器件:线性稳压器、Buck 和 Boost 转换器

想让电池用得更久、利用好它的每一份电力&#xff1f;低静态电流的电源转换器是你的必然选择。立錡深谙电源管理之道&#xff0c;为你备好了低耗电的各种产品&#xff0c;其中包括低压差线性稳压器、Buck 转换器和 Boost 转换器&#xff0c;最低消耗仅有 360nA&#xff0c;是无…

猎人维修大师免狗版

技术文档摘要 标题&#xff1a; 多功能维修工具集合概述 摘要&#xff1a; 本文档提供了一组多功能维修工具的概述&#xff0c;这些工具旨在为专业技术人员提供便利&#xff0c;以执行设备维修和软件解锁等任务。文档列出了各个工具的主要功能和应用场景。 关键词&#xff1…