├── .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 |
4 |
5 |
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 TEMPLATES = new ArrayList<>();
22 |
23 | public static void loadTemplates() {
24 | try {
25 | for (String name : getResourceFiles()) {
26 | TEMPLATES.add(new Template(name.replace(".json", ""), new String(ByteStreams.toByteArray(Templates.class.getResourceAsStream("/templates/" + name)), StandardCharsets.UTF_8)));
27 | }
28 | } catch (IOException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | private static List getResourceFiles() throws IOException {
34 | List filenames = new ArrayList<>();
35 |
36 | try (
37 | InputStream in = getResourceAsStream("/templates");
38 | BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
39 | String resource;
40 |
41 | while ((resource = br.readLine()) != null) {
42 | filenames.add(resource);
43 | }
44 | }
45 |
46 | return filenames;
47 | }
48 |
49 | private static InputStream getResourceAsStream(String resource) {
50 | InputStream in
51 | = getContextClassLoader().getResourceAsStream(resource);
52 |
53 | if (in == null) {
54 | in = Templates.class.getResourceAsStream(resource);
55 | }
56 |
57 | return in == null ? new ByteArrayInputStream(new byte[0]) : in;
58 | }
59 |
60 | private static ClassLoader getContextClassLoader() {
61 | return Thread.currentThread().getContextClassLoader();
62 | }
63 |
64 | public static List getTemplates() {
65 | return TEMPLATES;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/VariableProvider.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.Type;
14 | import org.objectweb.asm.tree.AbstractInsnNode;
15 | import org.objectweb.asm.tree.MethodNode;
16 | import org.objectweb.asm.tree.VarInsnNode;
17 |
18 | import java.lang.reflect.Modifier;
19 |
20 | public class VariableProvider {
21 | private int max = 0;
22 | private int argumentSize;
23 |
24 | private VariableProvider() {
25 |
26 | }
27 |
28 | public VariableProvider(MethodNode method) {
29 | this();
30 |
31 | if (!Modifier.isStatic(method.access)) registerExisting(0, Type.getType("Ljava/lang/Object;"));
32 |
33 | for (Type argumentType : Type.getArgumentTypes(method.desc)) {
34 | registerExisting(argumentType.getSize() + max - 1, argumentType);
35 | }
36 |
37 | argumentSize = max;
38 |
39 | for (AbstractInsnNode abstractInsnNode : method.instructions.toArray()) {
40 | if (abstractInsnNode instanceof VarInsnNode) {
41 | registerExisting(((VarInsnNode) abstractInsnNode).var, Utils.getType((VarInsnNode) abstractInsnNode));
42 | }
43 | }
44 | }
45 |
46 | private void registerExisting(int var, Type type) {
47 | if (var >= max) max = var + type.getSize();
48 | }
49 |
50 | public boolean isUnallocated(int var) {
51 | return var >= max;
52 | }
53 |
54 | public boolean isArgument(int var) {
55 | return var < argumentSize;
56 | }
57 |
58 |
59 | public int allocateVar() {
60 | return max++;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/VersionComparator.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.Comparator;
14 |
15 | /**
16 | * @author Markus Jarderot (https://stackoverflow.com/questions/198431/how-do-you-compare-two-version-strings-in-java)
17 | */
18 | public class VersionComparator implements Comparator {
19 |
20 | public boolean equals(Object o1, Object o2) {
21 | return compare(o1, o2) == 0;
22 | }
23 |
24 | public int compare(Object o1, Object o2) {
25 | String version1 = (String) o1;
26 | String version2 = (String) o2;
27 |
28 | VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
29 | VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
30 |
31 | int number1, number2;
32 | String suffix1, suffix2;
33 |
34 | while (tokenizer1.MoveNext()) {
35 | if (!tokenizer2.MoveNext()) {
36 | do {
37 | number1 = tokenizer1.getNumber();
38 | suffix1 = tokenizer1.getSuffix();
39 | if (number1 != 0 || suffix1.length() != 0) {
40 | // Version one is longer than number two, and non-zero
41 | return 1;
42 | }
43 | }
44 | while (tokenizer1.MoveNext());
45 |
46 | // Version one is longer than version two, but zero
47 | return 0;
48 | }
49 |
50 | number1 = tokenizer1.getNumber();
51 | suffix1 = tokenizer1.getSuffix();
52 | number2 = tokenizer2.getNumber();
53 | suffix2 = tokenizer2.getSuffix();
54 |
55 | if (number1 < number2) {
56 | // Number one is less than number two
57 | return -1;
58 | }
59 | if (number1 > number2) {
60 | // Number one is greater than number two
61 | return 1;
62 | }
63 |
64 | boolean empty1 = suffix1.length() == 0;
65 | boolean empty2 = suffix2.length() == 0;
66 |
67 | if (empty1 && empty2) continue; // No suffixes
68 | if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
69 | if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
70 |
71 | // Lexical comparison of suffixes
72 | int result = suffix1.compareTo(suffix2);
73 | if (result != 0) return result;
74 |
75 | }
76 | if (tokenizer2.MoveNext()) {
77 | do {
78 | number2 = tokenizer2.getNumber();
79 | suffix2 = tokenizer2.getSuffix();
80 | if (number2 != 0 || suffix2.length() != 0) {
81 | // Version one is longer than version two, and non-zero
82 | return -1;
83 | }
84 | }
85 | while (tokenizer2.MoveNext());
86 |
87 | // Version two is longer than version one, but zero
88 | return 0;
89 | }
90 | return 0;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/VersionTokenizer.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 | /**
14 | * @author Markus Jarderot (https://stackoverflow.com/questions/198431/how-do-you-compare-two-version-strings-in-java)
15 | */
16 | public class VersionTokenizer {
17 | private final String _versionString;
18 | private final int _length;
19 |
20 | private int _position;
21 | private int _number;
22 | private String _suffix;
23 | private boolean _hasValue;
24 |
25 | public VersionTokenizer(String versionString) {
26 | if (versionString == null)
27 | throw new IllegalArgumentException("versionString is null");
28 |
29 | _versionString = versionString;
30 | _length = versionString.length();
31 | }
32 |
33 | public int getNumber() {
34 | return _number;
35 | }
36 |
37 | public String getSuffix() {
38 | return _suffix;
39 | }
40 |
41 | public boolean hasValue() {
42 | return _hasValue;
43 | }
44 |
45 | public boolean MoveNext() {
46 | _number = 0;
47 | _suffix = "";
48 | _hasValue = false;
49 |
50 | // No more characters
51 | if (_position >= _length)
52 | return false;
53 |
54 | _hasValue = true;
55 |
56 | while (_position < _length) {
57 | char c = _versionString.charAt(_position);
58 | if (c < '0' || c > '9') break;
59 | _number = _number * 10 + (c - '0');
60 | _position++;
61 | }
62 |
63 | int suffixStart = _position;
64 |
65 | while (_position < _length) {
66 | char c = _versionString.charAt(_position);
67 | if (c == '.') break;
68 | _position++;
69 | }
70 |
71 | _suffix = _versionString.substring(suffixStart, _position);
72 |
73 | if (_position < _length) _position++;
74 |
75 | return true;
76 | }
77 | }
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/scheduler/ScheduledRunnable.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.scheduler;
12 |
13 | public interface ScheduledRunnable {
14 |
15 | /**
16 | * @return Returns true if the thread is ready to exit
17 | */
18 | boolean runTick();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/scheduler/Scheduler.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.scheduler;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | public class Scheduler {
17 | private final List runningThreads = new ArrayList<>();
18 | private ScheduledRunnable runnable;
19 |
20 | public Scheduler(ScheduledRunnable runnable) {
21 | this.runnable = runnable;
22 | }
23 |
24 |
25 | public void run(int threads) {
26 | for (int i = 0; i < threads; i++) {
27 | runningThreads.add(new Thread(() -> {
28 | while (true) {
29 | if (runnable.runTick()) break;
30 | }
31 |
32 | synchronized (runningThreads) {
33 | runningThreads.remove(Thread.currentThread());
34 | }
35 | }, "Thread-" + i));
36 | }
37 |
38 | synchronized (runningThreads) {
39 | runningThreads.forEach(Thread::start);
40 | }
41 | }
42 |
43 | public void waitFor() {
44 | while (true) {
45 | synchronized (runningThreads) {
46 | runningThreads.removeIf(thread -> !thread.isAlive());
47 |
48 | if (runningThreads.size() == 0) break;
49 | }
50 |
51 | try {
52 | Thread.sleep(100);
53 | } catch (InterruptedException e) {
54 | break;
55 | }
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/script/JObfScript.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.script;
12 |
13 | import org.objectweb.asm.tree.ClassNode;
14 |
15 | import javax.script.Invocable;
16 | import javax.script.ScriptEngine;
17 | import javax.script.ScriptEngineManager;
18 | import javax.script.ScriptException;
19 |
20 | public class JObfScript {
21 |
22 | private ScriptEngine jsEngine;
23 |
24 | public JObfScript(String script) {
25 | try {
26 | jsEngine = new ScriptEngineManager().getEngineByName("nashorn");
27 | jsEngine.eval(script);
28 | } catch (Exception e) {
29 | throw new IllegalStateException("Failed to compile Script", e);
30 | }
31 | }
32 |
33 | public boolean remapClass(ClassNode node) {
34 | try {
35 | Invocable invocable = (Invocable) jsEngine;
36 |
37 | return (boolean) invocable.invokeFunction("isRemappingEnabledForClass", node);
38 | } catch (NoSuchMethodException e) {
39 | return true;
40 | } catch (ScriptException e) {
41 | e.printStackTrace();
42 | return true;
43 | }
44 | }
45 |
46 | public boolean isObfuscatorEnabled(ClassNode node) {
47 | try {
48 | Invocable invocable = (Invocable) jsEngine;
49 |
50 | return (boolean) invocable.invokeFunction("isObfuscatorEnabledForClass", node);
51 | } catch (NoSuchMethodException e) {
52 | return true;
53 | } catch (ScriptException e) {
54 | e.printStackTrace();
55 | return true;
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/script/JObfScriptManager.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.script;
12 |
13 | import javax.script.*;
14 |
15 | public class JObfScriptManager {
16 |
17 | public static void main(String[] args) {
18 | try {
19 | ScriptEngine jsEngine = new ScriptEngineManager().getEngineByName("nashorn");
20 | ScriptContext context = jsEngine.getContext();
21 | jsEngine.eval("function isNameObfEnabled(className) {\n" +
22 | " if (!className.contains('x')) {\n" +
23 | " print('I will obfuscate ' + className);\n" +
24 | " return true;\n" +
25 | " }\n" +
26 | " return false;\n" +
27 | "}");
28 | Invocable inv = (Invocable) jsEngine;
29 | try {
30 | System.out.println(inv.invokeFunction("isNameObfEnabled", "avg"));
31 | System.out.println(inv.invokeFunction("isNameObfEnabled", "xxx"));
32 | } catch (NoSuchMethodException e) {
33 | e.printStackTrace();
34 | }
35 | } catch (ScriptException e) {
36 | e.printStackTrace();
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/BooleanValue.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.values;
12 |
13 | public class BooleanValue extends Value {
14 |
15 | public BooleanValue(String owner, String name, DeprecationLevel deprecation, Boolean object) {
16 | super(owner, name, deprecation, object);
17 | }
18 |
19 | public BooleanValue(String owner, String name, String description, DeprecationLevel deprecation, Boolean object) {
20 | super(owner, name, description, deprecation, object);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/Configuration.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.values;
12 |
13 | import com.google.gson.JsonArray;
14 | import com.google.gson.JsonElement;
15 | import com.google.gson.JsonObject;
16 | import com.google.gson.JsonPrimitive;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | public class Configuration {
22 | private String input;
23 | private String output;
24 | private String script;
25 | private List libraries;
26 |
27 | public Configuration(String input, String output, String script, List libraries) {
28 | this.input = input;
29 | this.output = output;
30 | this.script = script;
31 | this.libraries = libraries;
32 | }
33 |
34 | static Configuration fromJsonObject(JsonObject obj) {
35 | String input = "";
36 | String output = "";
37 | String script = null;
38 | List libraries = new ArrayList<>();
39 |
40 | if (obj.has("input")) {
41 | input = obj.get("input").getAsString();
42 | }
43 | if (obj.has("output")) {
44 | output = obj.get("output").getAsString();
45 | }
46 | if (obj.has("script")) {
47 | script = obj.get("script").getAsString();
48 | }
49 | if (obj.has("libraries")) {
50 | JsonArray jsonArray = obj.getAsJsonArray("libraries");
51 |
52 | for (JsonElement jsonElement : jsonArray) {
53 | libraries.add(jsonElement.getAsString());
54 | }
55 | }
56 |
57 | return new Configuration(input, output, script, libraries);
58 | }
59 |
60 | void addToJsonObject(JsonObject jsonObject) {
61 | jsonObject.addProperty("input", input);
62 | jsonObject.addProperty("output", output);
63 | jsonObject.addProperty("script", script);
64 |
65 | JsonArray array = new JsonArray();
66 |
67 | for (String library : libraries) {
68 | array.add(new JsonPrimitive(library));
69 | }
70 |
71 | jsonObject.add("libraries", array);
72 | }
73 |
74 | public String getInput() {
75 | return input;
76 | }
77 |
78 | public void setInput(String input) {
79 | this.input = input;
80 | }
81 |
82 | public String getOutput() {
83 | return output;
84 | }
85 |
86 | public void setOutput(String output) {
87 | this.output = output;
88 | }
89 |
90 | public String getScript() {
91 | return script;
92 | }
93 |
94 | public void setScript(String script) {
95 | this.script = script;
96 | }
97 |
98 | public List getLibraries() {
99 | return libraries;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/DeprecationLevel.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.values;
12 |
13 | public enum DeprecationLevel {
14 | GOOD, OK, BAD
15 | }
16 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/EnabledValue.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.values;
12 |
13 | public class EnabledValue extends BooleanValue {
14 |
15 | public EnabledValue(String owner, DeprecationLevel deprecated, Boolean object) {
16 | super(owner, "Enabled", deprecated, object);
17 | }
18 |
19 | public EnabledValue(String owner, String description, DeprecationLevel deprecation, Boolean object) {
20 | super(owner, "Enabled", description, deprecation, object);
21 | }
22 |
23 | @Override
24 | public String toString() {
25 | return String.format("%s = %s", getOwner(), getObject());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/FilePathValue.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.values;
12 |
13 | public class FilePathValue extends StringValue {
14 | public FilePathValue(String owner, String name, DeprecationLevel deprecated, String object) {
15 | super(owner, name, deprecated, object);
16 | }
17 |
18 | public FilePathValue(String owner, String name, String description, DeprecationLevel deprecation, String object) {
19 | super(owner, name, description, deprecation, object, 1);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/ModeValue.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.values;
12 |
13 | import joptsimple.internal.Strings;
14 |
15 | public class ModeValue extends Value {
16 | private String[] possibleValues;
17 |
18 | public ModeValue(String owner, String name, DeprecationLevel deprecated, Integer object, String[] possibleValues) {
19 | super(owner, name, deprecated, object);
20 | this.possibleValues = possibleValues;
21 | }
22 |
23 | public ModeValue(String owner, String name, String description, DeprecationLevel deprecated, Integer object, String[] possibleValues) {
24 | super(owner, name, description, deprecated, object);
25 | this.possibleValues = possibleValues;
26 | }
27 |
28 |
29 | private String[] getPossibleValues() {
30 | return possibleValues;
31 | }
32 |
33 |
34 | @Override
35 | public String toString() {
36 | return String.format("%s::%s<%s> = %s", getOwner(), getName(), Strings.join(getPossibleValues(), ", "), getObject());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/NumberValue.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.values;
12 |
13 | public class NumberValue extends Value {
14 |
15 | public NumberValue(String owner, String name, String description, DeprecationLevel deprecated, T object) {
16 | super(owner, name, description, deprecated, object);
17 | }
18 | public NumberValue(String owner, String name, DeprecationLevel deprecated, T object) {
19 | super(owner, name, deprecated, object);
20 | }
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/StringValue.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.values;
12 |
13 | public class StringValue extends Value {
14 | private int textFieldLines;
15 |
16 | public StringValue(String owner, String name, DeprecationLevel deprecated, String object) {
17 | super(owner, name, deprecated, object);
18 | this.textFieldLines = 1;
19 | }
20 |
21 | public StringValue(String owner, String name, String description, DeprecationLevel deprecation, String object, int textFieldLines) {
22 | super(owner, name, description, deprecation, object);
23 | this.textFieldLines = textFieldLines;
24 | }
25 |
26 | public int getTextFieldLines() {
27 | return textFieldLines;
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return String.format("%s::%s = \"%s\"", getOwner(), getName(), getObject());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/Value.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.values;
12 |
13 | public abstract class Value {
14 | private String owner;
15 | private String name;
16 | private String description;
17 | private T object;
18 | private DeprecationLevel deprecation;
19 |
20 | public Value(String owner, String name, DeprecationLevel deprecation, T object) {
21 | this(owner, name, "", deprecation, object);
22 | }
23 |
24 | public Value(String owner, String name, String description, DeprecationLevel deprecation, T object) {
25 | this.owner = owner;
26 | this.name = name;
27 | this.description = description;
28 | this.deprecation = deprecation;
29 | this.object = object;
30 | }
31 |
32 | public String getOwner() {
33 | return owner;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public T getObject() {
41 | return object;
42 | }
43 |
44 | public void setObject(T object) {
45 | this.object = object;
46 | }
47 |
48 | public DeprecationLevel getDeprecation() {
49 | return deprecation;
50 | }
51 |
52 | public String getDescription() {
53 | return description;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return String.format("%s::%s = %s", owner, name, object);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/me/superblaubeere27/jobf/utils/values/ValueManager.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.values;
12 |
13 | import java.lang.reflect.Field;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | public class ValueManager {
18 | private static List> values = new ArrayList<>();
19 |
20 | private static void registerField(Field field, Object object) {
21 | field.setAccessible(true);
22 |
23 | try {
24 | Object obj = field.get(object);
25 |
26 | if (obj instanceof Value) {
27 | Value value = (Value) obj;
28 | values.add(value);
29 | }
30 | } catch (IllegalAccessException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 |
35 | public static void registerClass(Object obj) {
36 | Class> clazz = obj.getClass();
37 |
38 | for (Field field : clazz.getFields()) {
39 | registerField(field, obj);
40 | }
41 | for (Field field : clazz.getDeclaredFields()) {
42 | registerField(field, obj);
43 | }
44 |
45 | }
46 |
47 | public static List> getValues() {
48 | return values;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/java/org/objectweb/asm/ModifiedClassWriter.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 | package org.objectweb.asm;
11 |
12 |
13 | import me.superblaubeere27.jobf.ObfuscatorClassLoader;
14 |
15 | /**
16 | * A {@link ClassVisitor} that generates a corresponding ClassFile structure, as defined in the Java
17 | * Virtual Machine Specification (JVMS). It can be used alone, to generate a Java class "from
18 | * scratch", or with one or more {@link ClassReader} and adapter {@link ClassVisitor} to generate a
19 | * modified class from one or more existing Java classes.
20 | *
21 | * @author Eric Bruneton
22 | * @see JVMS 4
23 | */
24 | public class ModifiedClassWriter extends ClassWriter {
25 |
26 | public ModifiedClassWriter(int flags) {
27 | super(flags);
28 | }
29 |
30 | public ModifiedClassWriter(ClassReader classReader, int flags) {
31 | super(classReader, flags);
32 | }
33 |
34 | @Override
35 | protected ClassLoader getClassLoader() {
36 | return ObfuscatorClassLoader.INSTANCE;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
13 |
14 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
31 |
32 |
33 |
34 | 1000
35 |
36 |
37 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/obfuscator-core/src/main/resources/strings.properties:
--------------------------------------------------------------------------------
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 | browse=&Browse
12 | class.options=Class Options
13 | enabled=&Enabled
14 | input=Input:
15 | input.output=Input / Output
16 | log=Log
17 | obfuscate=Obfuscate
18 | output=Output:
--------------------------------------------------------------------------------
/obfuscator-core/src/main/resources/templates/Aggressive.json:
--------------------------------------------------------------------------------
1 | {
2 | "ShuffleMembers": {
3 | "Enabled": true
4 | },
5 | "InvokeDynamic": {
6 | "Enabled": true
7 | },
8 | "LineNumberRemover": {
9 | "Enabled": true,
10 | "Rename local variables": true,
11 | "Remove Line Numbers": true,
12 | "Remove Debug Names": true,
13 | "Add Local Variables": true
14 | },
15 | "FlowObfuscator": {
16 | "Enabled": true,
17 | "Replace GOTO": true,
18 | "Replace If": true,
19 | "Bad POP": true
20 | },
21 | "HideMembers": {
22 | "Enabled": true
23 | },
24 | "StringEncryption": {
25 | "Enabled": true,
26 | "HideStrings": true
27 | },
28 | "NumberObfuscation": {
29 | "Enabled": true,
30 | "Extract to Array": true,
31 | "Obfuscate Zero": true,
32 | "Shift": true,
33 | "And": true,
34 | "Multiple Instructions": true
35 | }
36 | }
--------------------------------------------------------------------------------
/obfuscator-core/src/main/resources/templates/MixIn.json:
--------------------------------------------------------------------------------
1 | {
2 | "script": "function isRemappingEnabledForClass(node) {\n return false;\n}\nfunction isObfuscatorEnabledForClass(node) {\n\tvar flag \u003d false;\n\n\tif (node.superName.contains(\"IFMLLoadingPlugin\")) {\n\t\tflag \u003d true;\n\t}\n\n\tfor (i \u003d 0; i \u003c node.methods.length; i++) {\n\t\tvar method \u003d node.methods[i];\n\n\t\tif (method.visibleAnnotations !\u003d null) {\n\t\t\tfor (j \u003d 0; j \u003c method.visibleAnnotations.length; j++) {\n\t\t\t\tvar annotation \u003d method.visibleAnnotations[j];\n\t\t\t\t//print(\"ANNOTATION: \" + annotation.desc)\n\t\t\t\t\n\t\t\t\tif (annotation !\u003d null) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (annotation.desc.contains(\"injection\") \u0026\u0026 annotation.desc.contains(\"spongepowered\")) {\n\t\t\t\t\t\t\tflag \u003d true;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n \treturn !flag \u0026\u0026 !node.name.contains(\"spongepowered\") \u0026\u0026 !node.name.contains(\"springframework\");\n}",
3 | "ReferenceProxy": {
4 | "Enabled": false
5 | },
6 | "InvokeDynamic": {
7 | "Enabled": false
8 | },
9 | "Packager": {
10 | "Enabled": false
11 | },
12 | "HideMembers": {
13 | "Enabled": true
14 | },
15 | "NumberObfuscation": {
16 | "Enabled": true,
17 | "Extract to Array": true,
18 | "Obfuscate Zero": true,
19 | "Multiple Instructions": true
20 | }
21 | }
--------------------------------------------------------------------------------
/obfuscator-core/src/main/resources/theme.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/FormatTest.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 | public class FormatTest {
12 |
13 | public static void main(String[] args) {
14 | System.out.println(String.format("Number: %s%n", Integer.toHexString(10).toLowerCase()));
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/me/superblaubeere27/CipherTest.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;
12 |
13 | import me.superblaubeere27.jobf.processors.encryption.string.AESEncryptionAlgorithm;
14 | import me.superblaubeere27.jobf.processors.encryption.string.BlowfishEncryptionAlgorithm;
15 | import me.superblaubeere27.jobf.processors.encryption.string.DESEncryptionAlgorithm;
16 | import me.superblaubeere27.jobf.processors.encryption.string.XOREncryptionAlgorithm;
17 | import org.junit.Test;
18 |
19 | import static org.junit.Assert.assertEquals;
20 |
21 | public class CipherTest {
22 |
23 | @Test
24 | public void testDES() {
25 | String encrypt = "Encryption works.";
26 | String key = "123456 is a safe key";
27 |
28 | DESEncryptionAlgorithm algorithm = new DESEncryptionAlgorithm();
29 |
30 | String enc = algorithm.encrypt(encrypt, key);
31 |
32 |
33 | assertEquals(encrypt, DESEncryptionAlgorithm.decrypt(enc, key));
34 | }
35 |
36 |
37 | @Test
38 | public void testXOR() {
39 | String encrypt = "Encryption works.";
40 | String key = "123456 is a safe key";
41 |
42 | XOREncryptionAlgorithm algorithm = new XOREncryptionAlgorithm();
43 |
44 | String enc = algorithm.encrypt(encrypt, key);
45 |
46 |
47 | assertEquals(encrypt, XOREncryptionAlgorithm.decrypt(enc, key));
48 | }
49 |
50 | @Test
51 | public void testAES() {
52 | String encrypt = "Encryption works.";
53 | String key = "123456 is a safe key";
54 |
55 | AESEncryptionAlgorithm algorithm = new AESEncryptionAlgorithm();
56 |
57 | String enc = algorithm.encrypt(encrypt, key);
58 |
59 | assertEquals(encrypt, AESEncryptionAlgorithm.decrypt(enc, key));
60 | }
61 |
62 | @Test
63 | public void testBlowfish() {
64 | String encrypt = "Encryption works.";
65 | String key = "123456 is a safe key";
66 |
67 | BlowfishEncryptionAlgorithm algorithm = new BlowfishEncryptionAlgorithm();
68 |
69 | String enc = algorithm.encrypt(encrypt, key);
70 |
71 | assertEquals(encrypt, BlowfishEncryptionAlgorithm.decrypt(enc, key));
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/me/superblaubeere27/JumpTest.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;
12 |
13 | import com.google.common.io.Files;
14 | import me.superblaubeere27.jobf.JObfImpl;
15 | import me.superblaubeere27.jobf.processors.flowObfuscation.FlowObfuscator;
16 | import org.junit.Before;
17 | import org.junit.Test;
18 | import org.objectweb.asm.Label;
19 | import org.objectweb.asm.ModifiedClassWriter;
20 | import org.objectweb.asm.Opcodes;
21 | import org.objectweb.asm.tree.*;
22 |
23 | import java.io.File;
24 | import java.io.IOException;
25 | import java.lang.reflect.InvocationTargetException;
26 | import java.lang.reflect.Method;
27 |
28 | public class JumpTest {
29 | private Class> generatedClass = null;
30 |
31 | @Before
32 | public void generateClass() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, IOException {
33 | Class.forName(JObfImpl.class.getCanonicalName());
34 | InsnList methodInsns = new InsnList();
35 |
36 | ClassNode classNode = new ClassNode();
37 | classNode.name = "Test";
38 | classNode.access = Opcodes.ACC_PUBLIC;
39 | classNode.version = 52;
40 | classNode.superName = "java/lang/Object";
41 |
42 | MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "test", "()V", null, new String[0]);
43 |
44 | for (int i1 = 0; i1 < 10; i1++) {
45 | for (int i = 0; i <= 13; i++) {
46 | LabelNode end = new LabelNode(new Label());
47 | methodInsns.add(FlowObfuscator.generateIfGoto(i, end));
48 | methodInsns.add(new TypeInsnNode(Opcodes.NEW, "java/lang/RuntimeException"));
49 | methodInsns.add(new InsnNode(Opcodes.DUP));
50 | methodInsns.add(new LdcInsnNode("JumpGenerator row=" + i1 + " id=" + i + " failed"));
51 | methodInsns.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "", "(Ljava/lang/String;)V", false));
52 | methodInsns.add(new InsnNode(Opcodes.ATHROW));
53 | methodInsns.add(end);
54 | // methodInsns.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
55 | }
56 | }
57 | methodInsns.add(new InsnNode(Opcodes.RETURN));
58 |
59 |
60 | methodNode.instructions = methodInsns;
61 | methodNode.visitEnd();
62 |
63 |
64 | classNode.methods.add(methodNode);
65 |
66 | ModifiedClassWriter writer = new ModifiedClassWriter(ModifiedClassWriter.COMPUTE_FRAMES);
67 |
68 | classNode.accept(writer);
69 |
70 | writer.visitEnd();
71 |
72 | byte[] bytes = writer.toByteArray();
73 |
74 | Files.write(bytes, File.createTempFile("JumpTestClass", ".class"));
75 |
76 | Class> classLoaderClass = ClassLoader.class;
77 |
78 | Method defineClass = classLoaderClass.getDeclaredMethod("defineClass", byte[].class, int.class, int.class);
79 | defineClass.setAccessible(true);
80 |
81 | generatedClass = (Class) defineClass.invoke(getClass().getClassLoader(), bytes, 0, bytes.length);
82 | }
83 |
84 | @Test
85 | public void testFlowJumps() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
86 | generatedClass.getMethod("test").invoke(null);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/me/superblaubeere27/NodeUtilsTest.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;
12 |
13 | import me.superblaubeere27.jobf.utils.NameUtils;
14 | import me.superblaubeere27.jobf.utils.NodeUtils;
15 | import org.junit.Test;
16 | import org.objectweb.asm.Opcodes;
17 | import org.objectweb.asm.Type;
18 | import org.objectweb.asm.tree.AbstractInsnNode;
19 | import org.objectweb.asm.tree.MethodInsnNode;
20 |
21 | import static org.junit.Assert.assertEquals;
22 | import static org.junit.Assert.fail;
23 |
24 | public class NodeUtilsTest {
25 | @Test
26 | public void test_getPackage() {
27 | assertEquals(NameUtils.getPackage("className"), "");
28 | assertEquals(NameUtils.getPackage("package1/className"), "package1");
29 | assertEquals(NameUtils.getPackage("package1/package2/className"), "package1/package2");
30 |
31 | try {
32 | NameUtils.getPackage("/className");
33 | fail();
34 | } catch (Exception ignored) {
35 | }
36 | }
37 |
38 | @Test
39 | public void test_getWrapperMethod() {
40 | AbstractInsnNode wrapperMethod = NodeUtils.getWrapperMethod(Type.INT_TYPE);
41 |
42 | if (wrapperMethod instanceof MethodInsnNode) {
43 | MethodInsnNode method = (MethodInsnNode) wrapperMethod;
44 | assertEquals("valueOf", method.name);
45 | assertEquals(method.desc, "(I)Ljava/lang/Integer;");
46 | assertEquals(method.owner, "java/lang/Integer");
47 | } else {
48 | fail();
49 | }
50 |
51 | assertEquals(NodeUtils.getWrapperMethod(Type.VOID_TYPE).getOpcode(), Opcodes.NOP);
52 | assertEquals(NodeUtils.getWrapperMethod(Type.getType("Ljava/lang/Object;")).getOpcode(), Opcodes.NOP);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/me/superblaubeere27/ObfuscatorTest.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;
12 |
13 | import com.google.common.io.ByteStreams;
14 | import me.superblaubeere27.jobf.JObfImpl;
15 | import me.superblaubeere27.jobf.utils.values.ConfigManager;
16 | import me.superblaubeere27.jobf.utils.values.Configuration;
17 | import org.junit.AfterClass;
18 | import org.junit.BeforeClass;
19 | import org.junit.Test;
20 |
21 | import java.io.File;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.lang.reflect.InvocationTargetException;
25 | import java.net.URL;
26 | import java.net.URLClassLoader;
27 | import java.nio.charset.StandardCharsets;
28 | import java.util.Enumeration;
29 | import java.util.jar.JarEntry;
30 | import java.util.jar.JarFile;
31 |
32 | import static org.junit.Assert.*;
33 |
34 | public class ObfuscatorTest {
35 | private static File obfuscatedFile = null;
36 | private static File input;
37 |
38 | @BeforeClass
39 | public static void obfuscate() {
40 | try {
41 | input = File.createTempFile("obf_", ".jar");
42 | // Files.copy(new URL("https://github.com/SB27Team/JavaFeatureTest/raw/master/JavaFeatureTest.jar").openStream(), input.toPath());
43 | ByteStreams.copy(new URL("https://github.com/SB27Team/JavaFeatureTest/raw/master/JavaFeatureTest.jar").openStream(), new FileOutputStream(input));
44 | // impl.addProcessors();
45 |
46 | Configuration configuration = ConfigManager.loadConfig(new String(ByteStreams.toByteArray(ObfuscatorTest.class.getResourceAsStream("/config.jocfg")), StandardCharsets.UTF_8));
47 |
48 | configuration.setInput(input.getAbsolutePath());
49 | configuration.setOutput((obfuscatedFile = File.createTempFile("obf_", ".jar")).getAbsolutePath());
50 |
51 | JObfImpl.INSTANCE.processJar(configuration);
52 | } catch (IOException e) {
53 | e.printStackTrace();
54 | }
55 | }
56 |
57 | @AfterClass
58 | public static void removeFile() {
59 | if (obfuscatedFile != null && obfuscatedFile.exists()) {
60 | obfuscatedFile.delete();
61 | }
62 | if (input != null && input.exists()) {
63 | input.delete();
64 | }
65 | }
66 |
67 | @Test
68 | public void verifyFile() {
69 | assertNotNull(obfuscatedFile);
70 | assertTrue("File doesn't exist", obfuscatedFile.exists());
71 | }
72 |
73 | @Test
74 | public void testObfuscatedJar() throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
75 | int rightValue = 704643072;
76 | JarFile jarFile = new JarFile(obfuscatedFile);
77 | Enumeration e = jarFile.entries();
78 |
79 | URL[] urls = {new URL("jar:file:" + obfuscatedFile.getAbsolutePath() + "!/")};
80 | URLClassLoader cl = URLClassLoader.newInstance(urls);
81 | Class> c = null;
82 |
83 | while (e.hasMoreElements()) {
84 | JarEntry je = e.nextElement();
85 | if (je.isDirectory() || !je.getName().endsWith(".class")) {
86 | continue;
87 | }
88 | // -6 because of .class
89 | String className = je.getName().substring(0, je.getName().length() - 6);
90 | className = className.replace('/', '.');
91 | if (className.equals("JFT")) {
92 | c = cl.loadClass(className);
93 | }
94 | }
95 |
96 | if (c == null) {
97 | fail("JFT.class wasn't found");
98 | }
99 |
100 | assertEquals(((int) c.getMethod("test").invoke(null)), rightValue);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/me/superblaubeere27/Test.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;
12 |
13 | import java.lang.invoke.*;
14 |
15 | public class Test {
16 | private static String[] references;
17 | private static Class[] types;
18 |
19 | static {
20 | references = new String[]{"Test:a:0: "};
21 | types = new Class[]{String[].class};
22 | }
23 |
24 | public static void main(String[] args) {
25 | System.out.println();
26 | }
27 |
28 | private static CallSite bootstrap(final MethodHandles.Lookup lookup, final String s, final MethodType methodType) throws NoSuchMethodException, IllegalAccessException {
29 | try {
30 | final String[] split = Test.references[Integer.parseInt(s)].split(":");
31 | final Class> classIn = Class.forName(split[0]);
32 | final String name = split[1];
33 | MethodHandle methodHandle;
34 |
35 | int length = split[3].length();
36 |
37 | if (length <= 2) {
38 | final MethodType methodDesc = MethodType.fromMethodDescriptorString(split[2], Test.class.getClassLoader());
39 |
40 | if (length == 2) {
41 | methodHandle = lookup.findVirtual(classIn, name, methodDesc);
42 | } else {
43 | methodHandle = lookup.findStatic(classIn, name, methodDesc);
44 | }
45 | } else {
46 | Class typeLookup = types[Integer.parseInt(split[2])];
47 |
48 | if (length == 3) {
49 | methodHandle = lookup.findGetter(classIn, name, typeLookup);
50 | } else if (length == 4) {
51 | methodHandle = lookup.findStaticGetter(classIn, name, typeLookup);
52 | } else if (length == 5) {
53 | methodHandle = lookup.findSetter(classIn, name, typeLookup);
54 | } else {
55 | methodHandle = lookup.findStaticSetter(classIn, name, typeLookup);
56 | }
57 | }
58 |
59 | return new ConstantCallSite(methodHandle);
60 | } catch (Exception ex) {
61 | ex.printStackTrace();
62 | return null;
63 | }
64 | }
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/obfuscator-core/src/test/java/me/superblaubeere27/jobf/processors/optimizer/InsertedMethodsTest.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 org.junit.Test;
14 |
15 | import static org.junit.Assert.assertFalse;
16 | import static org.junit.Assert.assertTrue;
17 |
18 | public class InsertedMethodsTest {
19 |
20 | @Test
21 | public void testStartsWith() {
22 | assertTrue(InsertedMethods.startsWith("ich hasse Menschen", "ich hasse ".length(), "ich hasse ".hashCode()));
23 | assertTrue(InsertedMethods.startsWith("ich hasse ", "ich hasse ".length(), "ich hasse ".hashCode()));
24 | assertFalse(InsertedMethods.startsWith("cancer", "aids".length(), "aids".hashCode()));
25 | }
26 |
27 | @Test
28 | public void testEndsWith() {
29 | assertTrue(InsertedMethods.endsWith("ich hasse Menschen", "Menschen".length(), "Menschen".hashCode()));
30 | assertTrue(InsertedMethods.endsWith("hasse", "hasse".length(), "hasse".hashCode()));
31 | assertFalse(InsertedMethods.endsWith("cancer", "aidsfgd".length(), "aidsfgd".hashCode()));
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/obfuscator-core/src/test/resources/config.jocfg:
--------------------------------------------------------------------------------
1 | {
2 | "Crasher": {
3 | "Enabled": false
4 | },
5 | "InvokeDynamic": {
6 | "Enabled": true
7 | },
8 | "HWIDPRotection": {
9 | "Enabled": false
10 | },
11 | "LineNumberRemover": {
12 | "Enabled": true,
13 | "Rename local variables": true,
14 | "Remove Line Numbers": true,
15 | "Remove Debug Names": true,
16 | "Add Local Variables": true,
17 | "New SourceFile Name": ""
18 | },
19 | "StringEncryption": {
20 | "Enabled": true,
21 | "HideStrings": true,
22 | "AES": false
23 | },
24 | "NumberObfuscation": {
25 | "Enabled": true,
26 | "Extract to Array": true,
27 | "Obfuscate Zero": true,
28 | "Shift": true,
29 | "And": true,
30 | "Multiple Instructions": true
31 | },
32 | "ReferenceProxy": {
33 | "Enabled": false
34 | },
35 | "PeepholeOptimizer": {
36 | "Enabled": false,
37 | "Experimental Pop folding": false
38 | },
39 | "ShuffleMembers": {
40 | "Enabled": true
41 | },
42 | "InnerClassRemover": {
43 | "Enabled": true,
44 | "Remap": false,
45 | "Remove Metadata": true
46 | },
47 | "NameObfuscation": {
48 | "Enabled": false
49 | },
50 | "Packager": {
51 | "Enabled": false,
52 | "Use MainClass from the JAR manifest": true,
53 | "Main class": "org.example.Main"
54 | },
55 | "FlowObfuscator": {
56 | "Enabled": true,
57 | "Mangle Switches": true,
58 | "Mangle Return": false,
59 | "Replace GOTO": true,
60 | "Replace If": true,
61 | "Bad POP": true,
62 | "Bad Concat": true,
63 | "Mangle Local Variables": true
64 | },
65 | "HideMembers": {
66 | "Enabled": true
67 | },
68 | "Inlining": {
69 | "Enabled": false
70 | }
71 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
14 | 4.0.0
15 |
16 | me.superblaubeere27
17 | obfuscator
18 | 1.9.3-SNAPSHOT
19 | pom
20 |
21 |
22 | UTF-8
23 | 1.8
24 | 1.8
25 | 7.0
26 |
27 |
28 |
29 | obfuscator-annotations
30 | obfuscator-core
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | function isRemappingEnabledForClass(name) {
2 | return false;
3 | }
4 | function isObfuscatorEnabledForClass(name) {
5 | return true;
6 | }
--------------------------------------------------------------------------------
/version:
--------------------------------------------------------------------------------
1 | 1.9.3
2 |
--------------------------------------------------------------------------------
/watermark/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 | watermark
9 |
10 |
11 |
12 | org.apache.maven.plugins
13 | maven-compiler-plugin
14 |
15 | 1.8
16 | 1.8
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | me.superblaubeere27
25 | obfuscator
26 | 1.7
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/watermark/src/main/java/me/superblaubeere27/obfuscator/watermark/Config.java:
--------------------------------------------------------------------------------
1 | package me.superblaubeere27.obfuscator.watermark;
2 |
3 | import com.google.gson.JsonObject;
4 |
5 | import java.util.Random;
6 |
7 | public class Config {
8 | private static final Random random = new Random();
9 |
10 | private final String key;
11 | private final String magicBytes;
12 |
13 | public Config(String key, String magicBytes) {
14 | this.key = key;
15 | this.magicBytes = magicBytes;
16 | }
17 |
18 | public static Config generateConfig() {
19 | return new Config(randomString(random.nextInt(80) + 50), randomString(random.nextInt(5) + 1));
20 | }
21 |
22 | public static Config fromJson(JsonObject object) {
23 | if (!object.has("key")) throw new IllegalArgumentException("JsonObject hasn't 'key'");
24 | if (!object.has("magicBytes")) throw new IllegalArgumentException("JsonObject hasn't 'magicBytes'");
25 |
26 | return new Config(object.get("key").getAsString(), object.get("magicBytes").getAsString());
27 | }
28 |
29 | private static String randomString(int i) {
30 | StringBuilder sb = new StringBuilder();
31 |
32 | for (int i1 = 0; i1 < i; i1++) {
33 | sb.append((char) (random.nextInt(126 - 32) + 32));
34 | }
35 |
36 | return sb.toString();
37 | }
38 |
39 | public JsonObject toJsonObject() {
40 | JsonObject obj = new JsonObject();
41 |
42 | obj.addProperty("key", key);
43 | obj.addProperty("magicBytes", magicBytes);
44 |
45 | return obj;
46 | }
47 |
48 | public String getKey() {
49 | return key;
50 | }
51 |
52 | public String getMagicBytes() {
53 | return magicBytes;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return "Config{" +
59 | "key='" + key + '\'' +
60 | ", magicBytes='" + magicBytes + '\'' +
61 | '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/watermark/src/main/java/me/superblaubeere27/obfuscator/watermark/Encryption.java:
--------------------------------------------------------------------------------
1 | package me.superblaubeere27.obfuscator.watermark;
2 |
3 | import javax.crypto.Cipher;
4 | import javax.crypto.spec.SecretKeySpec;
5 | import java.nio.charset.StandardCharsets;
6 | import java.security.MessageDigest;
7 | import java.util.Base64;
8 |
9 | public class Encryption {
10 |
11 | public static String decrypt(String obj, String key) {
12 | try {
13 | SecretKeySpec keySpec = new SecretKeySpec(MessageDigest.getInstance("SHA-256").digest(key.getBytes(StandardCharsets.UTF_8)), "AES");
14 |
15 | Cipher des = Cipher.getInstance("AES");
16 | des.init(Cipher.DECRYPT_MODE, keySpec);
17 |
18 | return new String(des.doFinal(Base64.getDecoder().decode(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8);
19 |
20 | } catch (Exception e) {
21 | e.printStackTrace();
22 | }
23 | return null;
24 | }
25 |
26 | public static String encrypt(String obj, String key) {
27 | try {
28 | SecretKeySpec keySpec = new SecretKeySpec(MessageDigest.getInstance("SHA-256").digest(key.getBytes(StandardCharsets.UTF_8)), "AES");
29 |
30 | Cipher des = Cipher.getInstance("AES");
31 | des.init(Cipher.ENCRYPT_MODE, keySpec);
32 |
33 | return new String(Base64.getEncoder().encode(des.doFinal(obj.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8);
34 |
35 | } catch (Exception e) {
36 | e.printStackTrace();
37 | }
38 | return null;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------