├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── maven.yml ├── .gitignore ├── .idea └── copyright │ └── MIT.xml ├── .travis.yml ├── LICENSE ├── README.md ├── ShowHWID ├── META-INF │ └── MANIFEST.MF └── src │ └── HWIDGenerator.java ├── _config.yml ├── libs └── com │ └── bulenkov │ └── darcula │ ├── 1.0.0 │ ├── darcula-1.0.0.jar │ ├── darcula-1.0.0.jar.md5 │ ├── darcula-1.0.0.jar.sha1 │ ├── darcula-1.0.0.pom │ ├── darcula-1.0.0.pom.md5 │ └── darcula-1.0.0.pom.sha1 │ ├── maven-metadata.xml │ ├── maven-metadata.xml.md5 │ └── maven-metadata.xml.sha1 ├── obfuscator-annotations ├── obfuscatorannotations.iml ├── pom.xml └── src │ └── main │ └── java │ └── me │ └── superblaubeere27 │ └── annotations │ ├── ObfuscationTransformer.java │ ├── ObfuscatorRules.java │ └── Rule.java ├── obfuscator-core ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── me │ │ │ └── superblaubeere27 │ │ │ │ ├── hwid │ │ │ │ └── HWID.java │ │ │ │ └── jobf │ │ │ │ ├── IClassTransformer.java │ │ │ │ ├── IPreClassTransformer.java │ │ │ │ ├── JObf.java │ │ │ │ ├── JObfImpl.java │ │ │ │ ├── JObfSettings.java │ │ │ │ ├── ObfuscatorClassLoader.java │ │ │ │ ├── ProcessorCallback.java │ │ │ │ ├── processors │ │ │ │ ├── CrasherTransformer.java │ │ │ │ ├── HWIDProtection.java │ │ │ │ ├── HideMembers.java │ │ │ │ ├── InlineTransformer.java │ │ │ │ ├── InvokeDynamic.java │ │ │ │ ├── LineNumberRemover.java │ │ │ │ ├── NumberObfuscationTransformer.java │ │ │ │ ├── ReferenceProxy.java │ │ │ │ ├── ShuffleMembersTransformer.java │ │ │ │ ├── StaticInitializionTransformer.java │ │ │ │ ├── StringEncryptionTransformer.java │ │ │ │ ├── encryption │ │ │ │ │ └── string │ │ │ │ │ │ ├── AESEncryptionAlgorithm.java │ │ │ │ │ │ ├── BlowfishEncryptionAlgorithm.java │ │ │ │ │ │ ├── DESEncryptionAlgorithm.java │ │ │ │ │ │ ├── IStringEncryptionAlgorithm.java │ │ │ │ │ │ └── XOREncryptionAlgorithm.java │ │ │ │ ├── flowObfuscation │ │ │ │ │ ├── FloatingPointComparisionMangler.java │ │ │ │ │ ├── FlowObfuscator.java │ │ │ │ │ ├── JumpReplacer.java │ │ │ │ │ ├── LocalVariableMangler.java │ │ │ │ │ ├── ReturnMangler.java │ │ │ │ │ ├── SwitchMangler.java │ │ │ │ │ └── codegen │ │ │ │ │ │ ├── ITrashCodeGenerator.java │ │ │ │ │ │ └── TrashCodeGenerator.java │ │ │ │ ├── name │ │ │ │ │ ├── ClassWrapper.java │ │ │ │ │ ├── CommonPackageTrees.java │ │ │ │ │ ├── CustomRemapper.java │ │ │ │ │ ├── FieldWrapper.java │ │ │ │ │ ├── INameObfuscationProcessor.java │ │ │ │ │ ├── InnerClassRemover.java │ │ │ │ │ ├── MemberRemapper.java │ │ │ │ │ ├── MethodWrapper.java │ │ │ │ │ └── NameObfuscation.java │ │ │ │ ├── optimizer │ │ │ │ │ ├── ComparisionReplacer.java │ │ │ │ │ ├── InsertedMethods.java │ │ │ │ │ ├── Optimizer.java │ │ │ │ │ └── StaticStringCallOptimizer.java │ │ │ │ └── packager │ │ │ │ │ └── Packager.java │ │ │ │ ├── ui │ │ │ │ ├── Appender.java │ │ │ │ ├── GUI.form │ │ │ │ └── GUI.java │ │ │ │ └── utils │ │ │ │ ├── AnnotationUtils.java │ │ │ │ ├── ClassTree.java │ │ │ │ ├── ConsoleUtils.java │ │ │ │ ├── InliningUtils.java │ │ │ │ ├── JObfFileFilter.java │ │ │ │ ├── JarFileFilter.java │ │ │ │ ├── MissingClassException.java │ │ │ │ ├── NameUtils.java │ │ │ │ ├── NodeUtils.java │ │ │ │ ├── PrimitiveUtils.java │ │ │ │ ├── RuntimeTypeAdapterFactory.java │ │ │ │ ├── StringManipulationUtils.java │ │ │ │ ├── Template.java │ │ │ │ ├── Templates.java │ │ │ │ ├── Utils.java │ │ │ │ ├── VariableProvider.java │ │ │ │ ├── VersionComparator.java │ │ │ │ ├── VersionTokenizer.java │ │ │ │ ├── scheduler │ │ │ │ ├── ScheduledRunnable.java │ │ │ │ └── Scheduler.java │ │ │ │ ├── script │ │ │ │ ├── JObfScript.java │ │ │ │ └── JObfScriptManager.java │ │ │ │ └── values │ │ │ │ ├── BooleanValue.java │ │ │ │ ├── ConfigManager.java │ │ │ │ ├── Configuration.java │ │ │ │ ├── DeprecationLevel.java │ │ │ │ ├── EnabledValue.java │ │ │ │ ├── FilePathValue.java │ │ │ │ ├── ModeValue.java │ │ │ │ ├── NumberValue.java │ │ │ │ ├── StringValue.java │ │ │ │ ├── Value.java │ │ │ │ └── ValueManager.java │ │ └── org │ │ │ └── objectweb │ │ │ └── asm │ │ │ └── ModifiedClassWriter.java │ └── resources │ │ ├── DARCULA.LICENSE │ │ ├── logback.xml │ │ ├── strings.properties │ │ ├── templates │ │ ├── Aggressive.json │ │ └── MixIn.json │ │ └── theme.xml │ └── test │ ├── java │ ├── FormatTest.java │ └── me │ │ └── superblaubeere27 │ │ ├── CipherTest.java │ │ ├── JumpTest.java │ │ ├── NodeUtilsTest.java │ │ ├── ObfuscatorTest.java │ │ ├── Test.java │ │ └── jobf │ │ └── processors │ │ └── optimizer │ │ └── InsertedMethodsTest.java │ └── resources │ └── config.jocfg ├── pom.xml ├── script.js ├── version └── watermark ├── pom.xml └── src └── main └── java └── me └── superblaubeere27 └── obfuscator └── watermark ├── Config.java ├── Encryption.java └── Main.java /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: 'Create a bug report' 4 | 5 | --- 6 | 7 | # Bug Report 8 | ### Expected Behaviour 9 | Tell us what you wanted to do. If you think that everyone knows, what you expected (for example, if the program just crashed), you can skip this section 10 | ### Actual Behaviour 11 | Tell us what happened. If there is an Exception please attach it. 12 | ### How to reproduce the behaviour 13 | Tell us how to reproduce the wrong behaviour of the program. If it's an error which has to do this the obfuscation please **always** attach the configuration. 14 | (To get the config open the obfuscator in GUI-Mode, goto `Config`, enable `PrettyPrint` and press `Build`) 15 | ### Possible fix 16 | If you have no idea then you can just skip this section ^^ 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: 'You want me/us to add a new feature' 4 | 5 | --- 6 | 7 | # Feature Request 8 | - Describe the feature 9 | - Tell us why should add this feature 10 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Set up JDK 1.8 11 | uses: actions/setup-java@v1 12 | with: 13 | java-version: 1.8 14 | - name: Build with Maven 15 | run: mvn -B package --file pom.xml 16 | - name: Upload artifact 17 | uses: actions/upload-artifact@v1.0.0 18 | with: 19 | # Artifact name 20 | name: obfuscator.jar 21 | # Directory containing files to upload 22 | path: obfuscator-core/target/obfuscator-core-1.9.3-SNAPSHOT.jar 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,maven,eclipse,jetbrains+all 3 | # Edit at https://www.gitignore.io/?templates=java,maven,eclipse,jetbrains+all 4 | 5 | ### Eclipse ### 6 | .metadata 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | .recommenders 17 | 18 | # External tool builders 19 | .externalToolBuilders/ 20 | 21 | # Locally stored "Eclipse launch configurations" 22 | *.launch 23 | 24 | # PyDev specific (Python IDE for Eclipse) 25 | *.pydevproject 26 | 27 | # CDT-specific (C/C++ Development Tooling) 28 | .cproject 29 | 30 | # CDT- autotools 31 | .autotools 32 | 33 | # Java annotation processor (APT) 34 | .factorypath 35 | 36 | # PDT-specific (PHP Development Tools) 37 | .buildpath 38 | 39 | # sbteclipse plugin 40 | .target 41 | 42 | # Tern plugin 43 | .tern-project 44 | 45 | # TeXlipse plugin 46 | .texlipse 47 | 48 | # STS (Spring Tool Suite) 49 | .springBeans 50 | 51 | # Code Recommenders 52 | .recommenders/ 53 | 54 | # Annotation Processing 55 | .apt_generated/ 56 | 57 | # Scala IDE specific (Scala & Java development for Eclipse) 58 | .cache-main 59 | .scala_dependencies 60 | .worksheet 61 | 62 | ### Eclipse Patch ### 63 | # Eclipse Core 64 | .project 65 | 66 | # JDT-specific (Eclipse Java Development Tools) 67 | .classpath 68 | 69 | # Annotation Processing 70 | .apt_generated 71 | 72 | .sts4-cache/ 73 | 74 | ### Java ### 75 | # Compiled class file 76 | *.class 77 | 78 | # Log file 79 | *.log 80 | 81 | # BlueJ files 82 | *.ctxt 83 | 84 | # Mobile Tools for Java (J2ME) 85 | .mtj.tmp/ 86 | 87 | # Package Files # 88 | *.jar 89 | *.war 90 | *.nar 91 | *.ear 92 | *.zip 93 | *.tar.gz 94 | *.rar 95 | 96 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 97 | hs_err_pid* 98 | 99 | ### JetBrains+all ### 100 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 101 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 102 | 103 | # User-specific stuff 104 | .idea/**/workspace.xml 105 | .idea/**/tasks.xml 106 | .idea/**/usage.statistics.xml 107 | .idea/**/dictionaries 108 | .idea/**/shelf 109 | 110 | # Generated files 111 | .idea/**/contentModel.xml 112 | 113 | # Sensitive or high-churn files 114 | .idea/**/dataSources/ 115 | .idea/**/dataSources.ids 116 | .idea/**/dataSources.local.xml 117 | .idea/**/sqlDataSources.xml 118 | .idea/**/dynamic.xml 119 | .idea/**/uiDesigner.xml 120 | .idea/**/dbnavigator.xml 121 | 122 | # Gradle 123 | .idea/**/gradle.xml 124 | .idea/**/libraries 125 | 126 | # Gradle and Maven with auto-import 127 | # When using Gradle or Maven with auto-import, you should exclude module files, 128 | # since they will be recreated, and may cause churn. Uncomment if using 129 | # auto-import. 130 | # .idea/modules.xml 131 | # .idea/*.iml 132 | # .idea/modules 133 | # *.iml 134 | # *.ipr 135 | 136 | # CMake 137 | cmake-build-*/ 138 | 139 | # Mongo Explorer plugin 140 | .idea/**/mongoSettings.xml 141 | 142 | # File-based project format 143 | *.iws 144 | 145 | # IntelliJ 146 | out/ 147 | 148 | # mpeltonen/sbt-idea plugin 149 | .idea_modules/ 150 | 151 | # JIRA plugin 152 | atlassian-ide-plugin.xml 153 | 154 | # Cursive Clojure plugin 155 | .idea/replstate.xml 156 | 157 | # Crashlytics plugin (for Android Studio and IntelliJ) 158 | com_crashlytics_export_strings.xml 159 | crashlytics.properties 160 | crashlytics-build.properties 161 | fabric.properties 162 | 163 | # Editor-based Rest Client 164 | .idea/httpRequests 165 | 166 | # Android studio 3.1+ serialized cache file 167 | .idea/caches/build_file_checksums.ser 168 | 169 | ### JetBrains+all Patch ### 170 | # Ignores the whole .idea folder and all .iml files 171 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 172 | 173 | .idea/ 174 | 175 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 176 | 177 | *.iml 178 | modules.xml 179 | .idea/misc.xml 180 | *.ipr 181 | 182 | # Sonarlint plugin 183 | .idea/sonarlint 184 | 185 | ### Maven ### 186 | target/ 187 | pom.xml.tag 188 | pom.xml.releaseBackup 189 | pom.xml.versionsBackup 190 | pom.xml.next 191 | release.properties 192 | dependency-reduced-pom.xml 193 | buildNumber.properties 194 | .mvn/timing.properties 195 | .mvn/wrapper/maven-wrapper.jar 196 | .flattened-pom.xml 197 | 198 | # End of https://www.gitignore.io/api/java,maven,eclipse,jetbrains+all -------------------------------------------------------------------------------- /.idea/copyright/MIT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | script: mvn clean package -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 superblaubeere27 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ShowHWID/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: HWIDGenerator 3 | 4 | -------------------------------------------------------------------------------- /ShowHWID/src/HWIDGenerator.java: -------------------------------------------------------------------------------- 1 | import me.superblaubeere27.hwid.HWID; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.datatransfer.StringSelection; 6 | import java.util.Arrays; 7 | 8 | public class HWIDGenerator { 9 | 10 | public static void main(String args[]) { 11 | try { 12 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 13 | } catch (Exception e) { 14 | e.printStackTrace(); 15 | } 16 | 17 | JPanel jp = new JPanel(); 18 | jp.setLayout(new GridLayout(1, 2)); 19 | 20 | JTextField hwidfield; 21 | 22 | jp.add(hwidfield = new JTextField(HWID.bytesToHex(HWID.generateHWID()))); 23 | System.out.println(Arrays.toString(HWID.generateHWID())); 24 | hwidfield.setEditable(false); 25 | JButton button; 26 | jp.add(button = new JButton("Copy")); 27 | button.addActionListener(e -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(hwidfield.getText()), null)); 28 | 29 | JOptionPane.showMessageDialog(null, jp); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/githubXiaowangzi/obfuscator/fa83ef4149927998fb5b6ef24fe3e11f6db79776/libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.jar -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.jar.md5: -------------------------------------------------------------------------------- 1 | 5afdcd4e299f71fb9dfd1740937bfbea -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.jar.sha1: -------------------------------------------------------------------------------- 1 | d50f0b2f7cd4baae8f24bc31866f8409bc00aa3e -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.pom: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 4.0.0 16 | com.bulenkov 17 | darcula 18 | 1.0.0 19 | 20 | -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.pom.md5: -------------------------------------------------------------------------------- 1 | 697aac46bfa6e26ed3e3d74c3de449b2 -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/1.0.0/darcula-1.0.0.pom.sha1: -------------------------------------------------------------------------------- 1 | 4b3fe11e37571b6c8a51c4f4969e01f2dbfcee6f -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/maven-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | com.bulenkov 14 | darcula 15 | 16 | 1.0.0 17 | 18 | 1.0.0 19 | 20 | 20190207140545 21 | 22 | 23 | -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/maven-metadata.xml.md5: -------------------------------------------------------------------------------- 1 | 921046267861d063e7cf6da78cb81bba -------------------------------------------------------------------------------- /libs/com/bulenkov/darcula/maven-metadata.xml.sha1: -------------------------------------------------------------------------------- 1 | f9671e74971e73982b39f9d676ff94be745eed6a -------------------------------------------------------------------------------- /obfuscator-annotations/obfuscatorannotations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 37 | -------------------------------------------------------------------------------- /obfuscator-annotations/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 4.0.0 16 | 17 | me.superblaubeere27 18 | obfuscator 19 | 1.9.3-SNAPSHOT 20 | 21 | 22 | obfuscator-annotations 23 | 24 | 25 | 3.2.0 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-jar-plugin 33 | ${maven-jar-plugin.version} 34 | 35 | 36 | 37 | true 38 | true 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /obfuscator-annotations/src/main/java/me/superblaubeere27/annotations/ObfuscationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.annotations; 12 | 13 | public enum ObfuscationTransformer { 14 | FLOW_OBFUSCATION, 15 | LINE_NUMBER_REMOVER, 16 | NUMBER_OBFUSCATION, 17 | STRING_ENCRYPTION, 18 | HWID_PROTECTION, 19 | PEEPHOLE_OPTIMIZER, 20 | CRASHER, 21 | INVOKE_DYNAMIC, 22 | REFERENCE_PROXY, 23 | SHUFFLE_MEMBERS, 24 | INNER_CLASS_REMOVER, 25 | NAME_OBFUSCATION, 26 | HIDE_MEMBERS, 27 | INLINING 28 | } 29 | -------------------------------------------------------------------------------- /obfuscator-annotations/src/main/java/me/superblaubeere27/annotations/ObfuscatorRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.annotations; 12 | 13 | public @interface ObfuscatorRules { 14 | Rule[] value(); 15 | } 16 | -------------------------------------------------------------------------------- /obfuscator-annotations/src/main/java/me/superblaubeere27/annotations/Rule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.annotations; 12 | 13 | import static me.superblaubeere27.annotations.ObfuscationTransformer.*; 14 | 15 | public @interface Rule { 16 | Action value(); 17 | 18 | ObfuscationTransformer[] processors() default {FLOW_OBFUSCATION, 19 | LINE_NUMBER_REMOVER, 20 | NUMBER_OBFUSCATION, 21 | STRING_ENCRYPTION, 22 | HWID_PROTECTION, 23 | PEEPHOLE_OPTIMIZER, 24 | CRASHER, 25 | INVOKE_DYNAMIC, 26 | REFERENCE_PROXY, 27 | SHUFFLE_MEMBERS, 28 | INNER_CLASS_REMOVER, 29 | NAME_OBFUSCATION, 30 | HIDE_MEMBERS, 31 | INLINING}; 32 | 33 | enum Action { 34 | ALLOW, DISALLOW 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/hwid/HWID.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.hwid; 12 | 13 | import java.security.MessageDigest; 14 | import java.security.NoSuchAlgorithmException; 15 | 16 | public class HWID { 17 | private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); 18 | 19 | public static byte[] generateHWID() { 20 | try { 21 | MessageDigest hash = MessageDigest.getInstance("MD5"); 22 | 23 | String s = System.getProperty("os.name") + 24 | System.getProperty("os.arch") + 25 | System.getProperty("os.version") + 26 | Runtime.getRuntime().availableProcessors() + 27 | System.getenv("PROCESSOR_IDENTIFIER") + 28 | System.getenv("PROCESSOR_ARCHITECTURE") + 29 | System.getenv("PROCESSOR_ARCHITEW6432") + 30 | System.getenv("NUMBER_OF_PROCESSORS"); 31 | return hash.digest(s.getBytes()); 32 | } catch (NoSuchAlgorithmException e) { 33 | throw new Error("Algorithm wasn't found.", e); 34 | } 35 | 36 | } 37 | 38 | public static byte[] hexStringToByteArray(String s) { 39 | int len = s.length(); 40 | byte[] data = new byte[len / 2]; 41 | for (int i = 0; i < len; i += 2) { 42 | data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) 43 | + Character.digit(s.charAt(i + 1), 16)); 44 | } 45 | return data; 46 | } 47 | 48 | public static String bytesToHex(byte[] bytes) { 49 | char[] hexChars = new char[bytes.length * 2]; 50 | for (int j = 0; j < bytes.length; j++) { 51 | int v = bytes[j] & 0xFF; 52 | hexChars[j * 2] = hexArray[v >>> 4]; 53 | hexChars[j * 2 + 1] = hexArray[v & 0x0F]; 54 | } 55 | return new String(hexChars); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/IClassTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import org.objectweb.asm.tree.ClassNode; 15 | 16 | public interface IClassTransformer { 17 | void process(ProcessorCallback callback, ClassNode node); 18 | 19 | ObfuscationTransformer getType(); 20 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/IPreClassTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf; 12 | 13 | import org.objectweb.asm.tree.ClassNode; 14 | 15 | import java.util.Collection; 16 | 17 | public interface IPreClassTransformer { 18 | void process(Collection node); 19 | } 20 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/JObfSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf; 12 | 13 | import me.superblaubeere27.jobf.utils.values.BooleanValue; 14 | import me.superblaubeere27.jobf.utils.values.DeprecationLevel; 15 | import me.superblaubeere27.jobf.utils.values.FilePathValue; 16 | import me.superblaubeere27.jobf.utils.values.StringValue; 17 | 18 | public class JObfSettings { 19 | private static final String PROCESSOR_NAME = "General Settings"; 20 | 21 | private StringValue generatorChars = new StringValue(PROCESSOR_NAME, "Generator characters", DeprecationLevel.GOOD, "Il"); 22 | private BooleanValue useCustomDictionary = new BooleanValue(PROCESSOR_NAME, "Custom dictionary", DeprecationLevel.GOOD, false); 23 | private FilePathValue classNameDictionary = new FilePathValue(PROCESSOR_NAME, "Class Name dictionary", DeprecationLevel.GOOD, ""); 24 | private FilePathValue nameDictionary = new FilePathValue(PROCESSOR_NAME, "Name dictionary", DeprecationLevel.GOOD, ""); 25 | private BooleanValue useStore = new BooleanValue(PROCESSOR_NAME, "Use STORE instead of DEFLATE (For e.g. SpringBoot)", DeprecationLevel.GOOD, false); 26 | 27 | public BooleanValue getUseCustomDictionary() { 28 | return useCustomDictionary; 29 | } 30 | 31 | public FilePathValue getClassNameDictionary() { 32 | return classNameDictionary; 33 | } 34 | 35 | public FilePathValue getNameDictionary() { 36 | return nameDictionary; 37 | } 38 | 39 | public StringValue getGeneratorChars() { 40 | return generatorChars; 41 | } 42 | 43 | public BooleanValue getUseStore() { 44 | return useStore; 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/ObfuscatorClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf; 12 | 13 | import me.superblaubeere27.jobf.processors.name.ClassWrapper; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.nio.file.Files; 18 | 19 | public class ObfuscatorClassLoader extends ClassLoader { 20 | public static ObfuscatorClassLoader INSTANCE = new ObfuscatorClassLoader(); 21 | 22 | @Override 23 | protected Class findClass(String name) throws ClassNotFoundException { 24 | String internalName = name.replace('.', '/'); 25 | 26 | if (JObfImpl.INSTANCE.getClassPath().containsKey(internalName)) { 27 | ClassWrapper classWrapper = JObfImpl.INSTANCE.getClassPath().get(internalName); 28 | 29 | if (classWrapper == null || classWrapper.originalClass == null) 30 | throw new ClassNotFoundException(name); 31 | 32 | try { 33 | return defineClass(name, classWrapper.originalClass, 0, classWrapper.originalClass.length); 34 | } catch (ClassFormatError classFormatError) { 35 | classFormatError.printStackTrace(); 36 | try { 37 | Files.write(new File("A:/invalid.class").toPath(), classWrapper.originalClass); 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | } 43 | 44 | return super.findClass(name); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/ProcessorCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf; 12 | 13 | public class ProcessorCallback { 14 | private boolean forceComputeFrames = false; 15 | 16 | public boolean isForceComputeFrames() { 17 | return forceComputeFrames; 18 | } 19 | 20 | public void setForceComputeFrames() { 21 | this.forceComputeFrames = true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/CrasherTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import me.superblaubeere27.jobf.IClassTransformer; 15 | import me.superblaubeere27.jobf.JObfImpl; 16 | import me.superblaubeere27.jobf.ProcessorCallback; 17 | import me.superblaubeere27.jobf.utils.NameUtils; 18 | import me.superblaubeere27.jobf.utils.values.BooleanValue; 19 | import me.superblaubeere27.jobf.utils.values.DeprecationLevel; 20 | import me.superblaubeere27.jobf.utils.values.EnabledValue; 21 | import org.objectweb.asm.tree.AnnotationNode; 22 | import org.objectweb.asm.tree.ClassNode; 23 | 24 | import java.lang.reflect.Modifier; 25 | import java.util.ArrayList; 26 | 27 | public class CrasherTransformer implements IClassTransformer { 28 | private static final String EMPTY_STRINGS; 29 | 30 | static { 31 | StringBuilder stringBuilder = new StringBuilder(); 32 | 33 | for (int j = 0; j < 50000; j++) { 34 | stringBuilder.append("\n"); 35 | } 36 | 37 | EMPTY_STRINGS = stringBuilder.toString(); 38 | } 39 | 40 | private EnabledValue enabled = new EnabledValue("Crasher", DeprecationLevel.GOOD, false); 41 | private BooleanValue invalidSignatures = new BooleanValue("Crasher", "Invalid Signatures", "Adds invalid signatures", DeprecationLevel.GOOD, true); 42 | private BooleanValue emptyAnnotation = new BooleanValue("Crasher", "Empty annotation spam", "Adds annotations which are repeated newline", DeprecationLevel.GOOD, true); 43 | private JObfImpl inst; 44 | 45 | public CrasherTransformer(JObfImpl inst) { 46 | this.inst = inst; 47 | } 48 | 49 | @Override 50 | public void process(ProcessorCallback callback, ClassNode node) { 51 | if (Modifier.isInterface(node.access)) return; 52 | if (!enabled.getObject()) return; 53 | 54 | if (invalidSignatures.getObject()) { 55 | /* 56 | * By ItzSomebody 57 | */ 58 | if (node.signature == null) { 59 | node.signature = NameUtils.crazyString(10); 60 | } 61 | } 62 | 63 | if (emptyAnnotation.getObject()) { 64 | node.methods.forEach(method -> { 65 | 66 | if (method.invisibleAnnotations == null) 67 | method.invisibleAnnotations = new ArrayList<>(); 68 | 69 | for (int i = 0; i < 50; i++) { 70 | method.invisibleAnnotations.add(new AnnotationNode(EMPTY_STRINGS)); 71 | } 72 | }); 73 | } 74 | 75 | inst.setWorkDone(); 76 | } 77 | 78 | @Override 79 | public ObfuscationTransformer getType() { 80 | return ObfuscationTransformer.CRASHER; 81 | } 82 | 83 | 84 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/HideMembers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import me.superblaubeere27.jobf.IClassTransformer; 15 | import me.superblaubeere27.jobf.JObfImpl; 16 | import me.superblaubeere27.jobf.ProcessorCallback; 17 | import me.superblaubeere27.jobf.utils.values.DeprecationLevel; 18 | import me.superblaubeere27.jobf.utils.values.EnabledValue; 19 | import org.objectweb.asm.Opcodes; 20 | import org.objectweb.asm.tree.ClassNode; 21 | import org.objectweb.asm.tree.FieldNode; 22 | import org.objectweb.asm.tree.MethodNode; 23 | 24 | import java.util.Random; 25 | 26 | public class HideMembers implements IClassTransformer { 27 | private static final String PROCESSOR_NAME = "HideMembers"; 28 | private static Random random = new Random(); 29 | private JObfImpl inst; 30 | private EnabledValue enabled = new EnabledValue(PROCESSOR_NAME, DeprecationLevel.GOOD, true); 31 | 32 | public HideMembers(JObfImpl inst) { 33 | this.inst = inst; 34 | } 35 | 36 | @Override 37 | public void process(ProcessorCallback callback, ClassNode node) { 38 | if (!enabled.getObject()) return; 39 | 40 | if ((node.access & Opcodes.ACC_INTERFACE) == 0) { 41 | for (MethodNode method : node.methods) { 42 | // if ((method.access & Opcodes.ACC_BRIDGE) == 0 && (method.access & Opcodes.ACC_STATIC) == 0 && !method.name.startsWith("<")) { 43 | // method.access |= Opcodes.ACC_BRIDGE; 44 | // } 45 | // if ((method.access & Opcodes.ACC_SYNTHETIC) == 0) { 46 | if (method.name.startsWith("<")) 47 | continue; 48 | if ((method.access & Opcodes.ACC_NATIVE) == 0) { 49 | continue; 50 | } 51 | method.access = method.access | Opcodes.ACC_BRIDGE; 52 | method.access = method.access | Opcodes.ACC_SYNTHETIC; 53 | // } 54 | } 55 | } 56 | for (FieldNode field : node.fields) { 57 | // if ((field.access & Opcodes.ACC_FINAL) == 0) 58 | field.access = field.access | Opcodes.ACC_SYNTHETIC; 59 | } 60 | // if ((node.access & Opcodes.ACC_FINAL) == 0) { 61 | // node.access = node.access | Opcodes.ACC_SYNTHETIC; 62 | // } 63 | inst.setWorkDone(); 64 | } 65 | 66 | @Override 67 | public ObfuscationTransformer getType() { 68 | return ObfuscationTransformer.HIDE_MEMBERS; 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/ShuffleMembersTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import me.superblaubeere27.jobf.IClassTransformer; 15 | import me.superblaubeere27.jobf.JObfImpl; 16 | import me.superblaubeere27.jobf.ProcessorCallback; 17 | import me.superblaubeere27.jobf.utils.values.DeprecationLevel; 18 | import me.superblaubeere27.jobf.utils.values.EnabledValue; 19 | import org.objectweb.asm.Opcodes; 20 | import org.objectweb.asm.tree.ClassNode; 21 | import org.objectweb.asm.tree.FieldNode; 22 | import org.objectweb.asm.tree.MethodNode; 23 | 24 | import java.util.Collections; 25 | import java.util.Random; 26 | 27 | public class ShuffleMembersTransformer implements IClassTransformer { 28 | private static final String PROCESSOR_NAME = "ShuffleMembers"; 29 | private static Random random = new Random(); 30 | private JObfImpl inst; 31 | private EnabledValue enabled = new EnabledValue(PROCESSOR_NAME, DeprecationLevel.GOOD, true); 32 | 33 | public ShuffleMembersTransformer(JObfImpl inst) { 34 | this.inst = inst; 35 | } 36 | 37 | @Override 38 | public void process(ProcessorCallback callback, ClassNode node) { 39 | if (!enabled.getObject()) return; 40 | 41 | if ((node.access & Opcodes.ACC_ENUM) != 0) { 42 | return; 43 | } 44 | 45 | Collections.shuffle(node.methods, random); 46 | Collections.shuffle(node.fields, random); 47 | Collections.shuffle(node.innerClasses, random); 48 | Collections.shuffle(node.interfaces, random); 49 | 50 | if (node.invisibleAnnotations != null) Collections.shuffle(node.invisibleAnnotations, random); 51 | if (node.visibleAnnotations != null) Collections.shuffle(node.visibleAnnotations, random); 52 | if (node.invisibleTypeAnnotations != null) Collections.shuffle(node.invisibleTypeAnnotations, random); 53 | 54 | for (Object o : node.methods.toArray()) { 55 | if (o instanceof MethodNode) { 56 | MethodNode method = (MethodNode) o; 57 | if (method.invisibleAnnotations != null) Collections.shuffle(method.invisibleAnnotations, random); 58 | if (method.invisibleLocalVariableAnnotations != null) 59 | Collections.shuffle(method.invisibleLocalVariableAnnotations, random); 60 | if (method.invisibleTypeAnnotations != null) 61 | Collections.shuffle(method.invisibleTypeAnnotations, random); 62 | if (method.visibleAnnotations != null) Collections.shuffle(method.visibleAnnotations, random); 63 | if (method.visibleLocalVariableAnnotations != null) 64 | Collections.shuffle(method.visibleLocalVariableAnnotations, random); 65 | if (method.visibleTypeAnnotations != null) Collections.shuffle(method.visibleTypeAnnotations, random); 66 | 67 | Collections.shuffle(method.exceptions, random); 68 | if (method.localVariables != null) { 69 | Collections.shuffle(method.localVariables, random); 70 | } 71 | if (method.parameters != null) Collections.shuffle(method.parameters, random); 72 | } 73 | } 74 | for (Object o : node.methods.toArray()) { 75 | if (o instanceof FieldNode) { 76 | FieldNode method = (FieldNode) o; 77 | if (method.invisibleAnnotations != null) Collections.shuffle(method.invisibleAnnotations, random); 78 | if (method.invisibleTypeAnnotations != null) 79 | Collections.shuffle(method.invisibleTypeAnnotations, random); 80 | if (method.visibleAnnotations != null) Collections.shuffle(method.visibleAnnotations, random); 81 | if (method.visibleTypeAnnotations != null) Collections.shuffle(method.visibleTypeAnnotations, random); 82 | } 83 | } 84 | inst.setWorkDone(); 85 | } 86 | 87 | @Override 88 | public ObfuscationTransformer getType() { 89 | return ObfuscationTransformer.SHUFFLE_MEMBERS; 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/StaticInitializionTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import me.superblaubeere27.jobf.IClassTransformer; 15 | import me.superblaubeere27.jobf.JObfImpl; 16 | import me.superblaubeere27.jobf.ProcessorCallback; 17 | import me.superblaubeere27.jobf.utils.NodeUtils; 18 | import org.objectweb.asm.Opcodes; 19 | import org.objectweb.asm.tree.*; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import java.util.Random; 24 | 25 | public class StaticInitializionTransformer implements IClassTransformer { 26 | private static Random random = new Random(); 27 | private JObfImpl inst; 28 | 29 | public StaticInitializionTransformer(JObfImpl inst) { 30 | this.inst = inst; 31 | } 32 | 33 | @Override 34 | public void process(ProcessorCallback callback, ClassNode node) { 35 | HashMap objs = new HashMap<>(); 36 | for (FieldNode field : node.fields) { 37 | if (field.value != null) { 38 | if ((field.access & Opcodes.ACC_STATIC) != 0 && (field.value instanceof String || field.value instanceof Integer)) { 39 | objs.put(field, field.value); 40 | field.value = null; 41 | } 42 | } 43 | } 44 | InsnList toAdd = new InsnList(); 45 | for (Map.Entry fieldNodeObjectEntry : objs.entrySet()) { 46 | if (fieldNodeObjectEntry.getValue() instanceof String) { 47 | toAdd.add(new LdcInsnNode(fieldNodeObjectEntry.getValue())); 48 | } 49 | if (fieldNodeObjectEntry.getValue() instanceof Integer) { 50 | toAdd.add(NodeUtils.generateIntPush((Integer) fieldNodeObjectEntry.getValue())); 51 | } 52 | toAdd.add(new FieldInsnNode(Opcodes.PUTSTATIC, node.name, fieldNodeObjectEntry.getKey().name, fieldNodeObjectEntry.getKey().desc)); 53 | } 54 | MethodNode clInit = NodeUtils.getMethod(node, ""); 55 | if (clInit == null) { 56 | clInit = new MethodNode(Opcodes.ACC_STATIC, "", "()V", null, new String[0]); 57 | node.methods.add(clInit); 58 | } 59 | 60 | if (clInit.instructions == null || clInit.instructions.getFirst() == null) { 61 | clInit.instructions = toAdd; 62 | clInit.instructions.add(new InsnNode(Opcodes.RETURN)); 63 | } else { 64 | clInit.instructions.insertBefore(clInit.instructions.getFirst(), toAdd); 65 | } 66 | inst.setWorkDone(); 67 | } 68 | 69 | @Override 70 | public ObfuscationTransformer getType() { 71 | return null; 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/encryption/string/AESEncryptionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.encryption.string; 12 | 13 | import javax.crypto.Cipher; 14 | import javax.crypto.spec.SecretKeySpec; 15 | import java.nio.charset.StandardCharsets; 16 | import java.security.MessageDigest; 17 | import java.util.Base64; 18 | 19 | @Deprecated 20 | public class AESEncryptionAlgorithm implements IStringEncryptionAlgorithm { 21 | 22 | public static String decrypt(String obj, String key) { 23 | try { 24 | SecretKeySpec keySpec = new SecretKeySpec(MessageDigest.getInstance("SHA-256").digest(key.getBytes(StandardCharsets.UTF_8)), "AES"); 25 | 26 | Cipher des = Cipher.getInstance("AES"); 27 | des.init(Cipher.DECRYPT_MODE, keySpec); 28 | 29 | return new String(des.doFinal(Base64.getDecoder().decode(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); 30 | 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | return null; 35 | } 36 | 37 | @Override 38 | public String encrypt(String obj, String key) { 39 | try { 40 | SecretKeySpec keySpec = new SecretKeySpec(MessageDigest.getInstance("SHA-256").digest(key.getBytes(StandardCharsets.UTF_8)), "AES"); 41 | 42 | Cipher des = Cipher.getInstance("AES"); 43 | des.init(Cipher.ENCRYPT_MODE, keySpec); 44 | 45 | return new String(Base64.getEncoder().encode(des.doFinal(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); 46 | 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | return null; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/encryption/string/BlowfishEncryptionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.encryption.string; 12 | 13 | import javax.crypto.Cipher; 14 | import javax.crypto.spec.SecretKeySpec; 15 | import java.nio.charset.StandardCharsets; 16 | import java.security.MessageDigest; 17 | import java.util.Base64; 18 | 19 | public class BlowfishEncryptionAlgorithm implements IStringEncryptionAlgorithm { 20 | public static String decrypt(String obj, String key) { 21 | try { 22 | SecretKeySpec keySpec = new SecretKeySpec(MessageDigest.getInstance("MD5").digest(key.getBytes(StandardCharsets.UTF_8)), "Blowfish"); 23 | 24 | Cipher des = Cipher.getInstance("Blowfish"); 25 | des.init(Cipher.DECRYPT_MODE, keySpec); 26 | 27 | return new String(des.doFinal(Base64.getDecoder().decode(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); 28 | 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | return null; 33 | } 34 | 35 | @Override 36 | public String encrypt(String obj, String key) { 37 | try { 38 | SecretKeySpec keySpec = new SecretKeySpec(MessageDigest.getInstance("MD5").digest(key.getBytes(StandardCharsets.UTF_8)), "Blowfish"); 39 | 40 | Cipher des = Cipher.getInstance("Blowfish"); 41 | des.init(Cipher.ENCRYPT_MODE, keySpec); 42 | 43 | return new String(Base64.getEncoder().encode(des.doFinal(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); 44 | 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/encryption/string/DESEncryptionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.encryption.string; 12 | 13 | import javax.crypto.Cipher; 14 | import javax.crypto.spec.SecretKeySpec; 15 | import java.nio.charset.StandardCharsets; 16 | import java.security.MessageDigest; 17 | import java.util.Arrays; 18 | import java.util.Base64; 19 | 20 | public class DESEncryptionAlgorithm implements IStringEncryptionAlgorithm { 21 | public static String decrypt(String obj, String key) { 22 | try { 23 | SecretKeySpec keySpec = new SecretKeySpec(Arrays.copyOf(MessageDigest.getInstance("MD5").digest(key.getBytes(StandardCharsets.UTF_8)), 8), "DES"); 24 | 25 | Cipher des = Cipher.getInstance("DES"); 26 | des.init(Cipher.DECRYPT_MODE, keySpec); 27 | 28 | return new String(des.doFinal(Base64.getDecoder().decode(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); 29 | 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | return null; 34 | } 35 | 36 | @Override 37 | public String encrypt(String obj, String key) { 38 | try { 39 | SecretKeySpec keySpec = new SecretKeySpec(Arrays.copyOf(MessageDigest.getInstance("MD5").digest(key.getBytes(StandardCharsets.UTF_8)), 8), "DES"); 40 | 41 | Cipher des = Cipher.getInstance("DES"); 42 | des.init(Cipher.ENCRYPT_MODE, keySpec); 43 | 44 | return new String(Base64.getEncoder().encode(des.doFinal(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); 45 | 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/encryption/string/IStringEncryptionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.encryption.string; 12 | 13 | public interface IStringEncryptionAlgorithm { 14 | 15 | String encrypt(String obj, String key); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/encryption/string/XOREncryptionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.encryption.string; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.Base64; 15 | 16 | public class XOREncryptionAlgorithm implements IStringEncryptionAlgorithm { 17 | 18 | public static String decrypt(String obj, String key) { 19 | obj = new String(Base64.getDecoder().decode(obj.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); 20 | StringBuilder sb = new StringBuilder(); 21 | char[] keyChars = key.toCharArray(); 22 | int i = 0; 23 | for (char c : obj.toCharArray()) { 24 | sb.append((char) (c ^ keyChars[i % keyChars.length])); 25 | i++; 26 | } 27 | return sb.toString(); 28 | } 29 | 30 | @Override 31 | public String encrypt(String obj, String key) { 32 | StringBuilder sb = new StringBuilder(); 33 | char[] keyChars = key.toCharArray(); 34 | int i = 0; 35 | for (char c : obj.toCharArray()) { 36 | sb.append((char) (c ^ keyChars[i % keyChars.length])); 37 | i++; 38 | } 39 | return new String(Base64.getEncoder().encode(sb.toString().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/flowObfuscation/FloatingPointComparisionMangler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.flowObfuscation; 12 | 13 | import me.superblaubeere27.jobf.utils.NameUtils; 14 | import org.objectweb.asm.Opcodes; 15 | import org.objectweb.asm.Type; 16 | import org.objectweb.asm.tree.*; 17 | 18 | import java.util.Collection; 19 | import java.util.HashMap; 20 | 21 | class FloatingPointComparisionMangler { 22 | 23 | static Collection mangleComparisions(ClassNode cn, MethodNode node) { 24 | HashMap comparisionMethodMap = new HashMap<>(); 25 | 26 | for (AbstractInsnNode insnNode : node.instructions.toArray()) { 27 | if (insnNode.getOpcode() >= Opcodes.LCMP && insnNode.getOpcode() <= Opcodes.DCMPG) { 28 | if (!comparisionMethodMap.containsKey(insnNode.getOpcode())) { 29 | comparisionMethodMap.put(insnNode.getOpcode(), generateComparisionMethod(cn, insnNode.getOpcode())); 30 | } 31 | 32 | MethodNode comparisionMethod = comparisionMethodMap.get(insnNode.getOpcode()); 33 | 34 | // Invokes the comparision method instead of the comparision opcode 35 | // e.g: invokestatic Test.compare:(DD)I 36 | node.instructions.insert(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, cn.name, comparisionMethod.name, comparisionMethod.desc, false)); 37 | node.instructions.remove(insnNode); 38 | } 39 | } 40 | 41 | return comparisionMethodMap.values(); 42 | 43 | } 44 | 45 | /** 46 | * Generates a method that looks like this: 47 | *

