Repository: CodingGay/BlackObfuscator-ASPlugin Branch: main Commit: 10962b0ba3f8 Files: 46 Total size: 54.9 KB Directory structure: gitextract_pqonp2hm/ ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── README_EN.md ├── app/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── top/ │ │ └── niunaijun/ │ │ └── blackobfuscator/ │ │ └── asplugin/ │ │ └── ExampleInstrumentedTest.java │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── top/ │ │ │ └── niunaijun/ │ │ │ └── blackobfuscator/ │ │ │ └── asplugin/ │ │ │ ├── Abx.java │ │ │ └── MainActivity.java │ │ └── res/ │ │ ├── drawable/ │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── values/ │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── themes.xml │ │ └── values-night/ │ │ └── themes.xml │ └── test/ │ └── java/ │ └── top/ │ └── niunaijun/ │ └── blackobfuscator/ │ └── asplugin/ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── localRepo/ │ └── top/ │ └── niunaijun/ │ └── blackobfuscator/ │ └── plugin/ │ ├── 1.0.0/ │ │ ├── plugin-1.0.0.jar │ │ ├── plugin-1.0.0.jar.md5 │ │ ├── plugin-1.0.0.jar.sha1 │ │ ├── plugin-1.0.0.pom │ │ ├── plugin-1.0.0.pom.md5 │ │ └── plugin-1.0.0.pom.sha1 │ ├── maven-metadata.xml │ ├── maven-metadata.xml.md5 │ └── maven-metadata.xml.sha1 ├── plugin/ │ ├── .gitignore │ ├── build.gradle │ └── src/ │ └── main/ │ ├── groovy/ │ │ └── top/ │ │ └── niunaijun/ │ │ └── blackobfuscator/ │ │ ├── BlackObfuscatorExtension.groovy │ │ └── ObfPlugin.groovy │ ├── java/ │ │ └── top/ │ │ └── niunaijun/ │ │ └── blackobfuscator/ │ │ └── core/ │ │ ├── Mapping.java │ │ └── ObfDex.java │ └── resources/ │ └── META-INF/ │ └── gradle-plugins/ │ └── top.niunaijun.blackobfuscator.properties └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ # Auto detect text files and perform LF normalization * text=auto ================================================ FILE: .gitignore ================================================ # Compiled class file *.class # Log file *.log # BlueJ files *.ctxt # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.war *.nar *.ear *.zip *.tar.gz *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* app/.DS_Store .gradle/* .idea/* gradle/.DS_Store build/ ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # DEX控制流混淆插件版 · BlackObfuscator-ASPlugin **[English Version](README_EN.md)** ![](https://img.shields.io/badge/language-java-brightgreen.svg) 本项目为 [BlackObfuscator](https://github.com/CodingGay/BlackObfuscator) 的Android Studio插件版,支持打包自动化混淆。功能及介绍方面请查看 [BlackObfuscator](https://github.com/CodingGay/BlackObfuscator) 源项目 ## 注意事项 - 首要注意:[BlackObfuscator](https://github.com/CodingGay/BlackObfuscator) 内的注意事项 - 若打包报错或者无效请提供 ```./gradlew tasks --all``` 信息 ## 使用方式 ### 准备 #### Step 1. 根目录Gradle文件加入 ```gradle repositories { ... // 加入仓库 maven { url 'https://jitpack.io' } } dependencies { ... classpath "com.github.CodingGay:BlackObfuscator-ASPlugin:3.9" } ``` #### Step 2. app模块加入plugin ```gradle ... apply plugin: 'com.android.application' // 加入 apply plugin: 'top.niunaijun.blackobfuscator' ``` 或者你的是这样的 ```gradle plugins { id 'com.android.application' // 加入 id 'top.niunaijun.blackobfuscator' } ``` #### Step 3. 添加混淆配置 ```gradle android { ... defaultConfig { ... } } // 加入混淆配置 BlackObfuscator { // 是否启用 enabled true // 混淆深度 depth 2 // 需要混淆的包或者类(匹配前面一段) obfClass = ["top.niunaijun", "com.abc"] // blackClass中的包或者类不会进行混淆(匹配前面一段) blackClass = ["top.niunaijun.black"] } dependencies { ... } ``` #### Step 4. Clean一次项目,打包即可自动混淆 ### License > ``` > Copyright 2021 Milk > > Licensed under the Apache License, Version 2.0 (the "License"); > you may not use this file except in compliance with the License. > You may obtain a copy of the License at > > http://www.apache.org/licenses/LICENSE-2.0 > > Unless required by applicable law or agreed to in writing, software > distributed under the License is distributed on an "AS IS" BASIS, > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > See the License for the specific language governing permissions and > limitations under the License. > ``` ================================================ FILE: README_EN.md ================================================ # DexFile Control Flow Flattening · BlackObfuscator-ASPlugin ![](https://img.shields.io/badge/language-java-brightgreen.svg) This project is an Android Studio plugin version of [BlackObfuscator](https://github.com/CodingGay/BlackObfuscator), it supports obfuscating code automatically. More information about this project are in [BlackObfuscator](https://github.com/CodingGay/BlackObfuscator). ## Matters Need Attention - Please check the information of [BlackObfuscator](https://github.com/CodingGay/BlackObfuscator). - If you got errors in building, please provide the the ``` ./gradlew tasks --all ``` output for me. ## Usage #### Step 1. Configure your build.gradle (in top level directory) ```gradle repositories { ... maven { url 'https://jitpack.io' } } dependencies { ... classpath "com.github.CodingGay:BlackObfuscator-ASPlugin:3.9" } ``` #### Step 2. Apply the plugin in your app module ```gradle ... apply plugin: 'com.android.application' // Add apply plugin: 'top.niunaijun.blackobfuscator' ``` or you can do it like this ```gradle plugins { id 'com.android.application' // Add id 'top.niunaijun.blackobfuscator' } ``` #### Step 3. Add configuration in your build.gradle (Module: app) ```gradle android { ... defaultConfig { ... } } // Configuration BlackObfuscator { // Enabled state enabled true // Obfuscation depth depth 2 // The classes which need to be obfuscated obfClass = ["top.niunaijun", "com.abc"] // It will not obfuscate the classes that in blackClass blackClass = ["top.niunaijun.black"] } dependencies { ... } ``` #### Step 4. Clean your project, it will obfuscate code automatically while you are building project ### License > ``` > Copyright 2021 Milk > > Licensed under the Apache License, Version 2.0 (the "License"); > you may not use this file except in compliance with the License. > You may obtain a copy of the License at > > http://www.apache.org/licenses/LICENSE-2.0 > > Unless required by applicable law or agreed to in writing, software > distributed under the License is distributed on an "AS IS" BASIS, > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > See the License for the specific language governing permissions and > limitations under the License. > ``` ================================================ FILE: app/.gitignore ================================================ /build ================================================ FILE: app/build.gradle ================================================ plugins { id 'com.android.application' id 'top.niunaijun.blackobfuscator' } android { compileSdkVersion 30 buildToolsVersion "30.0.0" defaultConfig { applicationId "top.niunaijun.blackobfuscator.asplugin" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" flavorDimensions "default" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } googleplay { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } // productFlavors { // app { // applicationId "com.ghosthing.ball" // } // // cpp { // applicationId "com.ghosthing.ball" // } // } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } BlackObfuscator { enabled true obfClass = ["top.niunaijun.blackobfuscator.asplugin", "androidx.core.app"] } dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } ================================================ FILE: app/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile ================================================ FILE: app/src/androidTest/java/top/niunaijun/blackobfuscator/asplugin/ExampleInstrumentedTest.java ================================================ package top.niunaijun.blackobfuscator.asplugin; import android.content.Context; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.*; /** * Instrumented test, which will execute on an Android device. * * @see Testing documentation */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("top.niunaijun.blackobfuscator.asplugin", appContext.getPackageName()); } } ================================================ FILE: app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: app/src/main/java/top/niunaijun/blackobfuscator/asplugin/Abx.java ================================================ package top.niunaijun.blackobfuscator.asplugin; /** * Created by Milk on 2022/1/13. * * ∧_∧ * (`・ω・∥ * 丶 つ0 * しーJ * 此处无Bug */ public class Abx { public static boolean go() { return System.currentTimeMillis() > 0; } } ================================================ FILE: app/src/main/java/top/niunaijun/blackobfuscator/asplugin/MainActivity.java ================================================ package top.niunaijun.blackobfuscator.asplugin; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (System.currentTimeMillis() > 3) { Log.d("123", "onCreate: sdfasdffakea"); } else { Log.d("123", "onCreate: aax1xaaa"); } Log.d("123", "onCreate: " + Abx.go()); } } ================================================ FILE: app/src/main/res/drawable/ic_launcher_background.xml ================================================ ================================================ FILE: app/src/main/res/drawable-v24/ic_launcher_foreground.xml ================================================ ================================================ FILE: app/src/main/res/layout/activity_main.xml ================================================ ================================================ FILE: app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml ================================================ ================================================ FILE: app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml ================================================ ================================================ FILE: app/src/main/res/values/colors.xml ================================================ #FFBB86FC #FF6200EE #FF3700B3 #FF03DAC5 #FF018786 #FF000000 #FFFFFFFF ================================================ FILE: app/src/main/res/values/strings.xml ================================================ BlackObfuscator-ASPlugin ================================================ FILE: app/src/main/res/values/themes.xml ================================================ ================================================ FILE: app/src/main/res/values-night/themes.xml ================================================ ================================================ FILE: app/src/test/java/top/niunaijun/blackobfuscator/asplugin/ExampleUnitTest.java ================================================ package top.niunaijun.blackobfuscator.asplugin; import org.junit.Test; import static org.junit.Assert.*; /** * Example local unit test, which will execute on the development machine (host). * * @see Testing documentation */ public class ExampleUnitTest { @Test public void addition_isCorrect() { assertEquals(4, 2 + 2); } } ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() maven { url 'https://jitpack.io' } maven { url uri('./localRepo') } } dependencies { classpath "com.android.tools.build:gradle:4.2.0" classpath "top.niunaijun.blackobfuscator:plugin:1.0.0" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() mavenCentral() jcenter() // Warning: this repository is going to shut down soon maven { url uri('./localRepo') } maven { url 'https://jitpack.io' } } } task clean(type: Delete) { delete rootProject.buildDir } ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ #Thu Dec 16 21:12:52 CST 2021 distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME ================================================ FILE: gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app"s APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true ================================================ FILE: gradlew ================================================ #!/usr/bin/env sh ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn () { echo "$*" } die () { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Escape application args save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } APP_ARGS=$(save "$@") # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then cd "$(dirname "$0")" fi exec "$JAVACMD" "$@" ================================================ FILE: gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: local.properties ================================================ ## This file is automatically generated by Android Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file should *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. sdk.dir=/Users/milk/Library/Android/sdk ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/1.0.0/plugin-1.0.0.jar.md5 ================================================ eb035af7c6ce60caf3ab9c762a96e98d ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/1.0.0/plugin-1.0.0.jar.sha1 ================================================ eaab39a87530bce1ff233150bed9bd1c786c64d1 ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/1.0.0/plugin-1.0.0.pom ================================================ 4.0.0 top.niunaijun.blackobfuscator plugin 1.0.0 com.android.tools.build gradle 3.3.1 runtime com.android.tools.build transform-api 1.5.0 runtime commons-io commons-io 2.5 runtime com.github.CodingGay.BlackObfuscator dex-tools 2.1 runtime ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/1.0.0/plugin-1.0.0.pom.md5 ================================================ e072c183806d331aa32ac8863534a4ce ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/1.0.0/plugin-1.0.0.pom.sha1 ================================================ 76b4be6ced264f6379d490e0d7331dd732df1641 ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/maven-metadata.xml ================================================ top.niunaijun.blackobfuscator plugin 1.0.0 1.0.0 20220113045741 ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/maven-metadata.xml.md5 ================================================ a4e0ad7fcf21d4047bf1348dbbbeae58 ================================================ FILE: localRepo/top/niunaijun/blackobfuscator/plugin/maven-metadata.xml.sha1 ================================================ ef65fe9ba949d79e0d61ed67e5197027f3a5221b ================================================ FILE: plugin/.gitignore ================================================ /build ================================================ FILE: plugin/build.gradle ================================================ apply plugin: 'groovy' //apply plugin: 'maven' apply plugin: 'com.github.dcendents.android-maven' group='top.niunaijun.blackobfuscator' dependencies { implementation "com.android.tools.build:gradle:3.3.1" implementation "com.android.tools.build:transform-api:1.5.0" implementation "commons-io:commons-io:2.5" //gradle sdk implementation gradleApi() //groovy sdk implementation localGroovy() implementation "com.github.CodingGay.BlackObfuscator:dex-tools:2.2" } repositories { mavenCentral() maven { url uri('localRepo') } } group='top.niunaijun.blackobfuscator' version='1.0.0' //uploadArchives { // repositories { // mavenDeployer { // //提交到远程服务器: // // repository(url: "http://www.xxx.com/repos") { // // authentication(userName: "admin", password: "admin") // // } // //本地的Maven地址设置为E:/Maven // repository(url: uri('../localRepo')) // } // } //} ================================================ FILE: plugin/src/main/groovy/top/niunaijun/blackobfuscator/BlackObfuscatorExtension.groovy ================================================ package top.niunaijun.blackobfuscator import org.gradle.api.Project class BlackObfuscatorExtension { boolean enabled = false int depth = 1 String[] obfClass = [] String[] blackClass = [] BlackObfuscatorExtension(Project project) { } @Override public String toString() { return "BlackObfuscatorExtension{" + "enabled=" + enabled + ", depth=" + depth + ", obfClass=" + Arrays.toString(obfClass) + ", blackClass=" + Arrays.toString(blackClass) + '}'; } } ================================================ FILE: plugin/src/main/groovy/top/niunaijun/blackobfuscator/ObfPlugin.groovy ================================================ package top.niunaijun.blackobfuscator import com.android.build.gradle.AppExtension import com.android.build.gradle.api.ApplicationVariant import com.android.build.gradle.internal.api.ReadOnlyProductFlavor import com.android.build.gradle.internal.dsl.BuildType import com.android.build.gradle.internal.dsl.ProductFlavor import com.android.build.gradle.internal.tasks.DexMergingTask import org.gradle.api.* import org.gradle.api.internal.file.DefaultFilePropertyFactory import top.niunaijun.blackobfuscator.core.ObfDex public class ObfPlugin implements Plugin { private String PLUGIN_NAME = "BlackObfuscator" private Project mProject public static BlackObfuscatorExtension sObfuscatorExtension public Map mTaskMapping = new HashMap<>() void apply(Project project) { this.mProject = project def android = project.extensions.findByType(AppExtension) project.configurations.create(PLUGIN_NAME).extendsFrom(project.configurations.implementation) sObfuscatorExtension = project.extensions.create(PLUGIN_NAME, BlackObfuscatorExtension, project) mTaskMapping.clear() project.afterEvaluate { System.out.println("=====BlackObfuscator=====") System.out.println(sObfuscatorExtension.toString()) System.out.println("=========================") } project.afterEvaluate { -> if (!sObfuscatorExtension.enabled) { return } def action = new Action() { @Override void execute(Task task) { task.getOutputs().getFiles().collect().each() { element -> def file = new File(element.toString()) ObfDex.obf(file.getAbsolutePath(), sObfuscatorExtension.depth, sObfuscatorExtension.obfClass, sObfuscatorExtension.blackClass, mTaskMapping.get(task.name)) } } } List tasks = new ArrayList<>() if (android != null) { android.applicationVariants.all(new Action() { @Override void execute(ApplicationVariant applicationVariant) { File mappingFile = null if (applicationVariant.buildType.minifyEnabled) { mappingFile = applicationVariant.mappingFile } def buildType = upperCaseFirst(applicationVariant.buildType.name) boolean empty = true for (ReadOnlyProductFlavor flavor : applicationVariant.productFlavors) { def flavorName = upperCaseFirst(applicationVariant.flavorName) addOtherTask(tasks, flavorName, buildType, mappingFile) empty = false break } if (empty) { addOtherTask(tasks, "", buildType, mappingFile) } } }) } for (Task task : tasks) { task.doLast(action) } if (tasks.isEmpty()) { System.err.println("This gradle version is not applicable. Please submit issues in https://github.com/CodingGay/BlackObfuscator-ASPlugin") } } } private void addOtherTask(List tasks, String name, String buildType, File mappingFile) { addTask("mergeDex${name}${buildType}", tasks, mappingFile) addTask("mergeLibDex${name}${buildType}", tasks, mappingFile) addTask("mergeProjectDex${name}${buildType}", tasks, mappingFile) addTask("transformDexArchiveWithDexMergerFor${name}${buildType}", tasks, mappingFile) addTask("minify${name}${buildType}WithR8", tasks, mappingFile) println("$name$buildType mappingFile $mappingFile") } private String upperCaseFirst(String val) { char[] arr = val.toCharArray() arr[0] = Character.toUpperCase(arr[0]) return new String(arr) } private void addTask(String name, List tasks, File mappingFile) { try { //Protected code Task task = mProject.tasks.getByName(name) if (!tasks.contains(task)) { tasks.add(task) if (mappingFile != null) { mTaskMapping.put(task.name, mappingFile.absolutePath) } println("add Task $name") } } catch(UnknownTaskException e1) { //Catch block } } } ================================================ FILE: plugin/src/main/java/top/niunaijun/blackobfuscator/core/Mapping.java ================================================ package top.niunaijun.blackobfuscator.core; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by Milk on 2022/1/12. * * ∧_∧ * (`・ω・∥ * 丶 つ0 * しーJ * 此处无Bug */ public class Mapping { private File mFile; private final Map mapping = new HashMap<>(); public Mapping(String file) { if (file == null) return; mFile = new File(file); parser(); } private void parser() { if (mFile == null || !mFile.exists()) return; try { List strings = FileUtils.readLines(mFile, Charset.defaultCharset()); for (String string : strings) { if (string.startsWith("#") || string.startsWith(" ")) { continue; } String[] split = string.split(" -> "); if (split.length != 2) { continue; } // System.out.println("add mapping : " + string); mapping.put(split[0], split[1].substring(0, split[1].length() - 1)); } } catch (IOException ignored) { } } public String get(String origClazz) { return mapping.get(origClazz); } public Map getMapping() { return mapping; } } ================================================ FILE: plugin/src/main/java/top/niunaijun/blackobfuscator/core/ObfDex.java ================================================ package top.niunaijun.blackobfuscator.core; import com.googlecode.dex2jar.tools.Dex2jarCmd; import com.googlecode.dex2jar.tools.Jar2Dex; import org.jf.DexLib2Utils; import org.jf.util.TrieTree; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import top.niunaijun.obfuscator.ObfuscatorConfiguration; /** * Created by Milk on 2021/12/17. * * ∧_∧ * (`・ω・∥ * 丶 つ0 * しーJ * 此处无Bug */ public class ObfDex { public static void obf(String dir, int depth, String[] obfClass, String[] blackClass, String mappingFile) { File file = new File(dir); Mapping mapping = new Mapping(mappingFile); if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) return; for (File input : files) { if (input.isFile()) { handleDex(input, depth, obfClass, blackClass, mapping); } else { obf(input.getAbsolutePath(), depth, obfClass, blackClass, mappingFile); } } } else { handleDex(file, depth, obfClass, blackClass, mapping); } } private static void handleDex(File input, int depth, String[] obfClass, String[] blackClass, Mapping mapping) { if (!input.getAbsolutePath().endsWith(".dex")) return; File tempJar = null; File splitDex = null; File obfDex = null; try { tempJar = new File(input.getParent(), System.currentTimeMillis() + "obf" + input.getName() + ".jar"); splitDex = new File(input.getParent(), System.currentTimeMillis() + "split" + input.getName() + ".dex"); obfDex = new File(input.getParent(), System.currentTimeMillis() + "obf" + input.getName() + ".dex"); List obfClassList = arrayToList(obfClass); List blackClassList = arrayToList(blackClass); TrieTree whiteListTree = new TrieTree(); whiteListTree.addAll(obfClassList); for (String aClass : mapping.getMapping().keySet()) { if (whiteListTree.search(aClass)) { String orig = mapping.get(aClass); if (orig != null) { System.out.println("mapping : " + aClass + " ---> " + orig); obfClassList.add(orig); } } } TrieTree blackListTree = new TrieTree(); blackListTree.addAll(blackClassList); List tmpBlackClass = new ArrayList<>(blackClassList); for (String aClass : tmpBlackClass) { if (blackListTree.search(aClass)) { String orig = mapping.get(aClass); if (orig != null) { System.out.println("mapping : " + aClass + " ---> " + orig); blackClassList.add(orig); } } } long l = DexLib2Utils.splitDex(input, splitDex, obfClassList, blackClassList); if (l <= 0) { System.out.println("Obfuscator Class not found"); return; } new Dex2jarCmd(new ObfuscatorConfiguration() { @Override public int getObfDepth() { return depth; } @Override public boolean accept(String className, String methodName) { System.out.println("BlackObf Class: " + className + "#" + methodName); return super.accept(className, methodName); } }).doMain("-f", splitDex.getAbsolutePath(), "-o", tempJar.getAbsolutePath()); new Jar2Dex().doMain("-f", "-o", obfDex.getAbsolutePath(), tempJar.getAbsolutePath()); DexLib2Utils.mergerAndCoverDexFile(input, obfDex, input); } catch (Throwable t) { t.printStackTrace(); } finally { tempJar.delete(); splitDex.delete(); obfDex.delete(); } } private static List arrayToList(String[] array) { List list = Arrays.asList(array); return new ArrayList<>(list); } } ================================================ FILE: plugin/src/main/resources/META-INF/gradle-plugins/top.niunaijun.blackobfuscator.properties ================================================ implementation-class=top.niunaijun.blackobfuscator.ObfPlugin ================================================ FILE: settings.gradle ================================================ rootProject.name = "BlackObfuscator-ASPlugin" include ':app' include ':plugin'