48 | * private static int compare(double, double); 49 | * Flags: PRIVATE, STATIC 50 | * Code: 51 | * 0: dload_0 52 | * 1: dload_2 53 | * 2: dcmpl (<--- The opcode) 54 | * 3: ireturn 55 | * 56 | * @param cn The ClassNode the method is supposed to be 57 | * @param opcode the comparision opcode. Allowed opcodes: LCMP, FCMPL, FCMPG, DCMPL, DCMPG 58 | * @return The method node 59 | */ 60 | private static MethodNode generateComparisionMethod(ClassNode cn, int opcode) { 61 | if (!(opcode >= Opcodes.LCMP && opcode <= Opcodes.DCMPG)) 62 | throw new IllegalArgumentException("The opcode must be LCMP, FCMPL, FCMPG, DCMPL or DCMPG"); 63 | 64 | // The type of numbers which are compared 65 | Type type = opcode == Opcodes.LCMP ? Type.LONG_TYPE : (opcode == Opcodes.FCMPG || opcode == Opcodes.FCMPL) ? Type.FLOAT_TYPE : Type.DOUBLE_TYPE; 66 | String desc = "(" + type.toString() + type.toString() + ")I"; 67 | 68 | MethodNode methodNode = new MethodNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, NameUtils.generateMethodName(cn, desc), desc, null, new String[0]); 69 | 70 | methodNode.instructions = new InsnList(); 71 | 72 | methodNode.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 0)); 73 | methodNode.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), type.getSize())); 74 | methodNode.instructions.add(new InsnNode(opcode)); 75 | methodNode.instructions.add(new InsnNode(Opcodes.IRETURN)); 76 | 77 | return methodNode; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/flowObfuscation/ReturnMangler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.flowObfuscation; 12 | 13 | import me.superblaubeere27.jobf.ProcessorCallback; 14 | import me.superblaubeere27.jobf.utils.VariableProvider; 15 | import org.objectweb.asm.Opcodes; 16 | import org.objectweb.asm.Type; 17 | import org.objectweb.asm.tree.*; 18 | 19 | import java.lang.reflect.Modifier; 20 | 21 | class ReturnMangler { 22 | static void mangleReturn(ProcessorCallback callback, MethodNode node) { 23 | if (Modifier.isAbstract(node.access) || Modifier.isNative(node.access)) return; 24 | 25 | VariableProvider variableProvider = new VariableProvider(node); 26 | 27 | LabelNode returnLabel = new LabelNode(); 28 | Type returnType = Type.getReturnType(node.desc); 29 | boolean isVoidType = returnType.getSort() == Type.VOID; 30 | int returnSlot = -1; 31 | 32 | if (!isVoidType) { 33 | returnSlot = variableProvider.allocateVar(); 34 | } 35 | 36 | for (AbstractInsnNode abstractInsnNode : node.instructions.toArray()) { 37 | if (abstractInsnNode.getOpcode() >= Opcodes.IRETURN && abstractInsnNode.getOpcode() <= Opcodes.RETURN) { 38 | InsnList insnList = new InsnList(); 39 | 40 | if (!isVoidType) { 41 | insnList.add(new VarInsnNode(returnType.getOpcode(Opcodes.ISTORE), returnSlot)); 42 | } 43 | 44 | insnList.add(new JumpInsnNode(Opcodes.GOTO, returnLabel)); 45 | 46 | node.instructions.insert(abstractInsnNode, insnList); 47 | node.instructions.remove(abstractInsnNode); 48 | } 49 | } 50 | 51 | if (isVoidType) { 52 | node.instructions.add(returnLabel); 53 | node.instructions.add(new InsnNode(Opcodes.RETURN)); 54 | } else { 55 | node.instructions.add(returnLabel); 56 | node.instructions.add(new VarInsnNode(returnType.getOpcode(Opcodes.ILOAD), returnSlot)); 57 | node.instructions.add(new InsnNode((returnType.getOpcode(Opcodes.IRETURN)))); 58 | } 59 | 60 | callback.setForceComputeFrames(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/flowObfuscation/SwitchMangler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.flowObfuscation; 12 | 13 | import me.superblaubeere27.jobf.processors.NumberObfuscationTransformer; 14 | import me.superblaubeere27.jobf.utils.VariableProvider; 15 | import org.objectweb.asm.Opcodes; 16 | import org.objectweb.asm.tree.*; 17 | 18 | import java.lang.reflect.Modifier; 19 | import java.util.List; 20 | 21 | class SwitchMangler { 22 | 23 | static void mangleSwitches(MethodNode node) { 24 | if (Modifier.isAbstract(node.access) || Modifier.isNative(node.access)) 25 | return; 26 | 27 | VariableProvider provider = new VariableProvider(node); 28 | int resultSlot = provider.allocateVar(); 29 | 30 | for (AbstractInsnNode abstractInsnNode : node.instructions.toArray()) { 31 | if (abstractInsnNode instanceof TableSwitchInsnNode) { 32 | TableSwitchInsnNode switchInsnNode = (TableSwitchInsnNode) abstractInsnNode; 33 | 34 | InsnList insnList = new InsnList(); 35 | insnList.add(new VarInsnNode(Opcodes.ISTORE, resultSlot)); 36 | 37 | int j = 0; 38 | 39 | for (int i = switchInsnNode.min; i <= switchInsnNode.max; i++) { 40 | insnList.add(new VarInsnNode(Opcodes.ILOAD, resultSlot)); 41 | insnList.add(NumberObfuscationTransformer.getInstructions(i)); 42 | insnList.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, switchInsnNode.labels.get(j))); 43 | 44 | j++; 45 | } 46 | insnList.add(new JumpInsnNode(Opcodes.GOTO, switchInsnNode.dflt)); 47 | 48 | 49 | node.instructions.insert(abstractInsnNode, insnList); 50 | node.instructions.remove(abstractInsnNode); 51 | } 52 | if (abstractInsnNode instanceof LookupSwitchInsnNode) { 53 | LookupSwitchInsnNode switchInsnNode = (LookupSwitchInsnNode) abstractInsnNode; 54 | 55 | InsnList insnList = new InsnList(); 56 | insnList.add(new VarInsnNode(Opcodes.ISTORE, resultSlot)); 57 | 58 | List keys = switchInsnNode.keys; 59 | for (int i = 0; i < keys.size(); i++) { 60 | Integer key = keys.get(i); 61 | insnList.add(new VarInsnNode(Opcodes.ILOAD, resultSlot)); 62 | insnList.add(NumberObfuscationTransformer.getInstructions(key)); 63 | insnList.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, switchInsnNode.labels.get(i))); 64 | 65 | } 66 | 67 | insnList.add(new JumpInsnNode(Opcodes.GOTO, switchInsnNode.dflt)); 68 | 69 | 70 | node.instructions.insert(abstractInsnNode, insnList); 71 | node.instructions.remove(abstractInsnNode); 72 | } 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/flowObfuscation/codegen/ITrashCodeGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.flowObfuscation.codegen; 12 | 13 | import org.objectweb.asm.tree.ClassNode; 14 | import org.objectweb.asm.tree.InsnList; 15 | import org.objectweb.asm.tree.MethodNode; 16 | 17 | public interface ITrashCodeGenerator { 18 | 19 | InsnList gen(TrashCodeGenerator generator, ClassNode classNode, MethodNode methodNode); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/flowObfuscation/codegen/TrashCodeGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.flowObfuscation.codegen; 12 | 13 | public class TrashCodeGenerator { 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/ClassWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.name; 12 | 13 | import org.objectweb.asm.tree.ClassNode; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Wrapper for ClassNodes. 19 | * 20 | * @author ItzSomebody 21 | */ 22 | public class ClassWrapper { 23 | /** 24 | * Attached class node. 25 | */ 26 | public ClassNode classNode; 27 | 28 | /** 29 | * Original name of ClassNode. Really useful when class got renamed. 30 | */ 31 | public String originalName; 32 | 33 | /** 34 | * Quick way of figuring out if this is represents library class or not. 35 | */ 36 | public boolean libraryNode; 37 | 38 | /** 39 | * Required if you wanna load it at runtime. (For COMPUTE_FRAMES) 40 | */ 41 | public byte[] originalClass; 42 | 43 | /** 44 | * Methods. 45 | */ 46 | public ArrayList methods = new ArrayList<>(); 47 | 48 | /** 49 | * Fields. 50 | */ 51 | public ArrayList fields = new ArrayList<>(); 52 | 53 | /** 54 | * Creates a ClassWrapper object. 55 | * 56 | * @param classNode the attached {@link ClassNode}. 57 | * @param libraryNode is this a library class? 58 | * @param originalClass Original bytes of the class 59 | */ 60 | public ClassWrapper(ClassNode classNode, boolean libraryNode, byte[] originalClass) { 61 | this.classNode = classNode; 62 | this.originalName = classNode.name; 63 | this.libraryNode = libraryNode; 64 | this.originalClass = originalClass; 65 | 66 | ClassWrapper instance = this; 67 | classNode.methods.forEach(methodNode -> methods.add(new MethodWrapper(methodNode, instance, methodNode.name, 68 | methodNode.desc))); 69 | if (classNode.fields != null) { 70 | classNode.fields.forEach(fieldNode -> fields.add(new FieldWrapper(fieldNode, instance, fieldNode.name, 71 | fieldNode.desc))); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/CommonPackageTrees.java: -------------------------------------------------------------------------------- 1 | package me.superblaubeere27.jobf.processors.name; 2 | 3 | import com.google.common.base.Throwables; 4 | import me.superblaubeere27.jobf.JObf; 5 | import me.superblaubeere27.jobf.utils.Utils; 6 | 7 | import java.util.*; 8 | 9 | /* 10 | * A collection of common packages stored in a tree format 11 | * 12 | * @Author cookiedragon234 13 | */ 14 | public class CommonPackageTrees 15 | { 16 | public static List root; 17 | 18 | private static Tree com; 19 | private static Tree org; 20 | private static Tree javax; 21 | private static Tree net; 22 | 23 | private static Random random = new Random(); 24 | 25 | static 26 | { 27 | root = new ArrayList<>(); 28 | 29 | com = new Tree("com"); 30 | 31 | // Google 32 | Tree comgoogle = com.add("google"); 33 | Tree comgooglecommon = comgoogle.add("common"); 34 | comgooglecommon.add(Arrays.asList( 35 | "annotations", 36 | "base", 37 | "cache", 38 | "collect", 39 | "escape", 40 | "eventbus", 41 | "graph", 42 | "hash", 43 | "html", 44 | "io", 45 | "math", 46 | "net", 47 | "primitives", 48 | "reflect", 49 | "util", 50 | "xml" 51 | )); 52 | comgoogle.add("java"); 53 | 54 | com.add("fasterxml").add("jackson").add("core"); 55 | 56 | org = new Tree("org"); 57 | Tree orgapache = org.add("apache"); 58 | Tree orgapachecommons = orgapache.add("commons"); 59 | orgapachecommons.add("codec"); 60 | orgapachecommons.add("io"); 61 | orgapachecommons.add("logging"); 62 | orgapache.add("http"); 63 | org.add("json"); 64 | org.add("reflections"); 65 | org.add("scala"); 66 | org.add("yaml"); 67 | 68 | javax = new Tree("javax"); 69 | javax.add("vecmath"); 70 | 71 | net = new Tree("net"); 72 | net.add("jodah").add("typetools"); 73 | 74 | 75 | root.addAll(Arrays.asList(com, org, javax, net)); 76 | } 77 | 78 | public static String getRandomPackage() 79 | { 80 | Tree current = null; 81 | StringBuilder path = new StringBuilder(); 82 | while(true) 83 | { 84 | if(current == null) 85 | { 86 | current = root.get(random.nextInt(root.size())); 87 | } 88 | 89 | path.append(current.data).append("/"); 90 | 91 | if(random.nextBoolean() || current.leaves.size() <= 0) 92 | { 93 | return path.toString(); 94 | } 95 | 96 | int i = random.nextInt(current.leaves.size()); 97 | current = current.leaves.get(i); 98 | } 99 | } 100 | } 101 | 102 | class Tree { 103 | public List leaves = new LinkedList<>(); 104 | public Tree parent = null; 105 | public String data; 106 | 107 | public Tree(String data) { this(data, null); } 108 | public Tree(String data, Tree parent) { 109 | this.data = data; 110 | this.parent = parent; 111 | } 112 | 113 | public Tree add(String childData) { return add(new Tree(childData, this)); } 114 | public Tree add(Tree child) { leaves.add(child); return child; } 115 | 116 | public void add(List children) { 117 | for(String s: children) 118 | { 119 | add(s); 120 | } 121 | } 122 | 123 | public Tree get(Tree child) { 124 | return get(child.data); 125 | } 126 | public Tree get(String childData) { 127 | for(Tree leaf: leaves){ 128 | if(leaf.data.equals(childData)) 129 | return leaf; 130 | } 131 | return null; 132 | } 133 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/FieldWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.name; 12 | 13 | import org.objectweb.asm.tree.FieldNode; 14 | 15 | /** 16 | * Wrapper for FieldNodes. 17 | * 18 | * @author ItzSomebody. 19 | */ 20 | public class FieldWrapper { 21 | /** 22 | * Owner of this represented field. 23 | */ 24 | public ClassWrapper owner; 25 | /** 26 | * Attached FieldNode. 27 | */ 28 | FieldNode fieldNode; 29 | /** 30 | * Original field name. 31 | */ 32 | String originalName; 33 | 34 | /** 35 | * Original field description. 36 | */ 37 | String originalDescription; 38 | 39 | /** 40 | * Creates a FieldWrapper object. 41 | * 42 | * @param fieldNode the {@link FieldNode} attached to this FieldWrapper. 43 | * @param owner the owner of this represented field. 44 | * @param originalName the original name of the field represented. 45 | * @param originalDescription the original description of the field represented. 46 | */ 47 | FieldWrapper(FieldNode fieldNode, ClassWrapper owner, String originalName, String originalDescription) { 48 | this.fieldNode = fieldNode; 49 | this.owner = owner; 50 | this.originalName = originalName; 51 | this.originalDescription = originalDescription; 52 | } 53 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/INameObfuscationProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.name; 12 | 13 | import me.superblaubeere27.jobf.JObfImpl; 14 | import org.objectweb.asm.tree.ClassNode; 15 | 16 | import java.util.HashMap; 17 | 18 | public interface INameObfuscationProcessor { 19 | void transformPost(JObfImpl inst, HashMap nodes); 20 | } 21 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/InnerClassRemover.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.name; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import me.superblaubeere27.jobf.IClassTransformer; 15 | import me.superblaubeere27.jobf.JObfImpl; 16 | import me.superblaubeere27.jobf.ProcessorCallback; 17 | import me.superblaubeere27.jobf.utils.NameUtils; 18 | import me.superblaubeere27.jobf.utils.values.BooleanValue; 19 | import me.superblaubeere27.jobf.utils.values.DeprecationLevel; 20 | import me.superblaubeere27.jobf.utils.values.EnabledValue; 21 | import org.objectweb.asm.commons.ClassRemapper; 22 | import org.objectweb.asm.tree.ClassNode; 23 | 24 | import java.util.ArrayList; 25 | import java.util.HashMap; 26 | import java.util.List; 27 | import java.util.Map; 28 | import java.util.regex.Pattern; 29 | 30 | public class InnerClassRemover implements INameObfuscationProcessor, IClassTransformer { 31 | private static final String PROCESSOR_NAME = "InnerClassRemover"; 32 | private static Pattern innerClasses = Pattern.compile(".*[A-Za-z0-9]+\\$[0-9]+"); 33 | private EnabledValue enabled = new EnabledValue(PROCESSOR_NAME, DeprecationLevel.GOOD, true); 34 | private BooleanValue remap = new BooleanValue(PROCESSOR_NAME, "Remap", DeprecationLevel.OK, false); 35 | private BooleanValue removeMetadata = new BooleanValue(PROCESSOR_NAME, "Remove Metadata", DeprecationLevel.GOOD, true); 36 | 37 | @Override 38 | public void transformPost(JObfImpl inst, HashMap nodes) { 39 | if (!enabled.getObject() || !remap.getObject()) return; 40 | 41 | final List classNodes = new ArrayList<>(JObfImpl.classes.values()); 42 | 43 | final Map updatedClasses = new HashMap<>(); 44 | final CustomRemapper remapper = new CustomRemapper(); 45 | 46 | for (ClassNode classNode : classNodes) { 47 | if (innerClasses.matcher(classNode.name).matches()) { 48 | String newName; 49 | 50 | if (classNode.name.contains("/")) { 51 | String packageName = classNode.name.substring(0, classNode.name.lastIndexOf('/')); 52 | newName = packageName + "/" + NameUtils.generateClassName(packageName); 53 | } else newName = NameUtils.generateClassName(); 54 | 55 | String mappedName; 56 | 57 | 58 | do { 59 | mappedName = newName; 60 | } while (!remapper.map(classNode.name, mappedName)); 61 | } 62 | } 63 | 64 | for (final ClassNode classNode : classNodes) { 65 | JObfImpl.classes.remove(classNode.name + ".class"); 66 | 67 | ClassNode newNode = new ClassNode(); 68 | ClassRemapper classRemapper = new ClassRemapper(newNode, remapper); 69 | classNode.accept(classRemapper); 70 | 71 | // if (!classNode.name.equals(newNode.name)) 72 | // Fume.fume.obfuscator.classTransforms.put(classNode.name, newNode.name); 73 | 74 | updatedClasses.put(newNode.name + ".class", newNode); 75 | } 76 | 77 | updatedClasses.forEach((s, classNode) -> JObfImpl.classes.put(s, classNode)); 78 | } 79 | 80 | @Override 81 | public void process(ProcessorCallback callback, ClassNode node) { 82 | if (!enabled.getObject() || !removeMetadata.getObject()) return; 83 | 84 | node.outerClass = null; 85 | node.innerClasses.clear(); 86 | 87 | node.outerMethod = null; 88 | node.outerMethodDesc = null; 89 | } 90 | 91 | @Override 92 | public ObfuscationTransformer getType() { 93 | return ObfuscationTransformer.INNER_CLASS_REMOVER; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/MemberRemapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.name; 12 | 13 | import org.objectweb.asm.commons.SimpleRemapper; 14 | 15 | import java.util.Map; 16 | 17 | /** 18 | * Custom implementation of ASM's SimpleRemapper taking in account for field descriptions. 19 | * 20 | * @author ItzSomebody 21 | */ 22 | public class MemberRemapper extends SimpleRemapper { 23 | 24 | MemberRemapper(final Map mappings) { 25 | super(mappings); 26 | } 27 | 28 | @Override 29 | public String mapFieldName(String owner, String name, String desc) { 30 | String remappedName = map(owner + '.' + name + '.' + desc); 31 | return (remappedName != null) ? remappedName : name; 32 | } 33 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/name/MethodWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.name; 12 | 13 | import org.objectweb.asm.tree.MethodNode; 14 | 15 | /** 16 | * Wrapper for MethodNodes. 17 | * 18 | * @author ItzSomebody 19 | */ 20 | public class MethodWrapper { 21 | /** 22 | * Owner of the method this MethodWrapper represents. 23 | */ 24 | public ClassWrapper owner; 25 | /** 26 | * Attached MethodNode. 27 | */ 28 | MethodNode methodNode; 29 | /** 30 | * Original method name; 31 | */ 32 | String originalName; 33 | 34 | /** 35 | * Original method description. 36 | */ 37 | String originalDescription; 38 | 39 | /** 40 | * Creates a MethodWrapper object. 41 | * 42 | * @param methodNode the {@link MethodNode} this wrapper represents. 43 | * @param owner the owner of this represented method. 44 | * @param originalName the original method name. 45 | * @param originalDescription the original method description. 46 | */ 47 | MethodWrapper(MethodNode methodNode, ClassWrapper owner, String originalName, String originalDescription) { 48 | this.methodNode = methodNode; 49 | this.owner = owner; 50 | this.originalName = originalName; 51 | this.originalDescription = originalDescription; 52 | } 53 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/optimizer/ComparisionReplacer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.optimizer; 12 | 13 | import me.superblaubeere27.jobf.utils.Utils; 14 | import org.objectweb.asm.Opcodes; 15 | import org.objectweb.asm.tree.*; 16 | 17 | class ComparisionReplacer { 18 | static void replaceComparisons(MethodNode method, boolean replaceEquals, boolean replaceEqualsIgnoreCase) { 19 | for (AbstractInsnNode insnNode : method.instructions.toArray()) { 20 | if (insnNode instanceof MethodInsnNode) { 21 | MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; 22 | 23 | if (replaceEquals && Utils.matchMethodNode(methodInsnNode, "java/lang/String.equals:(Ljava/lang/Object;)Z")) { 24 | InsnList replacement = new InsnList(); 25 | 26 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false)); 27 | replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)); 28 | 29 | replacement.add(new InsnNode(Opcodes.SWAP)); 30 | 31 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false)); 32 | replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)); 33 | 34 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "equals", "(Ljava/lang/Object;)Z", false)); 35 | 36 | method.instructions.insert(insnNode, replacement); 37 | method.instructions.remove(insnNode); 38 | } 39 | if (replaceEqualsIgnoreCase && Utils.matchMethodNode(methodInsnNode, "java/lang/String.equalsIgnoreCase:(Ljava/lang/String;)Z")) { 40 | InsnList replacement = new InsnList(); 41 | 42 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "toUpperCase", "()Ljava/lang/String;", false)); 43 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false)); 44 | replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)); 45 | 46 | replacement.add(new InsnNode(Opcodes.SWAP)); 47 | 48 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "toUpperCase", "()Ljava/lang/String;", false)); 49 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false)); 50 | replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)); 51 | 52 | replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "equals", "(Ljava/lang/Object;)Z", false)); 53 | 54 | method.instructions.insert(insnNode, replacement); 55 | method.instructions.remove(insnNode); 56 | } 57 | } 58 | } 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/optimizer/InsertedMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.optimizer; 12 | 13 | public class InsertedMethods { 14 | 15 | public static boolean startsWith(String str, int len, int hashCode) { 16 | if (str.length() < len) return false; 17 | 18 | return str.substring(0, len).hashCode() == hashCode; 19 | } 20 | 21 | static boolean endsWith(String str, int len, int hashCode) { 22 | if (str.length() < len) return false; 23 | 24 | return str.substring(str.length() - len).hashCode() == hashCode; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/optimizer/Optimizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.optimizer; 12 | 13 | import me.superblaubeere27.annotations.ObfuscationTransformer; 14 | import me.superblaubeere27.jobf.IClassTransformer; 15 | import me.superblaubeere27.jobf.ProcessorCallback; 16 | import me.superblaubeere27.jobf.utils.values.BooleanValue; 17 | import me.superblaubeere27.jobf.utils.values.DeprecationLevel; 18 | import me.superblaubeere27.jobf.utils.values.EnabledValue; 19 | import org.objectweb.asm.tree.ClassNode; 20 | import org.objectweb.asm.tree.MethodNode; 21 | 22 | public class Optimizer implements IClassTransformer { 23 | private static final String PROCESSOR_NAME = "Optimizer"; 24 | private EnabledValue enabledValue = new EnabledValue(PROCESSOR_NAME, DeprecationLevel.OK, false); 25 | private BooleanValue replaceEquals = new BooleanValue(PROCESSOR_NAME, "Replace String.equals()", "NOT TESTED", DeprecationLevel.OK, false); 26 | private BooleanValue replaceEqualsIgnoreCase = new BooleanValue(PROCESSOR_NAME, "Replace String.equalsIgnoreCase()", "Might break some comparisons with strings that contains unicode chars", DeprecationLevel.OK, false); 27 | private BooleanValue optimizeStringCalls = new BooleanValue(PROCESSOR_NAME, "Optimize static string calls", null, DeprecationLevel.GOOD, false); 28 | 29 | @Override 30 | public void process(ProcessorCallback callback, ClassNode node) { 31 | if (!enabledValue.getObject()) return; 32 | 33 | for (MethodNode method : node.methods) { 34 | if (replaceEquals.getObject() || replaceEqualsIgnoreCase.getObject()) 35 | ComparisionReplacer.replaceComparisons(method, replaceEquals.getObject(), replaceEqualsIgnoreCase.getObject()); 36 | if (optimizeStringCalls.getObject()) StaticStringCallOptimizer.optimize(method); 37 | } 38 | } 39 | 40 | @Override 41 | public ObfuscationTransformer getType() { 42 | return ObfuscationTransformer.PEEPHOLE_OPTIMIZER; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/processors/optimizer/StaticStringCallOptimizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.processors.optimizer; 12 | 13 | import me.superblaubeere27.jobf.utils.NodeUtils; 14 | import me.superblaubeere27.jobf.utils.Utils; 15 | import org.objectweb.asm.tree.AbstractInsnNode; 16 | import org.objectweb.asm.tree.LdcInsnNode; 17 | import org.objectweb.asm.tree.MethodInsnNode; 18 | import org.objectweb.asm.tree.MethodNode; 19 | 20 | class StaticStringCallOptimizer { 21 | 22 | static void optimize(MethodNode method) { 23 | boolean found; 24 | 25 | do { 26 | found = false; 27 | 28 | for (AbstractInsnNode insnNode : method.instructions.toArray()) { 29 | if (insnNode instanceof MethodInsnNode) { 30 | MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; 31 | AbstractInsnNode prev = Utils.getPrevious(methodInsnNode, 1); 32 | 33 | if (prev instanceof LdcInsnNode && ((LdcInsnNode) prev).cst instanceof String && (Utils.matchMethodNode(methodInsnNode, "java/lang/Object.hashCode:()I") || Utils.matchMethodNode(methodInsnNode, "java/lang/String.hashCode:()I"))) { 34 | method.instructions.insert(insnNode, NodeUtils.generateIntPush(((LdcInsnNode) prev).cst.hashCode())); 35 | method.instructions.remove(insnNode); 36 | method.instructions.remove(prev); 37 | found = true; 38 | } 39 | if (prev instanceof LdcInsnNode && ((LdcInsnNode) prev).cst instanceof String && (Utils.matchMethodNode(methodInsnNode, "java/lang/String.toUpperCase:()Ljava/lang/String;"))) { 40 | method.instructions.insert(insnNode, new LdcInsnNode(((String) ((LdcInsnNode) prev).cst).toUpperCase())); 41 | method.instructions.remove(insnNode); 42 | method.instructions.remove(prev); 43 | found = true; 44 | } 45 | if (prev instanceof LdcInsnNode && ((LdcInsnNode) prev).cst instanceof String && (Utils.matchMethodNode(methodInsnNode, "java/lang/String.toLowerCase:()Ljava/lang/String;"))) { 46 | method.instructions.insert(insnNode, new LdcInsnNode(((String) ((LdcInsnNode) prev).cst).toLowerCase())); 47 | method.instructions.remove(insnNode); 48 | method.instructions.remove(prev); 49 | found = true; 50 | } 51 | } 52 | } 53 | } while (found); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/AnnotationUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | public class AnnotationUtils { 14 | 15 | // public static boolean isExcluded(ClassNode node, ObfuscationTransformer type) { 16 | // if (node.visibleAnnotations != null && isExcluded(node.invisibleAnnotations, type)) { 17 | // return true; 18 | // } 19 | // return node.invisibleAnnotations != null && isExcluded(node.invisibleAnnotations, type); 20 | // } 21 | // public static boolean isExcluded(List annotations, ObfuscationTransformer type) { 22 | // for (AnnotationNode annotation : annotations) { 23 | // if (annotation.desc.equals("L" + ObfuscatorRules.class.getName().replace('.', '/') + ";")) { 24 | // if (annotation.values.size() < 2 || !annotation.values.get(0).equals("value")) { 25 | // continue; 26 | // } 27 | // List rules; 28 | // 29 | // if (annotation.values.get(1) instanceof List) { 30 | // rules = (List) annotation.values.get(1); 31 | // } else if (annotation.values.get(1) instanceof AnnotationNode) { 32 | // rules = Collections.singletonList((AnnotationNode) annotation.values.get(1)); 33 | // } else { 34 | // continue; 35 | // } 36 | // 37 | // 38 | // for (AnnotationNode rule : rules) { 39 | // Rule.Action action = null; 40 | // 41 | // for (int i = 0; i < rule.values.size(); i++) { 42 | // Object o = rule.values.get(i); 43 | // 44 | // if (o instanceof ) { 45 | // 46 | // } 47 | // } 48 | // 49 | // } 50 | // } 51 | // } 52 | // return false; 53 | // } 54 | } 55 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/ClassTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import me.superblaubeere27.jobf.processors.name.ClassWrapper; 14 | 15 | import java.util.HashSet; 16 | import java.util.Set; 17 | 18 | /** 19 | * Used to keep information on the hierarchy of all loaded classes. 20 | * 21 | * @author ItzSomebody 22 | */ 23 | public class ClassTree { 24 | /** 25 | * Attached ClassWrapper. 26 | */ 27 | public ClassWrapper classWrapper; 28 | 29 | /** 30 | * Names of classes this represented class inherits from. 31 | */ 32 | public Set parentClasses = new HashSet<>(); 33 | 34 | /** 35 | * Names of classes this represented class is inherited by. 36 | */ 37 | public Set subClasses = new HashSet<>(); 38 | 39 | /** 40 | * If one of the super-classes is missing this is set to true. 41 | * It prevents methods from being remapped. 42 | */ 43 | public boolean missingSuperClass; 44 | 45 | /** 46 | * Creates a ClassTree object. 47 | * 48 | * @param classWrapper the ClassWraper attached to this ClassTree. 49 | */ 50 | public ClassTree(ClassWrapper classWrapper) { 51 | this.classWrapper = classWrapper; 52 | } 53 | } -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/ConsoleUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import java.util.List; 14 | 15 | public class ConsoleUtils { 16 | 17 | public static String formatBox(String title, boolean center, List lines) { 18 | int width = title.length() + 4; 19 | 20 | for (String line : lines) { 21 | int lineWidth = line.length() + 2; 22 | 23 | if (lineWidth > width) width = lineWidth; 24 | } 25 | 26 | int i = 0; 27 | 28 | StringBuilder sb = new StringBuilder(); 29 | 30 | sb.append("+"); 31 | 32 | centerString(sb, "[ " + title + " ]", "-", width); 33 | sb.append("+"); 34 | 35 | sb.append("\n"); 36 | 37 | for (String line : lines) { 38 | sb.append("|"); 39 | 40 | if (center) { 41 | centerString(sb, line, " ", width); 42 | } else { 43 | sb.append(" ").append(line); 44 | 45 | addTimes(sb, width - line.length() - 1, " "); 46 | } 47 | 48 | 49 | sb.append("|"); 50 | sb.append("\n"); 51 | } 52 | 53 | sb.append("+"); 54 | 55 | addTimes(sb, width, "-"); 56 | 57 | sb.append("+"); 58 | 59 | return sb.toString(); 60 | } 61 | 62 | private static void centerString(StringBuilder stringBuilder, String stringToCenter, String fillChar, int width) { 63 | int sideOffset = width - stringToCenter.length(); 64 | 65 | addTimes(stringBuilder, sideOffset / 2, fillChar); 66 | 67 | stringBuilder.append(stringToCenter); 68 | 69 | addTimes(stringBuilder, sideOffset - sideOffset / 2, fillChar); 70 | } 71 | 72 | private static void addTimes(StringBuilder sb, int times, String s) { 73 | for (int i = 0; i < times; i++) { 74 | sb.append(s); 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/JObfFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import javax.swing.filechooser.FileFilter; 14 | import java.io.File; 15 | 16 | public class JObfFileFilter extends FileFilter { 17 | @Override 18 | public boolean accept(File f) { 19 | return true; 20 | } 21 | 22 | @Override 23 | public String getDescription() { 24 | return "JObf files (*.jocfg)"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/JarFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import javax.swing.filechooser.FileFilter; 14 | import java.io.File; 15 | 16 | public class JarFileFilter extends FileFilter { 17 | @Override 18 | public boolean accept(File f) { 19 | String name = f.getName(); 20 | return f.isDirectory() || name.endsWith(".jar") || name.endsWith(".zip"); 21 | } 22 | 23 | @Override 24 | public String getDescription() { 25 | return "Java Archives (*.jar/*.zip)"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/MissingClassException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | public class MissingClassException extends RuntimeException { 14 | public MissingClassException() { 15 | } 16 | 17 | public MissingClassException(String message) { 18 | super(message); 19 | } 20 | 21 | public MissingClassException(String message, Throwable cause) { 22 | super(message, cause); 23 | } 24 | 25 | public MissingClassException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | public MissingClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 30 | super(message, cause, enableSuppression, writableStackTrace); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/PrimitiveUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import org.objectweb.asm.Opcodes; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | public class PrimitiveUtils { 19 | private static final Map> nameToPrimitive = new HashMap<>(); 20 | private static final Map, Object> defaultPrimitiveValues = new HashMap<>(); 21 | 22 | static { 23 | defaultPrimitiveValues.put(Integer.TYPE, 0); 24 | defaultPrimitiveValues.put(Long.TYPE, 0L); 25 | defaultPrimitiveValues.put(Double.TYPE, 0D); 26 | defaultPrimitiveValues.put(Float.TYPE, 0F); 27 | defaultPrimitiveValues.put(Boolean.TYPE, false); 28 | defaultPrimitiveValues.put(Character.TYPE, '\0'); 29 | defaultPrimitiveValues.put(Byte.TYPE, (byte) 0); 30 | defaultPrimitiveValues.put(Short.TYPE, (short) 0); 31 | defaultPrimitiveValues.put(Object.class, null); 32 | nameToPrimitive.put("int", Integer.TYPE); 33 | nameToPrimitive.put("long", Long.TYPE); 34 | nameToPrimitive.put("double", Double.TYPE); 35 | nameToPrimitive.put("float", Float.TYPE); 36 | nameToPrimitive.put("boolean", Boolean.TYPE); 37 | nameToPrimitive.put("char", Character.TYPE); 38 | nameToPrimitive.put("byte", Byte.TYPE); 39 | nameToPrimitive.put("short", Short.TYPE); 40 | nameToPrimitive.put("void", Void.TYPE); 41 | } 42 | 43 | public static Class getPrimitiveByName(String name) { 44 | return nameToPrimitive.get(name); 45 | } 46 | 47 | public static Object getDefaultValue(Class primitive) { 48 | return defaultPrimitiveValues.get(primitive); 49 | } 50 | 51 | public static Class getPrimitiveByNewArrayId(int id) { 52 | switch (id) { 53 | case Opcodes.T_BOOLEAN: 54 | return boolean.class; 55 | case Opcodes.T_CHAR: 56 | return char.class; 57 | case Opcodes.T_FLOAT: 58 | return float.class; 59 | case Opcodes.T_DOUBLE: 60 | return double.class; 61 | case Opcodes.T_BYTE: 62 | return byte.class; 63 | case Opcodes.T_SHORT: 64 | return short.class; 65 | case Opcodes.T_INT: 66 | return int.class; 67 | case Opcodes.T_LONG: 68 | return long.class; 69 | } 70 | throw new IllegalArgumentException("Unknown type " + id); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/StringManipulationUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import java.util.Random; 14 | 15 | public class StringManipulationUtils 16 | { 17 | 18 | private static final Random random = new Random(); 19 | 20 | public static String makeUnreadable(final String input) { 21 | final StringBuilder builder = new StringBuilder(); 22 | for (final char c : input.toCharArray()) 23 | builder.append((char) (c + '\u7159')); 24 | return builder.toString(); 25 | } 26 | 27 | public static String generateString(int lenght) { 28 | final String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 29 | final StringBuilder stringBuilder = new StringBuilder(lenght); 30 | 31 | for (int i = 0; i < lenght; i++) 32 | stringBuilder.append(s.charAt(random.nextInt(s.length()))); 33 | return stringBuilder.toString(); 34 | } 35 | 36 | public static String generateUnicodeString(int lenght) { 37 | final StringBuilder stringBuilder = new StringBuilder(lenght); 38 | 39 | for (int i = 0; i < lenght; i++) 40 | stringBuilder.append((char) random.nextInt(255)); 41 | return stringBuilder.toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/Template.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | public class Template { 14 | private String name; 15 | private String json; 16 | 17 | Template(String name, String json) { 18 | this.name = name; 19 | this.json = json; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public String getJson() { 27 | return json; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return String.format("%s", name); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/Templates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2019 superblaubeere27, Sam Sun, MarcoMC 3 | * 4 | * 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: 5 | * 6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | * 8 | * 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. 9 | */ 10 | 11 | package me.superblaubeere27.jobf.utils; 12 | 13 | import com.google.common.io.ByteStreams; 14 | 15 | import java.io.*; 16 | import java.nio.charset.StandardCharsets; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class Templates { 21 | private static List