├── .editorconfig ├── .github └── workflows │ ├── continous-integration.yml │ └── pages.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── annotation ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── yworks │ └── util │ └── annotation │ └── Obfuscation.java ├── build.gradle ├── docs ├── 3rdPartyLicenses │ ├── ant-license.txt │ ├── asm-license.txt │ └── guava-license.txt ├── compatibility.md ├── img │ ├── dbvissplash.png │ ├── favicon.ico │ ├── yFiles-text.svg │ └── yguard-logo.svg ├── index.md ├── license-agreements │ ├── README.txt │ ├── mark-welsh.txt │ ├── peer.txt │ └── yworks.txt ├── license.md ├── setup.md ├── stylesheets │ └── extra.css ├── task_documentation.md └── troubleshooting.md ├── examples ├── README.md ├── annotation │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── yworks │ │ └── example │ │ ├── Company.java │ │ ├── Employee.java │ │ ├── Member.java │ │ ├── Organisation.java │ │ └── Person.java ├── application │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── yworks │ │ └── example │ │ └── HelloWorld.java ├── external_library │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── yworks │ │ └── example │ │ └── HelloWorld.java ├── fxml │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── yworks │ │ │ └── example │ │ │ ├── HelloWorld.java │ │ │ └── HelloWorldController.java │ │ └── resources │ │ └── com │ │ └── yworks │ │ └── example │ │ └── HelloWorld.fxml ├── library │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── yworks │ │ └── example │ │ ├── Functional.java │ │ ├── HelloWorld.java │ │ └── Reducible.java ├── processing │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── yworks │ │ │ └── example │ │ │ ├── HelloWorldApplication.java │ │ │ └── HelloWorldImpl.java │ │ └── resources │ │ └── application.properties ├── recipes │ ├── DEMO_PROGRAM.md │ ├── LINKED_LIBRARY.md │ └── README.md ├── resources │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── yworks │ │ │ └── example │ │ │ ├── HelloWorld.java │ │ │ └── PluginImpl.java │ │ └── resources │ │ └── com │ │ └── yworks │ │ └── example │ │ ├── HelloWorld.properties │ │ └── resources │ │ └── HelloWorldMessage.txt └── serializable_exclusion │ ├── README.md │ ├── build.gradle │ ├── build.xml │ ├── pom.xml │ ├── settings.gradle │ └── src │ └── main │ └── java │ └── com │ └── yworks │ └── example │ ├── HelloWorld.java │ ├── IoUtils.java │ ├── SerializableCollection.java │ └── SerializableItem.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mkdocs.yml ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── yworks │ │ ├── common │ │ ├── ResourcePolicy.java │ │ ├── ShrinkBag.java │ │ └── ant │ │ │ ├── AttributesSection.java │ │ │ ├── EntryPointJar.java │ │ │ ├── EntryPointsSection.java │ │ │ ├── Exclude.java │ │ │ ├── InOutPair.java │ │ │ ├── PatternMatchedSection.java │ │ │ ├── TypePatternSet.java │ │ │ ├── YGuardBaseTask.java │ │ │ └── ZipScannerTool.java │ │ ├── logging │ │ ├── ConsoleLogger.java │ │ ├── Logger.java │ │ └── XmlLogger.java │ │ ├── util │ │ ├── CollectionFilter.java │ │ ├── Filter.java │ │ ├── Version.java │ │ ├── abstractjar │ │ │ ├── Archive.java │ │ │ ├── ArchiveWriter.java │ │ │ ├── Entry.java │ │ │ ├── Factory.java │ │ │ ├── StreamProvider.java │ │ │ └── impl │ │ │ │ ├── DirectoryStreamProvider.java │ │ │ │ ├── DirectoryWrapper.java │ │ │ │ ├── DirectoryWriterImpl.java │ │ │ │ ├── FileEntryWrapper.java │ │ │ │ ├── JarEntryWrapper.java │ │ │ │ ├── JarFileWrapper.java │ │ │ │ ├── JarStreamProvider.java │ │ │ │ └── JarWriterImpl.java │ │ └── graph │ │ │ ├── DefaultNetwork.java │ │ │ ├── Edge.java │ │ │ ├── Network.java │ │ │ └── Node.java │ │ ├── yguard │ │ ├── Conversion.java │ │ ├── LogParserView.java │ │ ├── ObfuscationListener.java │ │ ├── ObfuscatorTask.java │ │ ├── ParseException.java │ │ ├── ResourceAdjusterUtils.java │ │ ├── StringReplacer.java │ │ ├── YGuardLogParser.java │ │ ├── YGuardTask.java │ │ ├── ant │ │ │ ├── AttributesSection.java │ │ │ ├── ClassSection.java │ │ │ ├── ExposeSection.java │ │ │ ├── FieldSection.java │ │ │ ├── LineNumberTableSection.java │ │ │ ├── MapParser.java │ │ │ ├── Mappable.java │ │ │ ├── MethodSection.java │ │ │ ├── PackageSection.java │ │ │ ├── PatternMatchedClassesSection.java │ │ │ ├── Property.java │ │ │ └── SourceFileSection.java │ │ ├── obf │ │ │ ├── Cl.java │ │ │ ├── ClassTree.java │ │ │ ├── Cons.java │ │ │ ├── Fd.java │ │ │ ├── Filter.java │ │ │ ├── GuardDB.java │ │ │ ├── KeywordNameMaker.java │ │ │ ├── LineNumberTableMapper.java │ │ │ ├── Md.java │ │ │ ├── MdFd.java │ │ │ ├── NameListDown.java │ │ │ ├── NameListUp.java │ │ │ ├── NameMaker.java │ │ │ ├── NameMakerFactory.java │ │ │ ├── NoSuchMappingException.java │ │ │ ├── ObfuscationConfig.java │ │ │ ├── Pk.java │ │ │ ├── PkCl.java │ │ │ ├── PlaceholderCl.java │ │ │ ├── ResourceHandler.java │ │ │ ├── Tools.java │ │ │ ├── TreeAction.java │ │ │ ├── TreeItem.java │ │ │ ├── Version.java │ │ │ ├── YGuardRule.java │ │ │ └── classfile │ │ │ │ ├── AbstractDynamicCpInfo.java │ │ │ │ ├── AbstractTypeCpInfo.java │ │ │ │ ├── AnnotationDefaultAttrInfo.java │ │ │ │ ├── AnnotationInfo.java │ │ │ │ ├── AttrInfo.java │ │ │ │ ├── BootstrapMethod.java │ │ │ │ ├── BootstrapMethodsAttrInfo.java │ │ │ │ ├── ClassConstants.java │ │ │ │ ├── ClassCpInfo.java │ │ │ │ ├── ClassFile.java │ │ │ │ ├── ClassItemInfo.java │ │ │ │ ├── CodeAttrInfo.java │ │ │ │ ├── ConstantPool.java │ │ │ │ ├── ConstantValueAttrInfo.java │ │ │ │ ├── CpInfo.java │ │ │ │ ├── DeprecatedAttrInfo.java │ │ │ │ ├── DoubleCpInfo.java │ │ │ │ ├── DynamicCpInfo.java │ │ │ │ ├── ElementValueInfo.java │ │ │ │ ├── ElementValuePairInfo.java │ │ │ │ ├── EnclosingMethodAttrInfo.java │ │ │ │ ├── ExceptionInfo.java │ │ │ │ ├── ExceptionsAttrInfo.java │ │ │ │ ├── FieldInfo.java │ │ │ │ ├── FieldrefCpInfo.java │ │ │ │ ├── FloatCpInfo.java │ │ │ │ ├── InnerClassesAttrInfo.java │ │ │ │ ├── InnerClassesInfo.java │ │ │ │ ├── IntegerCpInfo.java │ │ │ │ ├── InterfaceMethodrefCpInfo.java │ │ │ │ ├── InvokeDynamicCpInfo.java │ │ │ │ ├── LineNumberInfo.java │ │ │ │ ├── LineNumberTableAttrInfo.java │ │ │ │ ├── LocalVariableInfo.java │ │ │ │ ├── LocalVariableTableAttrInfo.java │ │ │ │ ├── LocalVariableTypeInfo.java │ │ │ │ ├── LocalVariableTypeTableAttrInfo.java │ │ │ │ ├── Logger.java │ │ │ │ ├── LongCpInfo.java │ │ │ │ ├── MethodHandleCpInfo.java │ │ │ │ ├── MethodInfo.java │ │ │ │ ├── MethodParameter.java │ │ │ │ ├── MethodParametersAttrInfo.java │ │ │ │ ├── MethodTypeCpInfo.java │ │ │ │ ├── MethodrefCpInfo.java │ │ │ │ ├── ModuleAttrInfo.java │ │ │ │ ├── ModuleCpInfo.java │ │ │ │ ├── ModuleExports.java │ │ │ │ ├── ModuleMainClassAttrInfo.java │ │ │ │ ├── ModuleOpens.java │ │ │ │ ├── ModulePackagesAttrInfo.java │ │ │ │ ├── ModuleProvides.java │ │ │ │ ├── ModuleRequires.java │ │ │ │ ├── NameAndTypeCpInfo.java │ │ │ │ ├── NameMapper.java │ │ │ │ ├── NestHostAttrInfo.java │ │ │ │ ├── NestMembersAttrInfo.java │ │ │ │ ├── PackageCpInfo.java │ │ │ │ ├── ParameterAnnotationInfo.java │ │ │ │ ├── PermittedSubclassesAttrInfo.java │ │ │ │ ├── RecordAttrInfo.java │ │ │ │ ├── RecordComponent.java │ │ │ │ ├── RefCpInfo.java │ │ │ │ ├── RuntimeInvisibleAnnotationsAttrInfo.java │ │ │ │ ├── RuntimeInvisibleParameterAnnotationsAttrInfo.java │ │ │ │ ├── RuntimeInvisibleTypeAnnotationsAttrInfo.java │ │ │ │ ├── RuntimeVisibleAnnotationsAttrInfo.java │ │ │ │ ├── RuntimeVisibleParameterAnnotationsAttrInfo.java │ │ │ │ ├── RuntimeVisibleTypeAnnotationsAttrInfo.java │ │ │ │ ├── SignatureAttrInfo.java │ │ │ │ ├── SourceFileAttrInfo.java │ │ │ │ ├── StackMapFrameInfo.java │ │ │ │ ├── StackMapTableAttrInfo.java │ │ │ │ ├── StringCpInfo.java │ │ │ │ ├── SyntheticAttrInfo.java │ │ │ │ ├── TypeAnnotationInfo.java │ │ │ │ ├── Utf8CpInfo.java │ │ │ │ └── VerificationTypeInfo.java │ │ └── yguard.properties │ │ └── yshrink │ │ ├── YShrink.java │ │ ├── YShrinkInvoker.java │ │ ├── YShrinkInvokerImpl.java │ │ ├── YShrinkModel.java │ │ ├── YShrinkModelImpl.java │ │ ├── ant │ │ ├── AntLogger.java │ │ ├── ClassSection.java │ │ ├── FieldSection.java │ │ ├── MethodSection.java │ │ ├── ResourceCpResolver.java │ │ ├── ShrinkTask.java │ │ └── filters │ │ │ ├── AbstractEntryPointFilter.java │ │ │ ├── AllMainMethodsFilter.java │ │ │ ├── AttributeFilter.java │ │ │ ├── ClassFilter.java │ │ │ ├── EntryPointFilter.java │ │ │ ├── EntryPointFilters.java │ │ │ ├── EntryPointJarFilter.java │ │ │ ├── FieldFilter.java │ │ │ ├── MethodFilter.java │ │ │ ├── PatternMatchedFilter.java │ │ │ └── SerializationFilter.java │ │ ├── core │ │ ├── Analyzer.java │ │ ├── ClassResolver.java │ │ ├── Dfs.java │ │ ├── DirectoryWriter.java │ │ ├── OutputVisitor.java │ │ ├── Shrinker.java │ │ ├── URLCpResolver.java │ │ └── Writer.java │ │ ├── model │ │ ├── AbstractDescriptor.java │ │ ├── AnnotationUsage.java │ │ ├── ClassDescriptor.java │ │ ├── EdgeType.java │ │ ├── FieldDescriptor.java │ │ ├── Invocation.java │ │ ├── InvocationFactory.java │ │ ├── MethodDescriptor.java │ │ ├── Model.java │ │ ├── ModelVisitor.java │ │ ├── NewNodeDescriptor.java │ │ └── NodeType.java │ │ └── util │ │ ├── MultiReleaseException.java │ │ └── Util.java └── resources │ └── com │ └── yworks │ └── yguard │ ├── jdk118.bits │ ├── jdk131.bits │ ├── jdk142.bits │ ├── jdk15.bits │ ├── jdk15b.bits │ └── jdks.bits └── test ├── java └── com │ └── yworks │ ├── util │ ├── Compiler.java │ ├── InMemoryArchive.java │ ├── abstractjar │ │ ├── AbstractArchiveTest.java │ │ ├── ArchiveTest.java │ │ ├── StreamProviderTest.java │ │ └── Utils.java │ ├── compiler │ │ ├── FileObjects.java │ │ ├── SimpleCompiler.java │ │ └── Streams.java │ └── graph │ │ └── DefaultNetworkTest.java │ ├── yguard │ ├── LogParserTest.java │ ├── annotations │ │ ├── AnnoTest2KEEP.java │ │ ├── AnnoTest3OBFUSCATE.java │ │ ├── AnnoTest4KEEP.java │ │ ├── AnnoTest5KEEP.java │ │ ├── AnnoTest6KEEP.java │ │ ├── AnnoTest7KEEP.java │ │ ├── AnnoTestKEEP.java │ │ ├── AnnotationsTest.java │ │ ├── TestAnnotation.java │ │ ├── TestEnum.java │ │ └── YATAnnotation.java │ ├── generics │ │ ├── MyType.java │ │ ├── ParameterizedType.java │ │ └── TestGenerics.java │ └── obf │ │ ├── AbstractObfuscationTest.java │ │ ├── AdjustTest.java │ │ ├── BootstrapMethodsTest.java │ │ ├── KeepExtendsTest.java │ │ ├── Mapper.java │ │ └── MethodParametersTest.java │ └── yshrink │ ├── ant │ └── TestPatternMatchedSection.java │ ├── java13 │ ├── DefaultMethodTest.java │ ├── InvokeDynamicTest.java │ ├── NestHostTest.java │ └── Utils.java │ └── util │ └── TestUtil.java └── resources └── com └── yworks ├── yguard └── obf │ ├── ConstantBootstraps.txt │ ├── LambdaMetaFactoryTest.txt │ ├── SimpleMethodParametersTest.txt │ ├── StringConcatFactoryTest.txt │ ├── SwitchBootstraps_enumSwitch.txt │ ├── SwitchBootstraps_enumSwitch_string.txt │ ├── SwitchBootstraps_typeSwitch.txt │ ├── adjust │ ├── ClassWithResources.properties │ ├── ClassWithResources.txt │ └── GlobalResources.properties │ └── asm │ ├── AbstractBaseClass.txt │ ├── Impl.txt │ ├── Main.txt │ ├── OuterClass.txt │ ├── Sample.txt │ ├── SealedClassImpl.txt │ ├── SealedSerializableClass.txt │ └── SimpleClass.txt └── yshrink └── java13 ├── DirectSuperInterfaceTest.txt ├── LambdaMetaFactoryTest.txt ├── NestHostStubTest.txt ├── SimpleChainTest.txt └── StringConcatFactoryTest.txt /.github/workflows/continous-integration.yml: -------------------------------------------------------------------------------- 1 | name: Continous Integration for yGuard 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@master 10 | - uses: OrangeLabs-moe/gradle-actions@v5.0-openjdk-11 11 | with: 12 | args: clean build test 13 | examples: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@master 17 | - name: Set up JDK 1.8 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: 1.8 21 | - name: Local publication for consumption by examples 22 | run: ./gradlew publishToMavenLocal 23 | - name: Test annotation example 24 | working-directory: ./examples/annotation 25 | run: mvn package 26 | - name: Test application example 27 | working-directory: ./examples/application 28 | run: mvn package 29 | - name: Test external_library example 30 | working-directory: ./examples/external_library 31 | run: mvn package 32 | - name: Test library example 33 | working-directory: ./examples/library 34 | run: mvn package 35 | - name: Test resources example 36 | working-directory: ./examples/resources 37 | run: mvn package 38 | - name: Test serializable_exclusion example 39 | working-directory: ./examples/serializable_exclusion 40 | run: mvn package 41 | -------------------------------------------------------------------------------- /.github/workflows/pages.yml: -------------------------------------------------------------------------------- 1 | name: Build pages 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | build-and-deploy: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 🛎️ 12 | uses: actions/checkout@v2 13 | - uses: actions/setup-python@v1 14 | with: 15 | python-version: '3.x' 16 | - name: Install and Build 17 | run: | 18 | pip3 install mkdocs mkdocs-material 19 | mkdocs build 20 | - name: Deploy 🚀 21 | uses: JamesIves/github-pages-deploy-action@releases/v3 22 | with: 23 | ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 24 | BRANCH: gh-pages 25 | FOLDER: site 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Build files and distributions produced by ant 26 | dist/ 27 | target/ 28 | 29 | # IDE 30 | .idea/ 31 | 32 | # Ignore Gradle project-specific cache directory 33 | .gradle 34 | 35 | # Ignore Gradle build output directory 36 | build 37 | 38 | # Ignore yGuard output 39 | yguardlog.xml 40 | yshrinklog.xml 41 | 42 | lib/ 43 | node_modules/ 44 | 45 | # Ignore example files 46 | examples/*/build 47 | examples/*/target 48 | examples/*/lib 49 | examples/*/*log.xml 50 | 51 | # Ignore site/ folder generated by mkdocs 52 | site/ 53 | 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 yWorks GmbH 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 | -------------------------------------------------------------------------------- /annotation/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Ignore Gradle build output directory 26 | build 27 | -------------------------------------------------------------------------------- /annotation/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | compileJava { 6 | sourceCompatibility = 1.7 7 | targetCompatibility = 1.7 8 | } 9 | 10 | jar { 11 | setArchivesBaseName('ObfuscationAnnotation') 12 | } 13 | 14 | javadoc { 15 | source = sourceSets.main.allJava 16 | classpath = configurations.compileClasspath 17 | } 18 | 19 | task annotationSourceJar(type: Jar) { 20 | archiveClassifier = 'sources' 21 | from sourceSets.main.allJava 22 | } 23 | 24 | task annotationJavaDoc(type: Jar) { 25 | archiveClassifier = 'javadoc' 26 | from javadoc 27 | } 28 | 29 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/yworks/util/annotation/Obfuscation.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Inherited; 5 | import java.lang.annotation.Target; 6 | 7 | @Inherited 8 | @Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE}) 9 | public @interface Obfuscation { 10 | 11 | boolean applyToMembers() default true; 12 | boolean exclude() default true; 13 | } 14 | -------------------------------------------------------------------------------- /docs/3rdPartyLicenses/asm-license.txt: -------------------------------------------------------------------------------- 1 | ASM: a very small and fast Java bytecode manipulation framework 2 | Copyright (c) 2000-2011 INRIA, France Telecom 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holders nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 | THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /docs/img/dbvissplash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/docs/img/dbvissplash.png -------------------------------------------------------------------------------- /docs/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/docs/img/favicon.ico -------------------------------------------------------------------------------- /docs/img/yguard-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # yGuard 2 | 3 | `yGuard` is an open-source Java obfuscation tool. With `yGuard`, it is easy as pie (🍰) to configure obfuscation through an extensive ant task. 4 | This documentation explains how to use the `yGuard` Java obfuscation and shrinking software. 5 | 6 | yGuard is brought to you by [yWorks GmbH](https://www.yworks.com/), creator of the family of graph and diagram visualization frameworks [yFiles](https://www.yworks.com/yfiles) and other excellent [products](https://www.yworks.com/products). 7 | 8 | `yGuard` comes with a exhaustive set of examples to cover a broad range of use cases. When in doubt, [look up the examples](https://github.com/yWorks/yGuard/tree/master/examples) for solutions. 9 | 10 | ## Table of contents 11 | 12 | - [Setup](setup.md) 13 | - [Using `Ant`](setup.md#setup-using-ant) 14 | - [Using `Maven`](setup.md#setup-using-maven) 15 | - [Using `Gradle`](setup.md#setup-using-gradle) 16 | - [Task documentation](task_documentation.md) 17 | - [Examples](https://github.com/yWorks/yguard/tree/master/examples) 18 | - [Troubleshooting](troubleshooting.md) 19 | - [Compatibility](compatibility.md) 20 | - [License](license.md) 21 | 22 | ## Problems and Bug Reports 23 | 24 | If you experience any problems or think you have found a bug feel free to open an issue on our [public issue tracker](https://github.com/yWorks/yguard/issues). Please make sure you have read the [documentation](task_documentation.md) thoroughly before. We will do our best and try to answer your questions. 25 | -------------------------------------------------------------------------------- /docs/license-agreements/README.txt: -------------------------------------------------------------------------------- 1 | License agreements 2 | ------------------ 3 | 4 | yGuard was transitioned from two modules (yGuard and retroguard) to one module (yGuard). 5 | Historically the initial code of retroguard was based on Mark Welsh's work. 6 | In version 3.0.0 we contacted all copyright holders to unify the repository. 7 | Within this directory you can find the documents concerning the license change. 8 | -------------------------------------------------------------------------------- /docs/license-agreements/mark-welsh.txt: -------------------------------------------------------------------------------- 1 | Mark Welsh, the original author of Retroguard (21-09-2020) 2 | 3 | As the copyright holder of the original RetroGuard source, I grant permission for yWorks to relicense the RetroGuard-based parts in yGuard that are still under LGPL under the more permissive MIT license 4 | -------------------------------------------------------------------------------- /docs/license-agreements/peer.txt: -------------------------------------------------------------------------------- 1 | Peer Törngren who contributed randomized mappings for the rename task: 2 | 3 | yes 4 | 5 | Best Regards 6 | 7 | Peer 8 | 9 | ------ Original Message ------ 10 | Sent: 2020-09-21 09:10:30 11 | Subject: Relicensing contributions under MIT 12 | 13 | >Dear Peer, 14 | > 15 | >as you might know our repository (yGuard) is a bit complicated due to the dual-license in retroguard. 16 | > 17 | >We recently got ahold of the original author and with the approval of all contributors could relicense everything under MIT (which means smaller bundle size, less complicated setup etc). 18 | > 19 | >Would it be ok to relicense your contributions to retroguard under MIT? (simple yes / no is sufficient) 20 | > 21 | > 22 | >All the best, hope you had nice holidays despite COVID-19! 23 | > 24 | >Kind regards, 25 | > 26 | >Lennard 27 | > 28 | > 29 | -------------------------------------------------------------------------------- /docs/license-agreements/yworks.txt: -------------------------------------------------------------------------------- 1 | yWorks the creator of yGuard (21-09-2020) 2 | 3 | yWorks hereby grants permission to relicense any parts written by yWorks employees and contributed under the entity yWorks to retroguard to be relicensed under MIT. 4 | -------------------------------------------------------------------------------- /docs/license.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | `yGuard` is licensed under the `MIT` license. 4 | 5 | All 3rd party licenses can be found in the `3rdPartyLicenses` folder. 6 | -------------------------------------------------------------------------------- /docs/stylesheets/extra.css: -------------------------------------------------------------------------------- 1 | .plain-label { 2 | margin-bottom: 12px; 3 | } 4 | 5 | .rst-content dl.plain-dl > dt.plain-dt { 6 | background: none; 7 | border-top: none; 8 | padding: 0; 9 | } 10 | 11 | .rst-content dl.plain-dl code { 12 | font-weight: normal; 13 | } 14 | 15 | .rst-content dd.plain-dd > pre { 16 | line-height: initial; 17 | } 18 | 19 | .rst-content code.plain-code { 20 | color: initial; 21 | } 22 | -------------------------------------------------------------------------------- /examples/annotation/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | configurations { 10 | yguard 11 | } 12 | 13 | dependencies { 14 | yguard 'com.yworks:yguard:4.1.1' 15 | compile 'com.yworks:annotation:4.1.1' 16 | } 17 | 18 | task obfuscate { 19 | dependsOn jar 20 | group 'yGuard' 21 | description 'Obfuscates the java archive.' 22 | 23 | doLast { 24 | def archivePath = jar.archiveFile.get().asFile.path 25 | def unobfJar = archivePath.replace(".jar", "_unobf.jar") 26 | 27 | ant.move(file: archivePath, tofile: unobfJar, verbose: true) 28 | 29 | ant.taskdef( 30 | name: 'yguard', 31 | classname: 'com.yworks.yguard.YGuardTask', 32 | classpath: configurations.yguard.asPath 33 | ) 34 | ant.yguard { 35 | inoutpair(in: unobfJar, out: archivePath) 36 | rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") 37 | } 38 | } 39 | } 40 | 41 | assemble.dependsOn obfuscate -------------------------------------------------------------------------------- /examples/annotation/build.xml: -------------------------------------------------------------------------------- 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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | This example demonstrates obfuscation for a Java library. 49 | Thus, there is no main class to execute. 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/annotation/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'annotation' 2 | -------------------------------------------------------------------------------- /examples/annotation/src/main/java/com/yworks/example/Company.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import com.yworks.util.annotation.Obfuscation; 4 | 5 | public class Company { 6 | 7 | public String name; 8 | 9 | @Obfuscation 10 | public String taxNumber; 11 | } 12 | -------------------------------------------------------------------------------- /examples/annotation/src/main/java/com/yworks/example/Employee.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import com.yworks.util.annotation.Obfuscation; 4 | 5 | @Obfuscation(exclude = true, applyToMembers = true) 6 | public class Employee { 7 | 8 | @Obfuscation(exclude = false) 9 | public String name; 10 | 11 | public String position; 12 | 13 | public String businessUnit; 14 | } -------------------------------------------------------------------------------- /examples/annotation/src/main/java/com/yworks/example/Member.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import com.yworks.util.annotation.Obfuscation; 4 | 5 | @Obfuscation( exclude = true, applyToMembers = true) 6 | class Member { 7 | 8 | public String id; 9 | 10 | public String department; 11 | } 12 | -------------------------------------------------------------------------------- /examples/annotation/src/main/java/com/yworks/example/Organisation.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import com.yworks.util.annotation.Obfuscation; 4 | 5 | @Obfuscation (exclude = true, applyToMembers = true) 6 | public class Organisation { 7 | 8 | public String name; 9 | 10 | public String category; 11 | 12 | @Obfuscation(exclude = false, applyToMembers = true) 13 | public static class Address { 14 | 15 | String countryCode; 16 | 17 | String street; 18 | 19 | String houseNumber; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/annotation/src/main/java/com/yworks/example/Person.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import com.yworks.util.annotation.Obfuscation; 4 | 5 | @Obfuscation(exclude = true, applyToMembers = false) 6 | public class Person { 7 | 8 | public String name; 9 | 10 | public String occupation; 11 | 12 | @Obfuscation(exclude = true) 13 | public int age; 14 | } -------------------------------------------------------------------------------- /examples/application/README.md: -------------------------------------------------------------------------------- 1 | application 2 | ----------- 3 | 4 | This example demonstrates how to create a program that can be run from a `JAR` archive using `java -jar application.jar`. 5 | -------------------------------------------------------------------------------- /examples/application/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | } 4 | 5 | application { 6 | mainClassName = 'com.yworks.example.HelloWorld' 7 | } 8 | 9 | jar { 10 | manifest { 11 | attributes( 12 | 'Main-Class': application.mainClassName 13 | ) 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | configurations { 22 | yguard 23 | } 24 | 25 | dependencies { 26 | yguard 'com.yworks:yguard:4.1.1' 27 | } 28 | 29 | task obfuscate { 30 | dependsOn jar 31 | group 'yGuard' 32 | description 'Obfuscates the java archive.' 33 | 34 | doLast { 35 | def archivePath = jar.archiveFile.get().asFile.path 36 | def unobfJar = archivePath.replace(".jar", "_unobf.jar") 37 | 38 | ant.move(file: archivePath, tofile: unobfJar, verbose: true) 39 | 40 | ant.taskdef( 41 | name: 'yguard', 42 | classname: 'com.yworks.yguard.YGuardTask', 43 | classpath: configurations.yguard.asPath 44 | ) 45 | ant.yguard { 46 | inoutpair(in: unobfJar, out: archivePath) 47 | rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") { 48 | keep { 49 | 'method'(name: 'void main(java.lang.String[])', class: application.mainClassName) 50 | } 51 | } 52 | } 53 | } 54 | } 55 | 56 | distTar.dependsOn obfuscate 57 | distZip.dependsOn obfuscate 58 | -------------------------------------------------------------------------------- /examples/application/build.xml: -------------------------------------------------------------------------------- 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/application/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'application' 2 | -------------------------------------------------------------------------------- /examples/application/src/main/java/com/yworks/example/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | public class HelloWorld { 4 | private static String companyName() { 5 | return "yWorks"; 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println("Hello World from " + companyName() + '.'); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/external_library/README.md: -------------------------------------------------------------------------------- 1 | external_library 2 | ---------------- 3 | 4 | This example demonstrates how to obfuscate an application that depends on 5 | external libraries with e.g. third-party code. 6 | 7 | The dependencies are specified in the `externalclasses` element using the 8 | standard `Ant` path specification mechanisms. 9 | Classes residing in `lib/gson-2.8.9.jar` will be used to resolve external 10 | dependencies during the obfuscation run. 11 | 12 | yGuard automatically detects externally declared methods and prevents renaming 13 | and shrinking of these items. 14 | 15 | As a result, the shrinked and obfuscated jar file can be used together with 16 | unmodified versions of external libraries without causing any problems. 17 | -------------------------------------------------------------------------------- /examples/external_library/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | } 4 | 5 | application { 6 | mainClassName = 'com.yworks.example.HelloWorld' 7 | } 8 | 9 | compileJava { 10 | sourceCompatibility '1.7' 11 | targetCompatibility '1.7' 12 | } 13 | 14 | jar { 15 | manifest { 16 | attributes( 17 | 'Main-Class': application.mainClassName, 18 | 'Class-Path': './gson-2.8.9.jar' 19 | ) 20 | } 21 | } 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | configurations { 28 | gson 29 | yguard 30 | } 31 | 32 | dependencies { 33 | yguard 'com.yworks:yguard:4.1.1' 34 | gson 'com.google.code.gson:gson:2.8.9' 35 | implementation configurations.gson.dependencies 36 | } 37 | 38 | task obfuscate { 39 | dependsOn jar 40 | group 'yGuard' 41 | description 'Obfuscates the java archive.' 42 | 43 | doLast { 44 | def archivePath = jar.archiveFile.get().asFile.path 45 | def unobfJar = archivePath.replace(".jar", "_unobf.jar") 46 | 47 | ant.move(file: archivePath, tofile: unobfJar, verbose: true) 48 | 49 | ant.taskdef( 50 | name: 'yguard', 51 | classname: 'com.yworks.yguard.YGuardTask', 52 | classpath: configurations.yguard.asPath 53 | ) 54 | ant.yguard { 55 | inoutpair(in: unobfJar, out: archivePath) 56 | 57 | externalclasses { 58 | pathelement(location: configurations.gson.asPath) 59 | } 60 | 61 | rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") { 62 | keep { 63 | 'method'(name: 'void main(java.lang.String[])', class: application.mainClassName) 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | distTar.dependsOn obfuscate 71 | distZip.dependsOn obfuscate 72 | -------------------------------------------------------------------------------- /examples/external_library/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'external_library' 2 | -------------------------------------------------------------------------------- /examples/external_library/src/main/java/com/yworks/example/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import com.google.gson.Gson; 4 | 5 | import java.util.Arrays; 6 | 7 | public class HelloWorld { 8 | public static void main(String[] args) { 9 | new HelloWorld().process("[\"Hello\",\"World\",\"using\",\"a\",\"JSON\",\"deserializer\"]"); 10 | } 11 | 12 | private void process(String document) { 13 | System.out.println(Arrays.asList(parseJson(document))); 14 | } 15 | 16 | private String[] parseJson(String document) { 17 | Gson gson = new Gson(); 18 | return gson.fromJson(document, String[].class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/fxml/README.md: -------------------------------------------------------------------------------- 1 | fxml 2 | ---- 3 | 4 | This example demonstrates how to obfuscate a JavaFX application. 5 | 6 | JavaFX uses reflection to bind fields and methods in controller classes to FXML 7 | markup. While yGuard is able to adjust the qualified names of controller classes 8 | in `*.fxml` files, it is not able to recognize and adjust the names of 9 | controller class members. Thus, the names of fields and methods that are used in 10 | `*.fxml` files have to be excluded from obfuscation. 11 | 12 | Note, yGuard is not able to adjust names of `*.fxml` files. 13 | For this reason, FXML source files should be loaded with explicit name strings 14 | 15 | ```java 16 | FXMLLoader.load(getClass().getResource("HelloWorld.fxml")); 17 | ``` 18 | 19 | to ensure `*.fxml` files can be resolved in classes that have been renamed. 20 | -------------------------------------------------------------------------------- /examples/fxml/settings.gradle: -------------------------------------------------------------------------------- 1 | if (!JavaVersion.current().isJava11Compatible()) { 2 | throw new GradleException( 3 | "Java version ${JavaVersion.current()} is not supported. " + 4 | "Run build with Java version 11 or higher.") 5 | } 6 | 7 | rootProject.name = 'fxml' 8 | -------------------------------------------------------------------------------- /examples/fxml/src/main/java/com/yworks/example/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import javafx.application.Application; 4 | import javafx.fxml.FXMLLoader; 5 | import javafx.scene.Parent; 6 | import javafx.scene.Scene; 7 | import javafx.stage.Stage; 8 | 9 | public class HelloWorld extends Application { 10 | 11 | @Override 12 | public void start( Stage stage ) throws Exception { 13 | Parent root = FXMLLoader.load(getClass().getResource("HelloWorld.fxml")); 14 | Scene scene = new Scene(root); 15 | stage.setScene(scene); 16 | stage.show(); 17 | } 18 | 19 | public static void main( String[] args ) { 20 | launch(args); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /examples/fxml/src/main/java/com/yworks/example/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import javafx.event.ActionEvent; 4 | import javafx.fxml.FXML; 5 | import javafx.scene.control.Label; 6 | 7 | public class HelloWorldController { 8 | 9 | @FXML 10 | private Label clickCountLabel; 11 | 12 | private int clickCount; 13 | 14 | @FXML 15 | private void onClicked( ActionEvent event ) { 16 | ++clickCount; 17 | clickCountLabel.setText(String.format("You clicked %d time%s.", clickCount, clickCount == 1 ? "" : "s")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/fxml/src/main/resources/com/yworks/example/HelloWorld.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 21 | 27 | 37 | 38 | -------------------------------------------------------------------------------- /examples/library/README.md: -------------------------------------------------------------------------------- 1 | library 2 | ------- 3 | 4 | This example demonstrates obfuscation for a Java library that exposes a public 5 | API. 6 | 7 | All public and protected classes, methods, and fields are excluded from 8 | obfuscaton. Package-private and private classes, methods and fields are renamed 9 | whenever possible. 10 | 11 | This example also shows how to use of the `attribute` element. In this case, it 12 | prevents the `yguard` task from removing the `Deprecated` flag from `.class` 13 | files. 14 | -------------------------------------------------------------------------------- /examples/library/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | configurations { 10 | yguard 11 | } 12 | 13 | dependencies { 14 | yguard 'com.yworks:yguard:4.1.1' 15 | } 16 | 17 | task obfuscate { 18 | dependsOn jar 19 | group 'yGuard' 20 | description 'Obfuscates the java archive.' 21 | 22 | doLast { 23 | def archivePath = jar.archiveFile.get().asFile.path 24 | def unobfJar = archivePath.replace(".jar", "_unobf.jar") 25 | 26 | ant.move(file: archivePath, tofile: unobfJar, verbose: true) 27 | 28 | ant.taskdef( 29 | name: 'yguard', 30 | classname: 'com.yworks.yguard.YGuardTask', 31 | classpath: configurations.yguard.asPath 32 | ) 33 | ant.yguard { 34 | inoutpair(in: unobfJar, out: archivePath) 35 | 36 | // Prevent yGuard from removing "Deprecated" attributes from .class files. 37 | attribute(name: "Deprecated") 38 | 39 | rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") { 40 | keep { 41 | 'class'(classes: 'protected', methods: 'protected', fields: 'protected') 42 | } 43 | } 44 | } 45 | } 46 | } 47 | 48 | assemble.dependsOn obfuscate -------------------------------------------------------------------------------- /examples/library/build.xml: -------------------------------------------------------------------------------- 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 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | This example demonstrates obfuscation for a Java library. 51 | Thus, there is no main class to execute. 52 | 53 | 54 | -------------------------------------------------------------------------------- /examples/library/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'library' 2 | -------------------------------------------------------------------------------- /examples/library/src/main/java/com/yworks/example/Functional.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Offers functional utilities for folding lists. 7 | * @deprecated Use {@link java.util.stream.Stream#reduce} instead. 8 | */ 9 | @Deprecated 10 | public class Functional { 11 | protected Double fold(Reducible func, List list) { 12 | return foldImpl(func, list, 0); 13 | } 14 | 15 | private Double foldImpl(Reducible func, List list, int idx ) { 16 | if (idx < list.size()) { 17 | return func.call(list.get(idx), foldImpl(func, list, idx + 1)); 18 | } else { 19 | return Double.valueOf(0); 20 | } 21 | } 22 | 23 | protected Double sum(List list) { 24 | return fold(new SumReducible(), list); 25 | } 26 | 27 | private static class SumReducible implements Reducible { 28 | public Double call(Double a, Double b) { 29 | return Double.valueOf(addDouble(a.doubleValue(), b.doubleValue())); 30 | } 31 | 32 | private double addDouble(double a, double b) { 33 | return a+b; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/library/src/main/java/com/yworks/example/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class HelloWorld { 7 | public static void run() { 8 | new HelloWorld().runImpl(); 9 | } 10 | 11 | private void runImpl() { 12 | List numbers = new ArrayList(); 13 | numbers.add(1.0); 14 | numbers.add(2.0); 15 | numbers.add(3.0); 16 | Functional functional = new Functional(); 17 | _assert(functional.sum(numbers), 6); 18 | } 19 | 20 | private static void _assert(double actual, double expected) { 21 | if (actual != expected) { 22 | throw new RuntimeException("Assertion failed: actual " + actual + " != expected " + expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/library/src/main/java/com/yworks/example/Reducible.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | /** 4 | * A a binary operator for two {@link Double} values. 5 | * @param the type of the operator's operands and return value. 6 | * @deprecated Use {@link java.util.stream.Stream#reduce} instead. 7 | */ 8 | @Deprecated 9 | public interface Reducible { 10 | public T call(T a, T b); 11 | } 12 | -------------------------------------------------------------------------------- /examples/processing/README.md: -------------------------------------------------------------------------------- 1 | # processing 2 | 3 | This example demonstrates how to use post-processing to obfuscate jar files that use non-conformant folders (such as `BOOT-INF`). 4 | 5 | This example will use a Spring Boot starter application. 6 | 7 | Basically, the process runs through the following steps: 8 | 9 | 1. compile and package the Spring Boot Application 10 | 2. extract `classes` from `BOOT_INF` 11 | 3. use a standard obfuscation scheme which will leave libraries unobfuscated 12 | 4. package the classes from the obfuscated JAR back into the JAR packaged in step 1 13 | 14 | The steps are illustrated with command line instructions below. 15 | 16 | ### Obfuscating with `Maven` 17 | ```shell 18 | # package the spring boot application with obfuscated application classes 19 | mvn clean package 20 | ``` 21 | 22 | ### Obfuscating with `Gradle` 23 | ```shell 24 | gradle clean build 25 | ``` 26 | 27 | ### Obfuscating with `Ant` 28 | ```shell 29 | ant clean obfuscate 30 | ``` 31 | -------------------------------------------------------------------------------- /examples/processing/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'processing' 2 | -------------------------------------------------------------------------------- /examples/processing/src/main/java/com/yworks/example/HelloWorldApplication.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * The entry point into a Spring console application. 9 | */ 10 | @SpringBootApplication 11 | public class HelloWorldApplication implements CommandLineRunner { 12 | public static void main( String[] args ) { 13 | SpringApplication.run(HelloWorldApplication.class, args); 14 | } 15 | 16 | @Override 17 | public void run( String... args ) throws Exception { 18 | new HelloWorldImpl().printHelloWorld(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/processing/src/main/java/com/yworks/example/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | /** 4 | * The implementation of a console application. 5 | * This class will be completely obfuscated. 6 | */ 7 | public class HelloWorldImpl { 8 | public void printHelloWorld() { 9 | System.out.println("Hello World."); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/processing/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.main.web-application-type=NONE 2 | -------------------------------------------------------------------------------- /examples/recipes/DEMO_PROGRAM.md: -------------------------------------------------------------------------------- 1 | Demo Program 2 | ------------ 3 | 4 | ```xml 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 | This example demonstrates the common use case of a demo program. 30 | 31 | The `keep` section contains examples for excluding classes, methods, and fields 32 | from the renaming process. Typically, these are classes that are loaded 33 | per reflection and fields and methods needed for serialization. 34 | Note how patternsets can be reused using the `id` and `refid` attributes. 35 | -------------------------------------------------------------------------------- /examples/recipes/README.md: -------------------------------------------------------------------------------- 1 | # Recipes 2 | 3 | This directory contains some recipes for more complex build files that have been 4 | thoroughly used by customers. 5 | 6 | Currently, the following recipes are listed: 7 | 8 | | Recipe Name | Description | 9 | |-------------|--------------------------------------------------------------| 10 | | [Demo Program](./DEMO_PROGRAM.md) | Demonstrates sample excludes | 11 | | [Linked Library](./LINKED_LIBRARY.md) | Shows how to obfuscate an application that depends on yFiles | 12 | -------------------------------------------------------------------------------- /examples/resources/README.md: -------------------------------------------------------------------------------- 1 | resources 2 | --------- 3 | 4 | This example, demonstrates full method and field obfuscation for a program, that uses `.properties` files and other resources files. 5 | 6 | Some configuration files are used that contain fully qualified classnames for plugins that are going to be obfuscated. Therefore, yGuard is configured to automatically replace the plain-text entries in those files with the obfuscated name versions. 7 | 8 | Additionally, some resources are hardcoded into the classes (image locations and html files, e.g.). yGuard gets instructed not to move these resource files even if they reside in a package structure that is obfuscated. 9 | 10 | Since the property files have been created with the same name as the classes that make use of them, yGuard is configured to rename the `.properties` files according to the obfuscated names of the corresponding `.class` files. 11 | -------------------------------------------------------------------------------- /examples/resources/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | } 4 | 5 | application { 6 | mainClassName = 'com.yworks.example.HelloWorld' 7 | } 8 | 9 | jar { 10 | manifest { 11 | attributes( 12 | 'Main-Class': application.mainClassName 13 | ) 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | configurations { 22 | yguard 23 | } 24 | 25 | dependencies { 26 | yguard 'com.yworks:yguard:4.1.1' 27 | } 28 | 29 | task obfuscate { 30 | dependsOn jar 31 | group 'yGuard' 32 | description 'Obfuscates the java archive.' 33 | 34 | doLast { 35 | def archivePath = jar.archiveFile.get().asFile.path 36 | def unobfJar = archivePath.replace(".jar", "_unobf.jar") 37 | 38 | ant.move(file: archivePath, tofile: unobfJar, verbose: true) 39 | 40 | ant.taskdef( 41 | name: 'yguard', 42 | classname: 'com.yworks.yguard.YGuardTask', 43 | classpath: configurations.yguard.asPath 44 | ) 45 | 46 | ant.yguard { 47 | inoutpair(in: unobfJar, out: archivePath) 48 | rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") { 49 | adjust(replacePath: false) { 50 | // keep the complete path to the resources even if 51 | // package com.yworks.example gets obfuscated by name 52 | include(name: "com/yworks/example/resources/*") 53 | } 54 | adjust(replaceContent: true, replaceContentSeparator: ".", replaceName: true) { 55 | // plain-text class names in the config files will 56 | // be replaced with the obfuscated name versions 57 | // replace the .properties files' names with the obfuscated 58 | // versions if the corresponding .class files get obfuscated 59 | include(name: "**/*.properties") 60 | } 61 | keep { 62 | method(name: "void main(java.lang.String[])", "class": application.mainClassName) 63 | } 64 | } 65 | } 66 | } 67 | } 68 | 69 | distTar.dependsOn obfuscate 70 | distZip.dependsOn obfuscate 71 | -------------------------------------------------------------------------------- /examples/resources/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'resources' 2 | -------------------------------------------------------------------------------- /examples/resources/src/main/java/com/yworks/example/PluginImpl.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | /** 4 | * Empty class that is dynamically loaded by name from {@link HelloWorld}. 5 | */ 6 | public class PluginImpl { 7 | } 8 | -------------------------------------------------------------------------------- /examples/resources/src/main/resources/com/yworks/example/HelloWorld.properties: -------------------------------------------------------------------------------- 1 | PLUGIN=com.yworks.example.PluginImpl 2 | -------------------------------------------------------------------------------- /examples/resources/src/main/resources/com/yworks/example/resources/HelloWorldMessage.txt: -------------------------------------------------------------------------------- 1 | Hello World. -------------------------------------------------------------------------------- /examples/serializable_exclusion/README.md: -------------------------------------------------------------------------------- 1 | serializable_exclusion 2 | ---------------------- 3 | 4 | This example demonstrates how to exclude classes based on their type hierarchy. 5 | More specifically, in this example the `implements` attribute of yGuard's 6 | `class` element is used to exclude all classed that implement the 7 | `java.io.Serializable` interface. (In the same way, the `extends` attribute of 8 | the same element could be used to exclude classes that extend a certain base 9 | class). 10 | 11 | Additionally, all classes that extend the base class for menu items, 12 | `com.yworks.example.MyMenuItem`, are defined as entrypoints for the shrinking 13 | engine using the extends attribute of the class element. 14 | The `readObject` and `writeObject` methods and the field `serialVersionUID` 15 | needed for serialization are excluded from name obfuscation as well. 16 | -------------------------------------------------------------------------------- /examples/serializable_exclusion/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | } 4 | 5 | application { 6 | mainClassName = 'com.yworks.example.HelloWorld' 7 | } 8 | 9 | jar { 10 | manifest { 11 | attributes( 12 | 'Main-Class': application.mainClassName 13 | ) 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | configurations { 22 | yguard 23 | } 24 | 25 | dependencies { 26 | yguard 'com.yworks:yguard:4.1.1' 27 | } 28 | 29 | task obfuscate { 30 | dependsOn jar 31 | group 'yGuard' 32 | description 'Obfuscates the java archive.' 33 | 34 | doLast { 35 | def archivePath = jar.archiveFile.get().asFile.path 36 | def unobfJar = archivePath.replace(".jar", "_unobf.jar") 37 | 38 | ant.move(file: archivePath, tofile: unobfJar, verbose: true) 39 | 40 | ant.taskdef( 41 | name: 'yguard', 42 | classname: 'com.yworks.yguard.YGuardTask', 43 | classpath: configurations.yguard.asPath 44 | ) 45 | ant.yguard { 46 | inoutpair(in: unobfJar, out: archivePath) 47 | rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") { 48 | keep { 49 | 'class'(implements: 'java.io.Serializable', methods: 'private', fields: 'private') 50 | 51 | method(name: 'void main(java.lang.String[])', class: application.mainClassName) 52 | } 53 | } 54 | } 55 | } 56 | } 57 | 58 | distTar.dependsOn obfuscate 59 | distZip.dependsOn obfuscate 60 | -------------------------------------------------------------------------------- /examples/serializable_exclusion/build.xml: -------------------------------------------------------------------------------- 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /examples/serializable_exclusion/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'serializable_exclusion' -------------------------------------------------------------------------------- /examples/serializable_exclusion/src/main/java/com/yworks/example/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import java.io.Serializable; 10 | 11 | public class HelloWorld { 12 | public static void main( String[] args ) { 13 | new HelloWorld().run(); 14 | } 15 | 16 | private void run() { 17 | SerializableCollection source = new SerializableCollection(); 18 | source.add(new SerializableItem(1, "Hello World")); 19 | source.add(new SerializableItem(2, "from serializable item")); 20 | dump("source", source); 21 | 22 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 23 | write(source, baos); 24 | 25 | SerializableCollection target = read(new ByteArrayInputStream(baos.toByteArray())); 26 | dump("target", target); 27 | } 28 | 29 | private void dump( String name, SerializableCollection data ) { 30 | final StringBuilder sb = new StringBuilder(); 31 | sb.append("Items in ").append(name).append(":\n"); 32 | for (Serializable item : data) { 33 | sb.append(" ").append(item); 34 | } 35 | System.out.println(sb.toString()); 36 | } 37 | 38 | private SerializableCollection read( InputStream is ) { 39 | try { 40 | return (SerializableCollection) IoUtils.newObjectInputStream(is).readObject(); 41 | } catch (Exception ex) { 42 | if (ex instanceof RuntimeException) { 43 | throw (RuntimeException) ex; 44 | } else { 45 | throw new RuntimeException(ex); 46 | } 47 | } 48 | } 49 | 50 | private void write( SerializableCollection data, OutputStream os ) { 51 | try { 52 | IoUtils.newObjectOutputStream(os).writeObject(data); 53 | } catch (Exception ex) { 54 | if (ex instanceof RuntimeException) { 55 | throw (RuntimeException) ex; 56 | } else { 57 | throw new RuntimeException(ex); 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /examples/serializable_exclusion/src/main/java/com/yworks/example/SerializableCollection.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.io.ObjectOutputStream; 6 | import java.io.Serializable; 7 | import java.util.ArrayList; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | 11 | public class SerializableCollection implements Iterable, Serializable { 12 | private static final long serialVersionUID = 5632652075812502119L; 13 | 14 | private transient List items; 15 | 16 | public SerializableCollection() { 17 | items = new ArrayList(); 18 | } 19 | 20 | public void add( Serializable item ) { 21 | items.add(item); 22 | } 23 | 24 | @Override 25 | public Iterator iterator() { 26 | return items.iterator(); 27 | } 28 | 29 | public void clear() { 30 | items.clear(); 31 | } 32 | 33 | private void readObject( ObjectInputStream is ) throws ClassNotFoundException, IOException { 34 | if (items == null) { 35 | items = new ArrayList(); 36 | } else { 37 | items.clear(); 38 | } 39 | 40 | int size = is.readInt(); 41 | for (int i = 0; i < size; ++i) { 42 | items.add((Serializable) is.readObject()); 43 | } 44 | } 45 | 46 | private void writeObject( ObjectOutputStream os ) throws IOException { 47 | os.writeInt(items.size()); 48 | for (Serializable item : items) { 49 | os.writeObject(item); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/serializable_exclusion/src/main/java/com/yworks/example/SerializableItem.java: -------------------------------------------------------------------------------- 1 | package com.yworks.example; 2 | 3 | import java.io.Serializable; 4 | 5 | public class SerializableItem implements Serializable { 6 | private static final long serialVersionUID = -9206976987376375747L; 7 | 8 | private int rank; 9 | private String description; 10 | 11 | public SerializableItem( final int rank, final String description ) { 12 | this.rank = rank; 13 | this.description = description; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return rank + ": " + description; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_MAJOR=4.1 2 | VERSION_MINOR=1 3 | 4 | POM_DESCRIPTION=The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts 5 | POM_URL=https://github.com/yWorks/yGuard 6 | 7 | POM_SCM_CONNECTION=scm:git:git://github.com/yWorks/yGuard.git 8 | POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/yWorks/yGuard.git 9 | POM_SCM_URL=https://github.com/yWorks/yGuard 10 | 11 | POM_DEVELOPER_ID=berger 12 | POM_DEVELOPER_NAME=Lennard Berger 13 | POM_DEVELOPER_EMAIL=lennard.berger@yworks.com 14 | 15 | POM_LICENCE_NAME=MIT 16 | POM_LICENCE_URL=https://opensource.org/licenses/mit-license.php 17 | POM_LICENCE_DIST=repo 18 | 19 | SONATYPE_NEXUS_USERNAME= 20 | SONATYPE_NEXUS_PASSWORD= 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: yGuard Documentation 2 | repo_url: https://github.com/yWorks/yGuard/ 3 | site_description: The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts 4 | theme: 5 | name: material 6 | logo: img/yguard-logo.svg 7 | favicon: img/favicon.ico 8 | plugins: 9 | - offline 10 | - search 11 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'yguard' 2 | include 'annotation' 3 | include 'retroguard' 4 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/common/ResourcePolicy.java: -------------------------------------------------------------------------------- 1 | package com.yworks.common; 2 | 3 | /** 4 | * The enum Resource policy. 5 | * 6 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 7 | */ 8 | public enum ResourcePolicy { 9 | /** 10 | * Copy resource policy. 11 | */ 12 | COPY, 13 | /** 14 | * Auto resource policy. 15 | */ 16 | AUTO, 17 | /** 18 | * None resource policy. 19 | */ 20 | NONE; } 21 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/common/ShrinkBag.java: -------------------------------------------------------------------------------- 1 | package com.yworks.common; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * The interface Shrink bag. 7 | * 8 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 9 | */ 10 | public interface ShrinkBag { 11 | 12 | /** 13 | * Sets in. 14 | * 15 | * @param file the file 16 | */ 17 | void setIn( File file ); 18 | 19 | /** 20 | * Sets out. 21 | * 22 | * @param file the file 23 | */ 24 | void setOut( File file ); 25 | 26 | /** 27 | * Gets in. 28 | * 29 | * @return the in 30 | */ 31 | File getIn(); 32 | 33 | /** 34 | * Gets out. 35 | * 36 | * @return the out 37 | */ 38 | File getOut(); 39 | 40 | /** 41 | * Is entry point jar boolean. 42 | * 43 | * @return the boolean 44 | */ 45 | boolean isEntryPointJar(); 46 | 47 | /** 48 | * Sets resources. 49 | * 50 | * @param resourcesStr the resources str 51 | */ 52 | void setResources( String resourcesStr ); 53 | 54 | /** 55 | * Gets resources. 56 | * 57 | * @return the resources 58 | */ 59 | ResourcePolicy getResources(); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/common/ant/AttributesSection.java: -------------------------------------------------------------------------------- 1 | package com.yworks.common.ant; 2 | 3 | import java.util.Set; 4 | import java.util.HashSet; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * The type Attributes section. 9 | * 10 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 11 | */ 12 | public class AttributesSection extends PatternMatchedSection { 13 | 14 | private Set attributes = new HashSet( ); 15 | private String attributesStr; 16 | 17 | /** 18 | * Gets attributes. 19 | * 20 | * @return the attributes 21 | */ 22 | public Set getAttributes() { 23 | return attributes; 24 | } 25 | 26 | /** 27 | * Gets attributes str. 28 | * 29 | * @return the attributes str 30 | */ 31 | public String getAttributesStr() { 32 | return this.attributesStr; 33 | } 34 | 35 | /** 36 | * Sets name. 37 | * 38 | * @param attributeStr the attribute str 39 | */ 40 | public void setName( String attributeStr ) { 41 | 42 | this.attributesStr = attributeStr; 43 | StringTokenizer tok = new StringTokenizer( attributeStr, "," ); 44 | while ( tok.hasMoreElements() ) { 45 | attributes.add( tok.nextToken().trim() ); 46 | } 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/common/ant/EntryPointJar.java: -------------------------------------------------------------------------------- 1 | package com.yworks.common.ant; 2 | 3 | import com.yworks.common.ResourcePolicy; 4 | import com.yworks.common.ShrinkBag; 5 | import org.apache.tools.ant.BuildException; 6 | 7 | import java.io.File; 8 | 9 | /** 10 | * The type Entry point jar. 11 | * 12 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 13 | */ 14 | public class EntryPointJar implements ShrinkBag { 15 | 16 | private File inFile; 17 | 18 | public void setIn( File file ) { 19 | inFile = file; 20 | } 21 | 22 | /** 23 | * Sets name. 24 | * 25 | * @param fileName the file name 26 | */ 27 | public void setName(File fileName) { 28 | inFile = fileName; 29 | } 30 | 31 | public void setOut( File file ) { 32 | throw new BuildException( "You can't set an outfile on an EntryPointJar." ); 33 | } 34 | 35 | public File getIn() { 36 | return inFile; 37 | } 38 | 39 | public File getOut() { 40 | return null; 41 | } 42 | 43 | public boolean isEntryPointJar() { 44 | return true; 45 | } 46 | 47 | public void setResources( String resourcesStr ) { 48 | throw new BuildException( "You can't set resources on an EntryPointJar." ); 49 | } 50 | 51 | public ResourcePolicy getResources() { 52 | return null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/common/ant/InOutPair.java: -------------------------------------------------------------------------------- 1 | package com.yworks.common.ant; 2 | 3 | import com.yworks.common.ResourcePolicy; 4 | import com.yworks.common.ShrinkBag; 5 | import org.apache.tools.ant.BuildException; 6 | 7 | import java.io.File; 8 | 9 | /** 10 | * The type In out pair. 11 | * 12 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 13 | */ 14 | public class InOutPair implements ShrinkBag { 15 | private File inFile; 16 | private File outFile; 17 | 18 | /** 19 | * The Resources. 20 | */ 21 | ResourcePolicy resources = ResourcePolicy.COPY; 22 | 23 | public void setIn( final File file ) { 24 | this.inFile = file; 25 | } 26 | 27 | public void setOut( final File file ) { 28 | this.outFile = file; 29 | } 30 | 31 | public File getIn() { 32 | return inFile; 33 | } 34 | 35 | public File getOut() { 36 | return outFile; 37 | } 38 | 39 | public boolean isEntryPointJar() { 40 | return false; 41 | } 42 | 43 | public void setResources( String resourcesStr ) { 44 | 45 | try { 46 | resources = ResourcePolicy.valueOf( resourcesStr.trim().toUpperCase() ); 47 | } catch ( IllegalArgumentException e ) { 48 | throw new BuildException( "Invalid resource policy: " + resourcesStr ); 49 | } 50 | } 51 | 52 | public ResourcePolicy getResources() { 53 | return resources; 54 | } 55 | 56 | public String toString() { 57 | return "in: " + inFile + "; out: " + outFile; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/common/ant/TypePatternSet.java: -------------------------------------------------------------------------------- 1 | package com.yworks.common.ant; 2 | 3 | import org.apache.tools.ant.types.PatternSet; 4 | 5 | /** 6 | * The type Type pattern set. 7 | * 8 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 9 | */ 10 | public class TypePatternSet extends PatternSet { 11 | 12 | /** 13 | * The enum Type. 14 | */ 15 | public enum Type { 16 | /** 17 | * Class type. 18 | */ 19 | CLASS, 20 | /** 21 | * Name type. 22 | */ 23 | NAME, 24 | /** 25 | * Package type. 26 | */ 27 | PACKAGE, 28 | /** 29 | * Extends type. 30 | */ 31 | EXTENDS, 32 | /** 33 | * Implements type. 34 | */ 35 | IMPLEMENTS 36 | } 37 | 38 | private Type type = Type.NAME; 39 | 40 | /** 41 | * Gets type. 42 | * 43 | * @return the type 44 | */ 45 | public Type getType() { 46 | return type; 47 | } 48 | 49 | /** 50 | * Sets type. 51 | * 52 | * @param type the type 53 | */ 54 | public void setType( String type ) { 55 | this.type = Type.valueOf( type.toUpperCase() ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package com.yworks.logging; 2 | 3 | /** 4 | * The type Console logger. 5 | * 6 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 7 | */ 8 | public class ConsoleLogger extends Logger { 9 | 10 | /** 11 | * Instantiates a new Console logger. 12 | */ 13 | public ConsoleLogger() { 14 | register(); 15 | } 16 | 17 | public void doLog( final String s ) { 18 | //System.out.println( s ); 19 | } 20 | 21 | public void doErr( final String s ) { 22 | System.err.println( s ); 23 | } 24 | 25 | public void doWarn( final String s ) { 26 | System.out.println( s ); 27 | } 28 | 29 | public void doWarnToLog( String s ) { 30 | } 31 | 32 | public void doShrinkLog( String s ) { 33 | System.out.println( s ); 34 | } 35 | 36 | public void doErr( String s, Throwable ex ) { 37 | System.out.println( s ); 38 | ex.printStackTrace(); 39 | } 40 | 41 | public void close() { 42 | unregister(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/CollectionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * CollectionFilter.java 3 | * 4 | * Created on October 24, 2002, 5:01 PM 5 | */ 6 | 7 | package com.yworks.util; 8 | 9 | /** 10 | * The type Collection filter. 11 | * 12 | * @author Sebastian Mueller, yWorks GmbH http://www.yworks.com 13 | */ 14 | public class CollectionFilter implements Filter 15 | { 16 | 17 | /** Holds value of property collection. */ 18 | private java.util.Collection collection; 19 | 20 | /** 21 | * Creates a new instance of CollectionFilter 22 | * 23 | * @param col the col 24 | */ 25 | public CollectionFilter(java.util.Collection col) 26 | { 27 | this.collection = col; 28 | } 29 | 30 | public boolean accepts(Object o) 31 | { 32 | return collection != null && collection.contains(o); 33 | } 34 | 35 | /** 36 | * Getter for property collection. 37 | * 38 | * @return Value of property collection. 39 | */ 40 | public java.util.Collection getCollection() 41 | { 42 | return this.collection; 43 | } 44 | 45 | /** 46 | * Setter for property collection. 47 | * 48 | * @param collection New value of property collection. 49 | */ 50 | public void setCollection(java.util.Collection collection) 51 | { 52 | this.collection = collection; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/Filter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Filter.java 3 | * 4 | * Created on October 24, 2002, 4:51 PM 5 | */ 6 | 7 | package com.yworks.util; 8 | 9 | /** 10 | * The interface Filter. 11 | * 12 | * @author Sebastian Mueller, yWorks GmbH http://www.yworks.com 13 | */ 14 | public interface Filter 15 | { 16 | /** 17 | * Accepts boolean. 18 | * 19 | * @param o the o 20 | * @return the boolean 21 | */ 22 | boolean accepts(Object o); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/Version.java: -------------------------------------------------------------------------------- 1 | /** 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | 8 | */ 9 | package com.yworks.util; 10 | 11 | 12 | /** 13 | * Central point for version and build control. 14 | * 15 | * @author Mark Welsh, yWorks' yGuard Team 16 | */ 17 | public class Version { 18 | // Constants ------------------------------------------------------------- 19 | private static final String REL_VERSION = "@VERSION@"; 20 | private static final String YGUARD_REL_JAR_COMMENT = null; // "Obfuscation by yGuard v"+REL_VERSION+" - www.yworks.com (authors: Mark Welsh, markw@retrologic.com; yWorks' yGuard Development Team, yguard@yworks.com)"; 21 | 22 | 23 | // Class Methods --------------------------------------------------------- 24 | 25 | /** 26 | * Return the current major.minor version string. 27 | * 28 | * @return the version 29 | */ 30 | public static String getVersion() { 31 | return REL_VERSION; 32 | } 33 | 34 | /** 35 | * Return the current Jar comment String. 36 | * 37 | * @return the jar comment 38 | */ 39 | public static String getJarComment() { 40 | return YGUARD_REL_JAR_COMMENT; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/Archive.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Enumeration; 6 | import java.util.jar.Manifest; 7 | 8 | /** 9 | * Describes an abstract "archive". This is usually a JAR archive. 10 | * However in Java terms using a directory to execute code (.class files) is perfectly fine. 11 | * Thus AbstractArchive provides an abstraction layer to account for both JAR files and directories (and potentially more). 12 | */ 13 | public interface Archive { 14 | /** 15 | * Gets name. 16 | * 17 | * @return the name 18 | */ 19 | String getName(); 20 | 21 | /** 22 | * Gets entries. 23 | * 24 | * @return the entries 25 | */ 26 | Enumeration getEntries(); 27 | 28 | /** 29 | * Gets manifest. 30 | * 31 | * @return the manifest 32 | * @throws IOException the io exception 33 | */ 34 | Manifest getManifest() throws IOException; 35 | 36 | /** 37 | * Gets input stream. 38 | * 39 | * @param entry the entry 40 | * @return the input stream 41 | * @throws IOException the io exception 42 | */ 43 | InputStream getInputStream(Entry entry) throws IOException; 44 | 45 | /** 46 | * Close. 47 | * 48 | * @throws IOException the io exception 49 | */ 50 | void close() throws IOException; 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/ArchiveWriter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import java.io.IOException; 4 | import java.util.jar.Manifest; 5 | 6 | /** 7 | * Specifies the contract for adding content to archive files, 8 | * that is jars and directories. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public abstract class ArchiveWriter { 13 | protected ArchiveWriter( Manifest man ) throws IOException { 14 | if (man == null) { 15 | throw new NullPointerException("man"); 16 | } 17 | } 18 | 19 | public abstract void setComment( String comment ); 20 | 21 | public abstract void addDirectory( String path ) throws IOException; 22 | 23 | public abstract void addFile( String path, byte[] data ) throws IOException; 24 | 25 | public abstract void close() throws IOException; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/Entry.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | /** 4 | * Entry represents an entry in an archive, e.g class file or resource file 5 | */ 6 | public interface Entry { 7 | /** 8 | * Is directory boolean. 9 | * 10 | * @return the boolean 11 | */ 12 | boolean isDirectory(); 13 | 14 | /** 15 | * Gets name. 16 | * 17 | * @return the name 18 | */ 19 | String getName(); 20 | 21 | /** 22 | * Gets size. 23 | * 24 | * @return the size 25 | */ 26 | long getSize(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/Factory.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import com.yworks.util.abstractjar.impl.DirectoryWriterImpl; 4 | import com.yworks.util.abstractjar.impl.DirectoryStreamProvider; 5 | import com.yworks.util.abstractjar.impl.DirectoryWrapper; 6 | import com.yworks.util.abstractjar.impl.JarWriterImpl; 7 | import com.yworks.util.abstractjar.impl.JarFileWrapper; 8 | import com.yworks.util.abstractjar.impl.JarStreamProvider; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.util.jar.Manifest; 13 | 14 | /** 15 | * Creates facades for transparent usage of archive files, 16 | * that is jars and directories. 17 | * 18 | * @author Thomas Behr 19 | */ 20 | public class Factory { 21 | private Factory() { 22 | } 23 | 24 | public static Archive newArchive( final File archive ) throws IOException { 25 | return archive.isDirectory() 26 | ? new DirectoryWrapper(archive) 27 | : new JarFileWrapper(archive); 28 | } 29 | 30 | public static StreamProvider newStreamProvider( 31 | final File archive 32 | ) throws IOException { 33 | return archive.isDirectory() 34 | ? new DirectoryStreamProvider(archive) 35 | : new JarStreamProvider(archive); 36 | } 37 | 38 | public static ArchiveWriter newArchiveWriter( 39 | final File archive, final Manifest manifest 40 | ) throws IOException { 41 | return archive.isDirectory() 42 | ? new DirectoryWriterImpl(archive, manifest) 43 | : new JarWriterImpl(archive, manifest); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/StreamProvider.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | 6 | /** 7 | * The interface Stream provider. 8 | * 9 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 10 | */ 11 | public interface StreamProvider { 12 | 13 | /** 14 | * Gets next class entry stream. 15 | * 16 | * @return the next class entry stream 17 | * @throws IOException the io exception 18 | */ 19 | DataInputStream getNextClassEntryStream() throws IOException; 20 | 21 | /** 22 | * Gets next resource entry stream. 23 | * 24 | * @return the next resource entry stream 25 | * @throws IOException the io exception 26 | */ 27 | DataInputStream getNextResourceEntryStream() throws IOException; 28 | 29 | /** 30 | * Gets current entry. 31 | * 32 | * @return the current entry 33 | */ 34 | Entry getCurrentEntry(); 35 | 36 | /** 37 | * Gets current entry name. 38 | * 39 | * @return the current entry name 40 | */ 41 | String getCurrentEntryName(); 42 | 43 | /** 44 | * Gets current dir. 45 | * 46 | * @return the current dir 47 | */ 48 | String getCurrentDir(); 49 | 50 | /** 51 | * Gets current filename. 52 | * 53 | * @return the current filename 54 | */ 55 | String getCurrentFilename(); 56 | 57 | /** 58 | * Resets the stream provider. 59 | */ 60 | void reset(); 61 | 62 | /** 63 | * Closes the stream provider. 64 | */ 65 | void close() throws IOException; 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/impl/FileEntryWrapper.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar.impl; 2 | 3 | import com.yworks.util.abstractjar.Entry; 4 | 5 | import java.io.File; 6 | import java.nio.file.Path; 7 | 8 | /** 9 | * The type File entry wrapper. 10 | */ 11 | public class FileEntryWrapper implements Entry { 12 | private File file; 13 | private String relative; 14 | 15 | /** 16 | * Instantiates a new File entry wrapper. 17 | * 18 | * @param relative relative path to the file 19 | * @param file the file 20 | */ 21 | FileEntryWrapper( File file, String relative ) { 22 | this.relative = relative; 23 | this.file = file; 24 | } 25 | 26 | @Override 27 | public boolean isDirectory() { 28 | return file.isDirectory(); 29 | } 30 | 31 | @Override 32 | public String getName() { 33 | return relative; 34 | } 35 | 36 | @Override 37 | public long getSize() { 38 | return file.length(); 39 | } 40 | 41 | /** 42 | * Gets file. 43 | * 44 | * @return the file 45 | */ 46 | public File getFile() { 47 | return file; 48 | } 49 | 50 | /** 51 | * Creates an entry instance for the given file relative to the given directory. 52 | */ 53 | static FileEntryWrapper newRelativeInstance( final File directory, final Path file ) { 54 | final String relative = directory.toPath().relativize(file).toString(); 55 | return new FileEntryWrapper(file.toFile(), relative.replace(File.separatorChar, '/')); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/impl/JarEntryWrapper.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar.impl; 2 | 3 | import com.yworks.util.abstractjar.Entry; 4 | 5 | import java.util.jar.JarEntry; 6 | 7 | /** 8 | * The type Jar entry wrapper. 9 | */ 10 | public class JarEntryWrapper implements Entry { 11 | /** 12 | * The Jar entry. 13 | */ 14 | JarEntry jarEntry; 15 | 16 | /** 17 | * Instantiates a new Jar entry wrapper. 18 | * 19 | * @param jarEntry the jar entry 20 | */ 21 | public JarEntryWrapper( JarEntry jarEntry ) { 22 | this.jarEntry = jarEntry; 23 | } 24 | 25 | @Override 26 | public boolean isDirectory() { 27 | return jarEntry.isDirectory(); 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return jarEntry.getName(); 33 | } 34 | 35 | @Override 36 | public long getSize() { 37 | return jarEntry.getSize(); 38 | } 39 | 40 | /** 41 | * Gets jar entry. 42 | * 43 | * @return the jar entry 44 | */ 45 | public JarEntry getJarEntry() { 46 | return jarEntry; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/impl/JarFileWrapper.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar.impl; 2 | 3 | import com.yworks.util.abstractjar.Archive; 4 | import com.yworks.util.abstractjar.Entry; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.util.Collections; 10 | import java.util.Enumeration; 11 | import java.util.LinkedHashMap; 12 | import java.util.Map; 13 | import java.util.jar.JarEntry; 14 | import java.util.jar.JarFile; 15 | import java.util.jar.Manifest; 16 | 17 | /** 18 | * The type Jar file wrapper. 19 | */ 20 | public class JarFileWrapper implements Archive { 21 | /** 22 | * The Jar file. 23 | */ 24 | JarFile jarFile; 25 | /** 26 | * The Entries. 27 | */ 28 | Map entries = new LinkedHashMap<>(); 29 | 30 | /** 31 | * Instantiates a new Jar file wrapper. 32 | * 33 | * @param file the file 34 | * @throws IOException the io exception 35 | */ 36 | public JarFileWrapper( File file ) throws IOException { 37 | jarFile = new JarFile(file); 38 | Enumeration jarEntryEnumeration = jarFile.entries(); 39 | while (jarEntryEnumeration.hasMoreElements()) { 40 | JarEntry jarEntry = jarEntryEnumeration.nextElement(); 41 | entries.put(new JarEntryWrapper(jarEntry), jarEntry); 42 | } 43 | } 44 | 45 | @Override 46 | public String getName() { 47 | return jarFile.getName(); 48 | } 49 | 50 | @Override 51 | public Enumeration getEntries() { 52 | return Collections.enumeration(entries.keySet()); 53 | } 54 | 55 | @Override 56 | public Manifest getManifest() throws IOException { 57 | return jarFile.getManifest(); 58 | } 59 | 60 | @Override 61 | public InputStream getInputStream( final Entry entry ) throws IOException { 62 | return jarFile.getInputStream(entries.get(entry)); 63 | } 64 | 65 | @Override 66 | public void close() throws IOException { 67 | jarFile.close(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/abstractjar/impl/JarWriterImpl.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar.impl; 2 | 3 | import com.yworks.util.abstractjar.ArchiveWriter; 4 | 5 | import java.io.BufferedOutputStream; 6 | import java.io.File; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.util.jar.JarEntry; 10 | import java.util.jar.JarOutputStream; 11 | import java.util.jar.Manifest; 12 | 13 | /** 14 | * Writes contents to jar files. 15 | * 16 | * @author Thomas Behr 17 | */ 18 | public class JarWriterImpl extends ArchiveWriter { 19 | private JarOutputStream jos; 20 | 21 | public JarWriterImpl( final File archive, final Manifest man ) throws IOException { 22 | super(man); 23 | 24 | jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(archive)), man); 25 | } 26 | 27 | @Override 28 | public void setComment( final String comment ) { 29 | jos.setComment(comment); 30 | } 31 | 32 | @Override 33 | public void addDirectory( final String path ) throws IOException { 34 | ensureValid(path); 35 | newEntry(jos, ensureDirName(path)); 36 | jos.closeEntry(); 37 | } 38 | 39 | @Override 40 | public void addFile( final String path, final byte[] data ) throws IOException { 41 | ensureValid(path); 42 | newEntry(jos, path); 43 | jos.write(data); 44 | jos.closeEntry(); 45 | } 46 | 47 | @Override 48 | public void close() throws IOException { 49 | if (jos != null) { 50 | jos.flush(); 51 | jos.close(); 52 | jos = null; 53 | } 54 | } 55 | 56 | 57 | private static void newEntry( 58 | final JarOutputStream jos, final String path 59 | ) throws IOException { 60 | jos.putNextEntry(new JarEntry(path)); 61 | } 62 | 63 | private static String ensureDirName( final String path ) { 64 | return path.endsWith("/") ? path : path + '/'; 65 | } 66 | 67 | private static void ensureValid( final String path ) { 68 | if (path == null) { 69 | throw new NullPointerException("path"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/graph/Edge.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.graph; 2 | 3 | /** 4 | * Package-private class used by DefaultNetwork to represent an Edge. 5 | */ 6 | class Edge { 7 | private final Node source, target; 8 | private Edge nextInEdge, nextOutEdge = null; 9 | 10 | public Edge(Node src, Node tgt) { 11 | source = src; 12 | target = tgt; 13 | } 14 | 15 | public Node getSource() { 16 | return source; 17 | } 18 | 19 | public Node getTarget() { 20 | return target; 21 | } 22 | 23 | public Edge getNextInEdge() { 24 | return nextInEdge; 25 | } 26 | 27 | public Edge getNextOutEdge() { 28 | return nextOutEdge; 29 | } 30 | 31 | public void setNextInEdge( final Edge nextInEdge ) { 32 | this.nextInEdge = nextInEdge; 33 | } 34 | 35 | public void setNextOutEdge( final Edge nextOutEdge ) { 36 | this.nextOutEdge = nextOutEdge; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/util/graph/Node.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.graph; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Package-private class used by DefaultNetwork to represent an Node. 8 | */ 9 | class Node { 10 | private final List inEdges = new ArrayList<>(); 11 | private final List outEdges = new ArrayList<>(); 12 | 13 | public List getInEdges() { 14 | return inEdges; 15 | } 16 | 17 | public List getOutEdges() { 18 | return outEdges; 19 | } 20 | 21 | public void addInEdge(Object edge) { 22 | inEdges.add((Edge) edge); 23 | } 24 | 25 | public void addOutEdge(Object edge) { 26 | outEdges.add((Edge) edge); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ObfuscationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 5 | * 6 | */ 7 | package com.yworks.yguard; 8 | 9 | /** 10 | * The interface Obfuscation listener. 11 | */ 12 | public interface ObfuscationListener extends java.util.EventListener 13 | { 14 | 15 | /** 16 | * Obfuscating jar. 17 | * 18 | * @param inJar the in jar 19 | * @param outJar the out jar 20 | */ 21 | void obfuscatingJar(String inJar, String outJar); 22 | 23 | /** 24 | * Obfuscating class. 25 | * 26 | * @param className the class name 27 | */ 28 | void obfuscatingClass(String className); 29 | 30 | /** 31 | * Parsing class. 32 | * 33 | * @param className the class name 34 | */ 35 | void parsingClass(String className); 36 | 37 | /** 38 | * Parsing jar. 39 | * 40 | * @param jar the jar 41 | */ 42 | void parsingJar(String jar); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 5 | * 6 | */ 7 | package com.yworks.yguard; 8 | 9 | /** 10 | * The type Parse exception. 11 | * 12 | * @author Sebastian Mueller, yWorks GmbH http://www.yworks.com 13 | */ 14 | public class ParseException extends java.lang.RuntimeException 15 | { 16 | 17 | /** 18 | * Creates a new instance of ParseException without detail message. 19 | */ 20 | public ParseException() 21 | { 22 | } 23 | 24 | 25 | /** 26 | * Constructs an instance of ParseException with the specified detail message. 27 | * 28 | * @param msg the detail message. 29 | */ 30 | public ParseException(String msg) 31 | { 32 | super(msg); 33 | } 34 | 35 | /** 36 | * Instantiates a new Parse exception. 37 | * 38 | * @param cause the cause 39 | */ 40 | public ParseException( Exception cause ) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ant/AttributesSection.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.ant; 2 | 3 | import com.yworks.yguard.obf.YGuardRule; 4 | import com.yworks.common.ant.YGuardBaseTask; 5 | 6 | import java.util.Collection; 7 | import java.util.StringTokenizer; 8 | 9 | /** 10 | * Used by ant to handle the attributes element. 11 | */ 12 | public class AttributesSection extends PatternMatchedClassesSection implements Mappable { 13 | protected final YGuardBaseTask obfuscatorTask; 14 | 15 | /** 16 | * Instantiates a new Attributes section. 17 | * 18 | * @param obfuscatorTask the obfuscator task 19 | */ 20 | public AttributesSection( YGuardBaseTask obfuscatorTask ){ 21 | super(); 22 | this.obfuscatorTask = obfuscatorTask; 23 | this.allowMatchAllPatternSet = true; 24 | } 25 | 26 | private String attributes; 27 | 28 | /** 29 | * Set name. 30 | * 31 | * @param attributes the attributes 32 | */ 33 | public void setName(String attributes){ 34 | this.attributes = attributes; 35 | } 36 | 37 | public void addEntries( Collection entries, String className){ 38 | StringTokenizer st = new StringTokenizer(this.attributes, ", ", false); 39 | while (st.hasMoreTokens()){ 40 | String token = st.nextToken().trim(); 41 | YGuardRule entry = new YGuardRule(YGuardRule.TYPE_ATTR2, token, className); 42 | entries.add(entry); 43 | } 44 | } 45 | 46 | public void addMapEntries(Collection entries) 47 | { 48 | } 49 | 50 | /** 51 | * Gets attributes. 52 | * 53 | * @return the attributes 54 | */ 55 | public String getAttributes() { 56 | return attributes; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ant/FieldSection.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.ant; 2 | 3 | import com.yworks.yguard.obf.YGuardRule; 4 | import com.yworks.yguard.ObfuscatorTask; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * Used by ant to handle the field element. 10 | */ 11 | public class FieldSection extends PatternMatchedClassesSection implements Mappable { 12 | private String name; 13 | private String className; 14 | private String mapTo; 15 | // private final YGuardBaseTask obfuscatorTask; 16 | 17 | 18 | 19 | // public FieldSection( YGuardBaseTask obfuscatorTask ) { 20 | // this.obfuscatorTask = obfuscatorTask; 21 | // } 22 | 23 | /** 24 | * Set name. 25 | * 26 | * @param name the name 27 | */ 28 | public void setName(String name){ 29 | this.name = name; 30 | } 31 | 32 | /** 33 | * Set class. 34 | * 35 | * @param name the name 36 | */ 37 | public void setClass(String name){ 38 | this.className = name; 39 | } 40 | 41 | public void addEntries( Collection entries, String className){ 42 | String lname = ObfuscatorTask.toNativeClass(className)+'/'+name; 43 | YGuardRule entry = new YGuardRule(YGuardRule.TYPE_FIELD, lname); 44 | entries.add(entry); 45 | } 46 | 47 | /** 48 | * Set map. 49 | * 50 | * @param map the map 51 | */ 52 | public void setMap(String map){ 53 | this.mapTo = map; 54 | } 55 | 56 | public void addMapEntries(Collection entries) 57 | { 58 | String lname = ObfuscatorTask.toNativeClass(className)+'/'+name; 59 | YGuardRule entry = new YGuardRule(YGuardRule.TYPE_FIELD_MAP, lname); 60 | entry.obfName = mapTo; 61 | entries.add(entry); 62 | } 63 | 64 | /** 65 | * Gets name. 66 | * 67 | * @return the name 68 | */ 69 | public String getName() { 70 | return name; 71 | } 72 | 73 | /** 74 | * Gets class name. 75 | * 76 | * @return the class name 77 | */ 78 | public String getClassName() { 79 | return className; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ant/Mappable.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.ant; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * The interface Mappable. 7 | * 8 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 9 | */ 10 | public interface Mappable { 11 | /** 12 | * Add map entries. 13 | * 14 | * @param entries the entries 15 | */ 16 | void addMapEntries( Collection entries); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ant/Property.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.ant; 2 | 3 | /** 4 | * The type Property. 5 | * 6 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 7 | */ 8 | public final class Property { 9 | /** 10 | * Holds value of property name. 11 | */ 12 | String name; 13 | 14 | /** 15 | * Holds value of property value. 16 | */ 17 | String value; 18 | 19 | /** 20 | * Sets name. 21 | * 22 | * @param name the name 23 | */ 24 | public void setName(String name) 25 | { 26 | this.name = name; 27 | } 28 | 29 | /** 30 | * Sets value. 31 | * 32 | * @param value the value 33 | */ 34 | public void setValue(String value) 35 | { 36 | this.value = value; 37 | } 38 | 39 | /** 40 | * Gets name. 41 | * 42 | * @return the name 43 | */ 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | /** 49 | * Gets value. 50 | * 51 | * @return the value 52 | */ 53 | public String getValue() { 54 | return value; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/ant/SourceFileSection.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.ant; 2 | 3 | import com.yworks.yguard.obf.YGuardRule; 4 | import com.yworks.yguard.obf.classfile.ClassConstants; 5 | import com.yworks.common.ant.YGuardBaseTask; 6 | 7 | import java.util.Collection; 8 | 9 | /** 10 | * Used by ant to handle the attributes element. 11 | */ 12 | public class SourceFileSection extends PatternMatchedClassesSection implements Mappable { 13 | protected final YGuardBaseTask obfuscatorTask; 14 | 15 | /** 16 | * Instantiates a new Source file section. 17 | * 18 | * @param obfuscatorTask the obfuscator task 19 | */ 20 | public SourceFileSection( YGuardBaseTask obfuscatorTask ){ 21 | super(); 22 | this.obfuscatorTask = obfuscatorTask; 23 | this.allowMatchAllPatternSet = true; 24 | } 25 | 26 | public void addEntries( Collection entries, String className){ 27 | YGuardRule rule = createRule(className); 28 | entries.add(rule); 29 | } 30 | 31 | private YGuardRule createRule(String className) { 32 | if (properties.containsKey("mapping")){ 33 | YGuardRule sourceRule = new YGuardRule(YGuardRule.TYPE_SOURCE_ATTRIBUTE_MAP, className); 34 | sourceRule.obfName = (String) properties.get("mapping"); 35 | return sourceRule; 36 | } else { 37 | YGuardRule rule = new YGuardRule(YGuardRule.TYPE_ATTR2, ClassConstants.ATTR_SourceFile, className); 38 | return rule; 39 | } 40 | } 41 | 42 | public void addMapEntries(Collection entries) 43 | { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/Cons.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | /** 11 | * A 'cons' of two references -- useful as a generic return grouping from Enumerations. 12 | * 13 | * @author Mark Welsh 14 | */ 15 | public class Cons 16 | { 17 | // Fields ---------------------------------------------------------------- 18 | /** 19 | * The Car. 20 | */ 21 | public Object car; 22 | /** 23 | * The Cdr. 24 | */ 25 | public Object cdr; 26 | 27 | 28 | // Instance Methods --------------------------------------------------------- 29 | 30 | /** 31 | * Ctor. 32 | * 33 | * @param car the car 34 | * @param cdr the cdr 35 | */ 36 | public Cons(Object car, Object cdr) 37 | { 38 | this.car = car; 39 | this.cdr = cdr; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/Filter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 5 | * 6 | */ 7 | package com.yworks.yguard.obf; 8 | 9 | /** 10 | * The interface Filter. 11 | * 12 | * @author Sebastian Mueller, yWorks GmbH http://www.yworks.com 13 | */ 14 | public interface Filter 15 | { 16 | /** 17 | * Accepts boolean. 18 | * 19 | * @param o the o 20 | * @return the boolean 21 | */ 22 | boolean accepts(Object o); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/LineNumberTableMapper.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import com.yworks.yguard.obf.classfile.LineNumberTableAttrInfo; 4 | 5 | import java.io.PrintWriter; 6 | 7 | /** 8 | * The interface Line number table mapper. 9 | */ 10 | public interface LineNumberTableMapper { 11 | /** 12 | * Callback method that can be used to remap a line number table. 13 | * 14 | * @param className the classes name that contains the method 15 | * @param methodName the name of the method 16 | * @param methodSignature the signature of the method 17 | * @param lineNumberTable the table that may be modified by this method 18 | * @return whether the line number table should be kept 19 | * @see com.yworks.yguard.obf.YGuardRule#TYPE_LINE_NUMBER_MAPPER com.yworks.yguard.obf.YGuardRule#TYPE_LINE_NUMBER_MAPPERcom.yworks.yguard.obf.YGuardRule#TYPE_LINE_NUMBER_MAPPER 20 | */ 21 | boolean mapLineNumberTable(String className, String methodName, String methodSignature, LineNumberTableAttrInfo lineNumberTable); 22 | 23 | /** 24 | * Callback method that can be used to log custom properties to the Printwriter. 25 | * 26 | * @param pw the PrintWriter to print to. 27 | */ 28 | void logProperties(PrintWriter pw); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/NameListDown.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | /** 11 | * Interface to a list of method and field names and descriptors -- used for checking 12 | * if a name/descriptor is reserved through a derived class/interface. 13 | * 14 | * @author Mark Welsh 15 | */ 16 | public interface NameListDown 17 | { 18 | /** 19 | * Is the method reserved because of its reservation down the class hierarchy? 20 | * 21 | * @param caller the caller 22 | * @param name the name 23 | * @param descriptor the descriptor 24 | * @return the method obf name down 25 | * @throws ClassNotFoundException the class not found exception 26 | */ 27 | public String getMethodObfNameDown(Cl caller, String name, String descriptor) throws ClassNotFoundException; 28 | 29 | /** 30 | * Is the field reserved because of its reservation down the class hierarchy? 31 | * 32 | * @param caller the caller 33 | * @param name the name 34 | * @return the field obf name down 35 | * @throws ClassNotFoundException the class not found exception 36 | */ 37 | public String getFieldObfNameDown(Cl caller, String name) throws ClassNotFoundException; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/NameListUp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | /** 11 | * Interface to a list of method and field names and descriptors -- used for checking 12 | * if a name/descriptor is in the public/protected lists of the super-class/interface 13 | * hierarchy. 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public interface NameListUp 18 | { 19 | /** 20 | * Get output method name from list, or null if no mapping exists. 21 | * 22 | * @param name the name 23 | * @param descriptor the descriptor 24 | * @return the method out name up 25 | * @throws ClassNotFoundException the class not found exception 26 | */ 27 | public String getMethodOutNameUp(String name, String descriptor) throws ClassNotFoundException; 28 | 29 | /** 30 | * Get obfuscated method name from list, or null if no mapping exists. 31 | * 32 | * @param name the name 33 | * @param descriptor the descriptor 34 | * @return the method obf name up 35 | * @throws ClassNotFoundException the class not found exception 36 | */ 37 | public String getMethodObfNameUp(String name, String descriptor) throws ClassNotFoundException; 38 | 39 | /** 40 | * Get output field name from list, or null if no mapping exists. 41 | * 42 | * @param name the name 43 | * @return the field out name up 44 | * @throws ClassNotFoundException the class not found exception 45 | */ 46 | public String getFieldOutNameUp(String name) throws ClassNotFoundException; 47 | 48 | /** 49 | * Get obfuscated field name from list, or null if no mapping exists. 50 | * 51 | * @param name the name 52 | * @return the field obf name up 53 | * @throws ClassNotFoundException the class not found exception 54 | */ 55 | public String getFieldObfNameUp(String name) throws ClassNotFoundException; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/NameMaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | /** 11 | * Base interface for name generators for a given namespace. 12 | * 13 | * @author Mark Welsh 14 | */ 15 | public interface NameMaker 16 | { 17 | /** 18 | * Return the next unique name for this namespace, differing only for identical arg-lists. 19 | * 20 | * @param descriptor the descriptor 21 | * @return the string 22 | */ 23 | public String nextName(String descriptor); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/NoSuchMappingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Copyright (c) 2003 yWorks GmbH (yguard@yworks.com) 5 | * 6 | */ 7 | package com.yworks.yguard.obf; 8 | 9 | /** 10 | * The type No such mapping exception. 11 | */ 12 | public class NoSuchMappingException extends java.lang.IllegalArgumentException 13 | { 14 | 15 | private String key; 16 | 17 | /** 18 | * Constructs an instance of NoSuchMappingException with the specified detail message. 19 | * 20 | * @param key the detail message. 21 | */ 22 | public NoSuchMappingException(String key) 23 | { 24 | super("No mapping found for: "+key); 25 | this.key = key; 26 | } 27 | 28 | /** 29 | * Creates a new instance of NoSuchMappingException without detail message. 30 | */ 31 | public NoSuchMappingException() 32 | { 33 | super("No mapping found!"); 34 | this.key = ""; 35 | } 36 | 37 | /** 38 | * Get key string. 39 | * 40 | * @return the string 41 | */ 42 | public String getKey(){ 43 | return key; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/ObfuscationConfig.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | /** 4 | * Encapsulation of annotation configuration data 5 | */ 6 | public class ObfuscationConfig { 7 | 8 | /** 9 | * The constant annotationClassName. 10 | */ 11 | public static String annotationClassName = "com/yworks/util/annotation/Obfuscation"; 12 | 13 | /** 14 | * The Apply to members. 15 | */ 16 | public final boolean applyToMembers; 17 | /** 18 | * The Exclude. 19 | */ 20 | public final boolean exclude; 21 | 22 | /** 23 | * The constant DEFAULT. 24 | */ 25 | public static final ObfuscationConfig DEFAULT = new ObfuscationConfig(false, false); 26 | 27 | /** 28 | * Instantiates a new Obfuscation config. 29 | * 30 | * @param exclude the exclude 31 | * @param applyToMembers the apply to members 32 | */ 33 | public ObfuscationConfig(boolean exclude, boolean applyToMembers) { 34 | this.applyToMembers = applyToMembers; 35 | this.exclude = exclude; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/PlaceholderCl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | /** 11 | * Placeholder class -- used to represent a class which has inner classes, before the 12 | * class itself has been encountered. 13 | * 14 | * @author Mark Welsh 15 | */ 16 | public class PlaceholderCl extends Cl 17 | { 18 | // Constants ------------------------------------------------------------- 19 | 20 | 21 | // Fields ---------------------------------------------------------------- 22 | 23 | 24 | // Class Methods --------------------------------------------------------- 25 | 26 | 27 | // Instance Methods ------------------------------------------------------ 28 | 29 | /** 30 | * Ctor. 31 | * 32 | * @param parent the parent 33 | * @param isInnerClass the is inner class 34 | * @param name the name 35 | */ 36 | public PlaceholderCl(TreeItem parent, boolean isInnerClass, String name) 37 | { 38 | super(parent, isInnerClass, name, null, null, 0, null); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/ResourceHandler.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | 7 | /** 8 | * The interface Resource handler. 9 | * 10 | * @author wiese 11 | */ 12 | public interface ResourceHandler 13 | { 14 | /** 15 | * Filter name boolean. 16 | * 17 | * @param inputName the input name 18 | * @param outputName the output name 19 | * @return the boolean 20 | */ 21 | public boolean filterName(String inputName, StringBuffer outputName); 22 | 23 | /** 24 | * Filter content boolean. 25 | * 26 | * @param in the in 27 | * @param out the out 28 | * @param resourceName the resource name 29 | * @return the boolean 30 | * @throws IOException the io exception 31 | */ 32 | public boolean filterContent(InputStream in, OutputStream out, String resourceName) throws IOException; 33 | 34 | /** 35 | * Filter string string. 36 | * 37 | * @param in the in 38 | * @param resourceName the resource name 39 | * @return the string 40 | * @throws IOException the io exception 41 | */ 42 | public String filterString(String in, String resourceName) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/TreeAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | /** 11 | * Set of actions to be performed by a tree walker 12 | * 13 | * @author Mark Welsh 14 | */ 15 | public class TreeAction 16 | { 17 | /** 18 | * Package action. 19 | * 20 | * @param pk the pk 21 | */ 22 | public void packageAction(Pk pk) {defaultAction(pk);} 23 | 24 | /** 25 | * Class action. 26 | * 27 | * @param cl the cl 28 | */ 29 | public void classAction(Cl cl) {defaultAction(cl);} 30 | 31 | /** 32 | * Method action. 33 | * 34 | * @param md the md 35 | */ 36 | public void methodAction(Md md) {defaultAction(md);} 37 | 38 | /** 39 | * Field action. 40 | * 41 | * @param fd the fd 42 | */ 43 | public void fieldAction(Fd fd) {defaultAction(fd);} 44 | 45 | /** 46 | * Default action. 47 | * 48 | * @param ti the ti 49 | */ 50 | public void defaultAction(TreeItem ti) {} 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf; 9 | 10 | 11 | /** 12 | * Central point for version and build control. 13 | * 14 | * @author Mark Welsh, yWorks' yGuard Team 15 | */ 16 | public class Version { 17 | // Constants ------------------------------------------------------------- 18 | private static final String REL_VERSION = "@VERSION@"; 19 | private static final String YGUARD_REL_JAR_COMMENT = null; // "Obfuscation by yGuard v"+REL_VERSION+" - www.yworks.com (authors: Mark Welsh, markw@retrologic.com; yWorks' yGuard Development Team, yguard@yworks.com)"; 20 | 21 | 22 | // Class Methods --------------------------------------------------------- 23 | 24 | /** 25 | * Return the current major.minor version string. 26 | * 27 | * @return the version 28 | */ 29 | public static String getVersion() { 30 | return REL_VERSION; 31 | } 32 | 33 | /** 34 | * Return the current Jar comment String. 35 | * 36 | * @return the jar comment 37 | */ 38 | public static String getJarComment() { 39 | return YGUARD_REL_JAR_COMMENT; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/AbstractTypeCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a 'class', 'module', or 'package' entry in the ConstantPool. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public abstract class AbstractTypeCpInfo extends CpInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | /** 18 | * The U 2 name index. 19 | */ 20 | int u2nameIndex; 21 | 22 | 23 | // Class Methods --------------------------------------------------------- 24 | 25 | 26 | /** 27 | * Instantiates a new Abstract type cp info. 28 | * 29 | * @param tag the tag 30 | */ 31 | protected AbstractTypeCpInfo(int tag) { 32 | super(tag); 33 | } 34 | 35 | // Instance Methods ------------------------------------------------------ 36 | /** 37 | * Return the name index. 38 | * 39 | * @return the name index 40 | */ 41 | protected int getNameIndex() { 42 | return u2nameIndex; 43 | } 44 | 45 | /** 46 | * Set the name index. 47 | * 48 | * @param index the index 49 | */ 50 | protected void setNameIndex(int index) { 51 | u2nameIndex = index; 52 | } 53 | 54 | /** Check for Utf8 references to constant pool and mark them. */ 55 | protected void markUtf8Refs(ConstantPool pool) { 56 | pool.incRefCount(u2nameIndex); 57 | } 58 | 59 | /** Read the 'info' data following the u1tag byte. */ 60 | protected void readInfo(DataInput din) throws IOException { 61 | u2nameIndex = din.readUnsignedShort(); 62 | } 63 | 64 | /** Write the 'info' data following the u1tag byte. */ 65 | protected void writeInfo(DataOutput dout) throws IOException { 66 | dout.writeShort(u2nameIndex); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/AnnotationDefaultAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * The type Annotation default attr info. 5 | * 6 | * @author muellese 7 | */ 8 | public class AnnotationDefaultAttrInfo extends AttrInfo 9 | { 10 | /** 11 | * The Element value. 12 | */ 13 | protected ElementValueInfo elementValue; 14 | 15 | /** 16 | * Creates a new instance of AnnotationDefaultAttrInfo 17 | * 18 | * @param cf the cf 19 | * @param attrNameIndex the attr name index 20 | * @param attrLength the attr length 21 | */ 22 | public AnnotationDefaultAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 23 | { 24 | super(cf, attrNameIndex, attrLength); 25 | } 26 | 27 | protected String getAttrName() 28 | { 29 | return ClassConstants.ATTR_AnnotationDefault; 30 | } 31 | 32 | public void writeInfo(java.io.DataOutput dout) throws java.io.IOException 33 | { 34 | elementValue.write(dout); 35 | } 36 | 37 | 38 | 39 | protected void readInfo(java.io.DataInput din) throws java.io.IOException 40 | { 41 | elementValue = ElementValueInfo.create(din); 42 | } 43 | 44 | protected void markUtf8RefsInInfo(ConstantPool pool) 45 | { 46 | elementValue.markUtf8RefsInInfo(pool); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ClassCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.*; 11 | 12 | /** 13 | * Representation of a 'class' entry in the ConstantPool. 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public class ClassCpInfo extends AbstractTypeCpInfo 18 | { 19 | // Constants ------------------------------------------------------------- 20 | 21 | 22 | // Fields ---------------------------------------------------------------- 23 | 24 | 25 | // Class Methods --------------------------------------------------------- 26 | 27 | 28 | /** 29 | * Instantiates a new Class cp info. 30 | */ 31 | protected ClassCpInfo() 32 | { 33 | super(CONSTANT_Class); 34 | } 35 | 36 | // Instance Methods ------------------------------------------------------ 37 | /** 38 | * Dump the content of the class file to the specified file (used for debugging). 39 | * 40 | * @param pw the pw 41 | * @param cf the cf 42 | */ 43 | public void dump(PrintWriter pw, ClassFile cf) 44 | { 45 | pw.println(" Class: " + ((Utf8CpInfo)cf.getCpEntry(u2nameIndex)).getString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ConstantValueAttrInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.*; 11 | 12 | /** 13 | * Representation of an attribute. 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public class ConstantValueAttrInfo extends AttrInfo 18 | { 19 | // Constants ------------------------------------------------------------- 20 | 21 | 22 | // Fields ---------------------------------------------------------------- 23 | private int u2constantValueIndex; 24 | 25 | 26 | // Class Methods --------------------------------------------------------- 27 | 28 | 29 | /** 30 | * Instantiates a new Constant value attr info. 31 | * 32 | * @param cf the cf 33 | * @param attrNameIndex the attr name index 34 | * @param attrLength the attr length 35 | */ 36 | protected ConstantValueAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 37 | { 38 | super(cf, attrNameIndex, attrLength); 39 | } 40 | 41 | // Instance Methods ------------------------------------------------------ 42 | /** Return the String name of the attribute; over-ride this in sub-classes. */ 43 | protected String getAttrName() 44 | { 45 | return ATTR_ConstantValue; 46 | } 47 | 48 | /** Read the data following the header. */ 49 | protected void readInfo(DataInput din) throws java.io.IOException 50 | { 51 | u2constantValueIndex = din.readUnsignedShort(); 52 | } 53 | 54 | /** Export data following the header to a DataOutput stream. */ 55 | public void writeInfo(DataOutput dout) throws java.io.IOException 56 | { 57 | dout.writeShort(u2constantValueIndex); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/DeprecatedAttrInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.DataInput; 11 | import java.io.DataOutput; 12 | 13 | /** 14 | * Representation of an attribute. 15 | * 16 | * @author Mark Welsh 17 | */ 18 | public class DeprecatedAttrInfo extends AttrInfo 19 | { 20 | // Constants ------------------------------------------------------------- 21 | 22 | 23 | // Fields ---------------------------------------------------------------- 24 | 25 | 26 | // Class Methods --------------------------------------------------------- 27 | 28 | 29 | /** 30 | * Instantiates a new Deprecated attr info. 31 | * 32 | * @param cf the cf 33 | * @param attrNameIndex the attr name index 34 | * @param attrLength the attr length 35 | */ 36 | protected DeprecatedAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 37 | { 38 | super(cf, attrNameIndex, attrLength); 39 | } 40 | 41 | // Instance Methods ------------------------------------------------------ 42 | /** Return the String name of the attribute. */ 43 | protected String getAttrName() 44 | { 45 | return ATTR_Deprecated; 46 | } 47 | 48 | /** Read the data following the header. */ 49 | protected void readInfo(DataInput din) {} 50 | 51 | /** Export data following the header to a DataOutput stream. */ 52 | public void writeInfo(DataOutput dout) {} 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/DoubleCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.*; 11 | 12 | /** 13 | * Representation of a 'double' entry in the ConstantPool (takes up two indices). 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public class DoubleCpInfo extends CpInfo 18 | { 19 | // Constants ------------------------------------------------------------- 20 | 21 | 22 | // Fields ---------------------------------------------------------------- 23 | private int u4highBytes; 24 | private int u4lowBytes; 25 | 26 | 27 | // Class Methods --------------------------------------------------------- 28 | 29 | 30 | /** 31 | * Instantiates a new Double cp info. 32 | */ 33 | protected DoubleCpInfo() 34 | { 35 | super(CONSTANT_Double); 36 | } 37 | 38 | 39 | // Instance Methods ------------------------------------------------------ 40 | /** Read the 'info' data following the u1tag byte. */ 41 | protected void readInfo(DataInput din) throws java.io.IOException 42 | { 43 | u4highBytes = din.readInt(); 44 | u4lowBytes = din.readInt(); 45 | } 46 | 47 | /** Write the 'info' data following the u1tag byte. */ 48 | protected void writeInfo(DataOutput dout) throws java.io.IOException 49 | { 50 | dout.writeInt(u4highBytes); 51 | dout.writeInt(u4lowBytes); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/DynamicCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * Representation of a 'dynamic' entry in the ConstantPool. 5 | * 6 | * @author Thomas Behr 7 | */ 8 | public class DynamicCpInfo extends AbstractDynamicCpInfo { 9 | /** 10 | * Instantiates a new Dynamic cp info. 11 | */ 12 | protected DynamicCpInfo() { 13 | super(CONSTANT_Dynamic); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/FieldInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.*; 11 | 12 | /** 13 | * Representation of a field from a class-file. 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public class FieldInfo extends ClassItemInfo 18 | { 19 | // Constants ------------------------------------------------------------- 20 | 21 | 22 | // Fields ---------------------------------------------------------------- 23 | 24 | 25 | // Class Methods --------------------------------------------------------- 26 | 27 | /** 28 | * Create a new FieldInfo from the file format data in the DataInput stream. 29 | * 30 | * @param din the din 31 | * @param cf the cf 32 | * @return the field info 33 | * @throws IOException if class file is corrupt or incomplete 34 | */ 35 | public static FieldInfo create(DataInput din, ClassFile cf) throws java.io.IOException 36 | { 37 | if (din == null) throw new NullPointerException("No input stream was provided."); 38 | FieldInfo fi = new FieldInfo(cf); 39 | fi.read(din); 40 | return fi; 41 | } 42 | 43 | 44 | // Instance Methods ------------------------------------------------------ 45 | /** 46 | * Instantiates a new Field info. 47 | * 48 | * @param cf the cf 49 | */ 50 | protected FieldInfo(ClassFile cf) {super(cf);} 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/FieldrefCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | /** 11 | * Representation of a 'fieldref' entry in the ConstantPool. 12 | * 13 | * @author Mark Welsh 14 | */ 15 | public class FieldrefCpInfo extends RefCpInfo 16 | { 17 | // Constants ------------------------------------------------------------- 18 | 19 | 20 | // Fields ---------------------------------------------------------------- 21 | 22 | 23 | // Class Methods --------------------------------------------------------- 24 | 25 | 26 | /** 27 | * Instantiates a new Fieldref cp info. 28 | */ 29 | protected FieldrefCpInfo() 30 | { 31 | super(CONSTANT_Fieldref); 32 | } 33 | 34 | // Instance Methods ------------------------------------------------------ 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/FloatCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.DataInput; 11 | import java.io.DataOutput; 12 | 13 | /** 14 | * Representation of a 'float' entry in the ConstantPool. 15 | * 16 | * @author Mark Welsh 17 | */ 18 | public class FloatCpInfo extends CpInfo 19 | { 20 | // Constants ------------------------------------------------------------- 21 | 22 | 23 | // Fields ---------------------------------------------------------------- 24 | private int u4bytes; 25 | 26 | 27 | // Class Methods --------------------------------------------------------- 28 | 29 | 30 | /** 31 | * Instantiates a new Float cp info. 32 | */ 33 | protected FloatCpInfo() 34 | { 35 | super(CONSTANT_Float); 36 | } 37 | 38 | // Instance Methods ------------------------------------------------------ 39 | /** Read the 'info' data following the u1tag byte. */ 40 | protected void readInfo(DataInput din) throws java.io.IOException 41 | { 42 | u4bytes = din.readInt(); 43 | } 44 | 45 | /** Write the 'info' data following the u1tag byte. */ 46 | protected void writeInfo(DataOutput dout) throws java.io.IOException 47 | { 48 | dout.writeInt(u4bytes); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/IntegerCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.DataInput; 11 | import java.io.DataOutput; 12 | 13 | /** 14 | * Representation of a 'integer' entry in the ConstantPool. 15 | * 16 | * @author Mark Welsh 17 | */ 18 | public class IntegerCpInfo extends CpInfo 19 | { 20 | // Constants ------------------------------------------------------------- 21 | 22 | 23 | // Fields ---------------------------------------------------------------- 24 | private int u4bytes; 25 | 26 | 27 | // Class Methods --------------------------------------------------------- 28 | 29 | 30 | // Instance Methods ------------------------------------------------------ 31 | /** 32 | * Instantiates a new Integer cp info. 33 | */ 34 | protected IntegerCpInfo() 35 | { 36 | super(CONSTANT_Integer); 37 | } 38 | 39 | /** 40 | * As bool boolean. 41 | * 42 | * @return the boolean 43 | */ 44 | public boolean asBool() 45 | { 46 | return u4bytes != 0; 47 | } 48 | 49 | /** Read the 'info' data following the u1tag byte. */ 50 | protected void readInfo(DataInput din) throws java.io.IOException 51 | { 52 | u4bytes = din.readInt(); 53 | } 54 | 55 | /** Write the 'info' data following the u1tag byte. */ 56 | protected void writeInfo(DataOutput dout) throws java.io.IOException 57 | { 58 | dout.writeInt(u4bytes); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/InterfaceMethodrefCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | /** 11 | * Representation of a 'interfacemethodref' entry in the ConstantPool. 12 | * 13 | * @author Mark Welsh 14 | */ 15 | public class InterfaceMethodrefCpInfo extends RefCpInfo 16 | { 17 | // Constants ------------------------------------------------------------- 18 | 19 | 20 | // Fields ---------------------------------------------------------------- 21 | 22 | 23 | // Class Methods --------------------------------------------------------- 24 | 25 | 26 | /** 27 | * Instantiates a new Interface methodref cp info. 28 | */ 29 | protected InterfaceMethodrefCpInfo() 30 | { 31 | super(CONSTANT_InterfaceMethodref); 32 | } 33 | 34 | // Instance Methods ------------------------------------------------------ 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/InvokeDynamicCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * Representation of a 'invokedynamic' entry in the ConstantPool. 5 | * 6 | * @author Sebastian Rheinnecker, yworks 7 | */ 8 | public class InvokeDynamicCpInfo extends AbstractDynamicCpInfo { 9 | /** 10 | * Instantiates a new Invoke dynamic cp info. 11 | */ 12 | protected InvokeDynamicCpInfo() { 13 | super(CONSTANT_InvokeDynamic); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/LongCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.*; 11 | 12 | /** 13 | * Representation of a 'long' entry in the ConstantPool (takes up two indices). 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public class LongCpInfo extends CpInfo 18 | { 19 | // Constants ------------------------------------------------------------- 20 | 21 | 22 | // Fields ---------------------------------------------------------------- 23 | private int u4highBytes; 24 | private int u4lowBytes; 25 | 26 | 27 | // Class Methods --------------------------------------------------------- 28 | 29 | 30 | /** 31 | * Instantiates a new Long cp info. 32 | */ 33 | protected LongCpInfo() 34 | { 35 | super(CONSTANT_Long); 36 | } 37 | 38 | // Instance Methods ------------------------------------------------------ 39 | /** Read the 'info' data following the u1tag byte. */ 40 | protected void readInfo(DataInput din) throws java.io.IOException 41 | { 42 | u4highBytes = din.readInt(); 43 | u4lowBytes = din.readInt(); 44 | } 45 | 46 | /** Write the 'info' data following the u1tag byte. */ 47 | protected void writeInfo(DataOutput dout) throws java.io.IOException 48 | { 49 | dout.writeInt(u4highBytes); 50 | dout.writeInt(u4lowBytes); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/MethodHandleCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a 'methodhandle' entry in the ConstantPool. 9 | * 10 | * @author Sebastian Rheinnecker, yworks 11 | */ 12 | public class MethodHandleCpInfo extends CpInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | private int u1referenceKind; 18 | private int u2referenceIndex; 19 | 20 | // Class Methods --------------------------------------------------------- 21 | 22 | 23 | /** 24 | * Instantiates a new Method handle cp info. 25 | */ 26 | protected MethodHandleCpInfo() 27 | { 28 | super(CONSTANT_MethodHandle); 29 | } 30 | 31 | // Instance Methods ------------------------------------------------------ 32 | protected void readInfo(DataInput din) throws IOException { 33 | u1referenceKind = din.readUnsignedByte(); 34 | u2referenceIndex = din.readUnsignedShort(); 35 | } 36 | 37 | protected void writeInfo(DataOutput dout) throws IOException { 38 | dout.writeByte(u1referenceKind); 39 | dout.writeShort(u2referenceIndex); 40 | } 41 | 42 | /** 43 | * Gets reference kind. 44 | * 45 | * @return the reference kind 46 | */ 47 | protected int getReferenceKind() { 48 | return u1referenceKind; 49 | } 50 | 51 | /** 52 | * Gets reference index. 53 | * 54 | * @return the reference index 55 | */ 56 | protected int getReferenceIndex() { 57 | return u2referenceIndex; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/MethodInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.*; 11 | 12 | /** 13 | * Representation of a method from a class-file. 14 | * 15 | * @author Mark Welsh 16 | */ 17 | public class MethodInfo extends ClassItemInfo 18 | { 19 | // Constants ------------------------------------------------------------- 20 | 21 | 22 | // Fields ---------------------------------------------------------------- 23 | 24 | 25 | // Class Methods --------------------------------------------------------- 26 | 27 | /** 28 | * Create a new MethodInfo from the file format data in the DataInput stream. 29 | * 30 | * @param din the din 31 | * @param cf the cf 32 | * @return the method info 33 | * @throws IOException if class file is corrupt or incomplete 34 | */ 35 | public static MethodInfo create(DataInput din, ClassFile cf) throws java.io.IOException 36 | { 37 | if (din == null) throw new NullPointerException("No input stream was provided."); 38 | MethodInfo mi = new MethodInfo(cf); 39 | mi.read(din); 40 | return mi; 41 | } 42 | 43 | 44 | /** 45 | * Instantiates a new Method info. 46 | * 47 | * @param cf the cf 48 | */ 49 | protected MethodInfo(ClassFile cf) {super(cf);} 50 | 51 | // Instance Methods ------------------------------------------------------ 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/MethodParameter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a method parameter struct in the method parameters 9 | * attribute section. 10 | * 11 | * @author Thomas Behr 12 | */ 13 | public class MethodParameter { 14 | /** 15 | * Reference to {@link Utf8CpInfo} or {@code 0}. 16 | */ 17 | final int u2nameIndex; 18 | /** 19 | * Access flags value 20 | */ 21 | final int u2accessFlags; 22 | 23 | private MethodParameter( final int index, final int flags ) { 24 | this.u2nameIndex = index; 25 | this.u2accessFlags = flags; 26 | } 27 | 28 | /** 29 | * Read method parameter. 30 | * 31 | * @param din the din 32 | * @return the method parameter 33 | * @throws IOException the io exception 34 | */ 35 | static MethodParameter read( final DataInput din ) throws IOException { 36 | final int index = din.readUnsignedShort(); 37 | final int flags = din.readUnsignedShort(); 38 | return new MethodParameter(index, flags); 39 | } 40 | 41 | /** 42 | * Write. 43 | * 44 | * @param dout the dout 45 | * @throws IOException the io exception 46 | */ 47 | void write( final DataOutput dout ) throws IOException { 48 | dout.writeShort(u2nameIndex); 49 | dout.writeShort(u2accessFlags); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/MethodTypeCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a 'methodtype' entry in the ConstantPool. 9 | * 10 | * @author Sebastian Rheinnecker, yworks 11 | */ 12 | public class MethodTypeCpInfo extends CpInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | private int u2descriptorIndex; 18 | 19 | // Class Methods --------------------------------------------------------- 20 | 21 | 22 | /** 23 | * Instantiates a new Method type cp info. 24 | */ 25 | protected MethodTypeCpInfo() 26 | { 27 | super(CONSTANT_MethodType); 28 | } 29 | 30 | // Instance Methods ------------------------------------------------------ 31 | protected void readInfo(DataInput din) throws IOException { 32 | u2descriptorIndex = din.readUnsignedShort(); 33 | } 34 | 35 | protected void writeInfo(DataOutput dout) throws IOException { 36 | dout.writeShort(u2descriptorIndex); 37 | } 38 | 39 | /** 40 | * Gets u 2 descriptor index. 41 | * 42 | * @return the u 2 descriptor index 43 | */ 44 | public int getU2descriptorIndex() { 45 | return u2descriptorIndex; 46 | } 47 | 48 | protected void markUtf8Refs(ConstantPool pool) { 49 | pool.incRefCount(this.u2descriptorIndex); 50 | } 51 | 52 | /** 53 | * Sets u 2 descriptor index. 54 | * 55 | * @param u2descriptorIndex the u 2 descriptor index 56 | */ 57 | public void setU2descriptorIndex(int u2descriptorIndex) { 58 | this.u2descriptorIndex = u2descriptorIndex; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/MethodrefCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | /** 11 | * Representation of a 'methodref' entry in the ConstantPool. 12 | * 13 | * @author Mark Welsh 14 | */ 15 | public class MethodrefCpInfo extends RefCpInfo 16 | { 17 | // Constants ------------------------------------------------------------- 18 | 19 | 20 | // Fields ---------------------------------------------------------------- 21 | 22 | 23 | // Class Methods --------------------------------------------------------- 24 | 25 | 26 | /** 27 | * Instantiates a new Methodref cp info. 28 | */ 29 | protected MethodrefCpInfo() 30 | { 31 | super(CONSTANT_Methodref); 32 | } 33 | 34 | // Instance Methods ------------------------------------------------------ 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ModuleCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * Representation of a 'module' entry in the ConstantPool. 5 | * 6 | * @author Thomas Behr 7 | */ 8 | public class ModuleCpInfo extends AbstractTypeCpInfo { 9 | /** 10 | * Instantiates a new Module cp info. 11 | */ 12 | protected ModuleCpInfo() { 13 | super(CONSTANT_Module); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ModuleMainClassAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of the module main class attribute. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class ModuleMainClassAttrInfo extends AttrInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | private int u2mainClassIndex; 18 | 19 | 20 | // Class Methods --------------------------------------------------------- 21 | 22 | 23 | /** 24 | * Instantiates a new Module main class attr info. 25 | * 26 | * @param cf the cf 27 | * @param attrNameIndex the attr name index 28 | * @param attrLength the attr length 29 | */ 30 | ModuleMainClassAttrInfo( 31 | final ClassFile cf, final int attrNameIndex, final int attrLength 32 | ) { 33 | super(cf, attrNameIndex, attrLength); 34 | } 35 | 36 | // Instance Methods ------------------------------------------------------ 37 | /** 38 | * Returns "ModuleMainClass". 39 | */ 40 | protected String getAttrName() { 41 | return ATTR_ModuleMainClass; 42 | } 43 | 44 | /** 45 | * Read the data following the header. 46 | */ 47 | protected void readInfo( final DataInput din ) throws IOException { 48 | u2mainClassIndex = din.readUnsignedShort(); 49 | } 50 | 51 | /** 52 | * Export data following the header to a DataOutput stream. 53 | */ 54 | public void writeInfo( final DataOutput dout ) throws IOException { 55 | dout.writeShort(u2mainClassIndex); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ModuleOpens.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a module opens struct in the module attribute section. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class ModuleOpens { 13 | /** 14 | * Reference to {@link PackageCpInfo} 15 | */ 16 | final int u2opensIndex; 17 | /** 18 | * Access flags value 19 | */ 20 | final int u2opensFlags; 21 | /** 22 | * References to {@link ModuleCpInfo} 23 | */ 24 | final int[] u2opensToIndex; 25 | 26 | private ModuleOpens( final int index, final int flags, final int[] toIndex ) { 27 | this.u2opensIndex = index; 28 | this.u2opensFlags = flags; 29 | this.u2opensToIndex = toIndex; 30 | } 31 | 32 | /** 33 | * Read module opens. 34 | * 35 | * @param din the din 36 | * @return the module opens 37 | * @throws IOException the io exception 38 | */ 39 | static ModuleOpens read( final DataInput din ) throws IOException { 40 | final int index = din.readUnsignedShort(); 41 | final int flags = din.readUnsignedShort(); 42 | final int toCount = din.readUnsignedShort(); 43 | final int[] toIndex = new int[toCount]; 44 | for (int j = 0; j < toCount; ++j) { 45 | toIndex[j] = din.readUnsignedShort(); 46 | } 47 | 48 | return new ModuleOpens(index, flags, toIndex); 49 | } 50 | 51 | /** 52 | * Write. 53 | * 54 | * @param dout the dout 55 | * @throws IOException the io exception 56 | */ 57 | void write( final DataOutput dout ) throws IOException { 58 | dout.writeShort(u2opensIndex); 59 | dout.writeShort(u2opensFlags); 60 | final int u2opensToCount = u2opensToIndex.length; 61 | dout.writeShort(u2opensToCount); 62 | for (int i = 0; i < u2opensToCount; ++i) { 63 | dout.writeShort(u2opensToIndex[i]); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ModulePackagesAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a module packages attribute. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class ModulePackagesAttrInfo extends AttrInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | private int[] u2packageIndex; 18 | 19 | 20 | // Class Methods --------------------------------------------------------- 21 | 22 | 23 | /** 24 | * Instantiates a new Module packages attr info. 25 | * 26 | * @param cf the cf 27 | * @param attrNameIndex the attr name index 28 | * @param attrLength the attr length 29 | */ 30 | ModulePackagesAttrInfo( 31 | final ClassFile cf, final int attrNameIndex, final int attrLength 32 | ) { 33 | super(cf, attrNameIndex, attrLength); 34 | } 35 | 36 | // Instance Methods ------------------------------------------------------ 37 | /** 38 | * Returns "ModulePackages". 39 | */ 40 | protected String getAttrName() { 41 | return ATTR_ModulePackages; 42 | } 43 | 44 | /** 45 | * Read the data following the header. 46 | */ 47 | protected void readInfo( final DataInput din ) throws IOException { 48 | final int u2packageCount = din.readUnsignedShort(); 49 | u2packageIndex = new int[u2packageCount]; 50 | for (int i = 0; i < u2packageCount; ++i) { 51 | u2packageIndex[i] = din.readUnsignedShort(); 52 | } 53 | } 54 | 55 | /** 56 | * Export data following the header to a DataOutput stream. 57 | */ 58 | public void writeInfo( final DataOutput dout ) throws IOException { 59 | final int u2packageCount = u2packageIndex.length; 60 | dout.writeShort(u2packageCount); 61 | for (int i = 0; i < u2packageCount; ++i) { 62 | dout.writeShort(u2packageIndex[i]); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ModuleProvides.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a module provides struct in the module attribute section. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class ModuleProvides { 13 | /** 14 | * Reference to {@link ClassCpInfo} 15 | */ 16 | final int u2providesIndex; 17 | /** 18 | * References to {@link ClassCpInfo} 19 | */ 20 | final int[] u2providesWithIndex; 21 | 22 | private ModuleProvides( final int index, final int[] withIndex ) { 23 | this.u2providesIndex = index; 24 | this.u2providesWithIndex = withIndex; 25 | } 26 | 27 | /** 28 | * Read module provides. 29 | * 30 | * @param din the din 31 | * @return the module provides 32 | * @throws IOException the io exception 33 | */ 34 | static ModuleProvides read( final DataInput din ) throws IOException { 35 | final int index = din.readUnsignedShort(); 36 | final int withCount = din.readUnsignedShort(); 37 | final int[] withIndex = new int[withCount]; 38 | for (int j = 0; j < withCount; ++j) { 39 | withIndex[j] = din.readUnsignedShort(); 40 | } 41 | 42 | return new ModuleProvides(index, withIndex); 43 | } 44 | 45 | /** 46 | * Write. 47 | * 48 | * @param dout the dout 49 | * @throws IOException the io exception 50 | */ 51 | void write( final DataOutput dout ) throws IOException { 52 | dout.writeShort(u2providesIndex); 53 | final int u2providesWithCount = u2providesWithIndex.length; 54 | dout.writeShort(u2providesWithCount); 55 | for (int i = 0; i < u2providesWithCount; ++i) { 56 | dout.writeShort(u2providesWithIndex[i]); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/ModuleRequires.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of a module requires struct in the module attribute section. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class ModuleRequires { 13 | /** 14 | * Reference to {@link ModuleCpInfo} 15 | */ 16 | final int u2requiresIndex; 17 | /** 18 | * Access flags value 19 | */ 20 | final int u2requiresFlags; 21 | /** 22 | * Reference to {@link Utf8CpInfo} 23 | */ 24 | final int u2requiresVersionIndex; 25 | 26 | private ModuleRequires( final int index, final int flags, final int versionIndex ) { 27 | this.u2requiresIndex = index; 28 | this.u2requiresFlags = flags; 29 | this.u2requiresVersionIndex = versionIndex; 30 | } 31 | 32 | /** 33 | * Read module requires. 34 | * 35 | * @param din the din 36 | * @return the module requires 37 | * @throws IOException the io exception 38 | */ 39 | static ModuleRequires read( final DataInput din ) throws IOException { 40 | final int index = din.readUnsignedShort(); 41 | final int flags = din.readUnsignedShort(); 42 | final int versionIndex = din.readUnsignedShort(); 43 | return new ModuleRequires(index, flags, versionIndex); 44 | } 45 | 46 | /** 47 | * Write. 48 | * 49 | * @param dout the dout 50 | * @throws IOException the io exception 51 | */ 52 | void write( final DataOutput dout ) throws IOException { 53 | dout.writeShort(u2requiresIndex); 54 | dout.writeShort(u2requiresFlags); 55 | dout.writeShort(u2requiresVersionIndex); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/NestHostAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of the nest host attribute. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class NestHostAttrInfo extends AttrInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | private int u2hostClassIndex; 18 | 19 | 20 | // Class Methods --------------------------------------------------------- 21 | 22 | 23 | /** 24 | * Instantiates a new Nest host attr info. 25 | * 26 | * @param cf the cf 27 | * @param attrNameIndex the attr name index 28 | * @param attrLength the attr length 29 | */ 30 | NestHostAttrInfo( 31 | final ClassFile cf, final int attrNameIndex, final int attrLength 32 | ) { 33 | super(cf, attrNameIndex, attrLength); 34 | } 35 | 36 | // Instance Methods ------------------------------------------------------ 37 | /** 38 | * Returns "NestHost". 39 | */ 40 | protected String getAttrName() { 41 | return ATTR_NestHost; 42 | } 43 | 44 | /** 45 | * Read the data following the header. 46 | */ 47 | protected void readInfo( final DataInput din ) throws IOException { 48 | u2hostClassIndex = din.readUnsignedShort(); 49 | } 50 | 51 | /** 52 | * Export data following the header to a DataOutput stream. 53 | */ 54 | public void writeInfo( final DataOutput dout ) throws IOException { 55 | dout.writeShort(u2hostClassIndex); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/NestMembersAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of the nest members attribute. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class NestMembersAttrInfo extends AttrInfo { 13 | // Constants ------------------------------------------------------------- 14 | 15 | 16 | // Fields ---------------------------------------------------------------- 17 | private int[] u2classes; 18 | 19 | 20 | // Class Methods --------------------------------------------------------- 21 | 22 | 23 | /** 24 | * Instantiates a new Nest members attr info. 25 | * 26 | * @param cf the cf 27 | * @param attrNameIndex the attr name index 28 | * @param attrLength the attr length 29 | */ 30 | NestMembersAttrInfo( 31 | final ClassFile cf, final int attrNameIndex, final int attrLength 32 | ) { 33 | super(cf, attrNameIndex, attrLength); 34 | } 35 | 36 | // Instance Methods ------------------------------------------------------ 37 | /** 38 | * Returns "NestMembers". 39 | */ 40 | protected String getAttrName() { 41 | return ATTR_NestMembers; 42 | } 43 | 44 | /** 45 | * Read the data following the header. 46 | */ 47 | protected void readInfo( final DataInput din ) throws IOException { 48 | final int u2numberOfClasses = din.readUnsignedShort(); 49 | u2classes = new int[u2numberOfClasses]; 50 | for (int i = 0; i < u2numberOfClasses; ++i) { 51 | u2classes[i] = din.readUnsignedShort(); 52 | } 53 | } 54 | 55 | /** 56 | * Export data following the header to a DataOutput stream. 57 | */ 58 | public void writeInfo( final DataOutput dout ) throws IOException { 59 | final int u2numberOfClasses = u2classes.length; 60 | dout.writeShort(u2numberOfClasses); 61 | for (int i = 0; i < u2numberOfClasses; ++i) { 62 | dout.writeShort(u2classes[i]); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/PackageCpInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * Representation of a 'package' entry in the ConstantPool. 5 | * 6 | * @author Thomas Behr 7 | */ 8 | public class PackageCpInfo extends AbstractTypeCpInfo { 9 | /** 10 | * Instantiates a new Package cp info. 11 | */ 12 | protected PackageCpInfo() { 13 | super(CONSTANT_Package); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/PermittedSubclassesAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | import java.io.DataInput; 4 | import java.io.DataOutput; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Representation of the permitted subclasses attribute. 9 | * 10 | * @author Thomas Behr 11 | */ 12 | public class PermittedSubclassesAttrInfo extends AttrInfo { 13 | private int[] u2classes; 14 | 15 | /** 16 | * Instantiates a new permitted subclasses attribute info. 17 | */ 18 | PermittedSubclassesAttrInfo( 19 | final ClassFile cf, final int attrNameIndex, final int attrLength 20 | ) { 21 | super(cf, attrNameIndex, attrLength); 22 | u2classes = new int[0]; 23 | } 24 | 25 | // Instance Methods ------------------------------------------------------ 26 | /** 27 | * Returns "PermittedSubclasses". 28 | */ 29 | protected String getAttrName() { 30 | return ATTR_PermittedSubclasses; 31 | } 32 | 33 | /** 34 | * Read the data following the header. 35 | */ 36 | protected void readInfo( final DataInput din ) throws IOException { 37 | final int u2numberOfClasses = din.readUnsignedShort(); 38 | u2classes = new int[u2numberOfClasses]; 39 | for (int i = 0; i < u2numberOfClasses; ++i) { 40 | u2classes[i] = din.readUnsignedShort(); 41 | } 42 | } 43 | 44 | /** 45 | * Export data following the header to a DataOutput stream. 46 | */ 47 | public void writeInfo( final DataOutput dout ) throws IOException { 48 | final int u2numberOfClasses = u2classes.length; 49 | dout.writeShort(u2numberOfClasses); 50 | for (int i = 0; i < u2numberOfClasses; ++i) { 51 | dout.writeShort(u2classes[i]); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/RuntimeInvisibleAnnotationsAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * The type Runtime invisible annotations attr info. 5 | * 6 | * @author muellese 7 | */ 8 | public class RuntimeInvisibleAnnotationsAttrInfo extends RuntimeVisibleAnnotationsAttrInfo 9 | { 10 | /** 11 | * Creates a new instance of RuntimeVisibleAnnotationsAttrInfo 12 | * 13 | * @param cf the cf 14 | * @param attrNameIndex the attr name index 15 | * @param attrLength the attr length 16 | */ 17 | public RuntimeInvisibleAnnotationsAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 18 | { 19 | super(cf, attrNameIndex, attrLength); 20 | } 21 | 22 | protected String getAttrName() 23 | { 24 | return ClassConstants.ATTR_RuntimeInvisibleAnnotations; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/RuntimeInvisibleParameterAnnotationsAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * The type Runtime invisible parameter annotations attr info. 5 | * 6 | * @author muellese 7 | */ 8 | public class RuntimeInvisibleParameterAnnotationsAttrInfo extends RuntimeVisibleParameterAnnotationsAttrInfo 9 | { 10 | 11 | /** 12 | * Creates a new instance of RuntimeInvisibleParameterAnnotationsAttrInfo 13 | * 14 | * @param cf the cf 15 | * @param attrNameIndex the attr name index 16 | * @param attrLength the attr length 17 | */ 18 | public RuntimeInvisibleParameterAnnotationsAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 19 | { 20 | super(cf, attrNameIndex, attrLength); 21 | } 22 | 23 | protected String getAttrName() 24 | { 25 | return ClassConstants.ATTR_RuntimeInvisibleParameterAnnotations; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/RuntimeInvisibleTypeAnnotationsAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * The type Runtime invisible type annotations attr info. 5 | * 6 | * @author mfk 7 | */ 8 | public class RuntimeInvisibleTypeAnnotationsAttrInfo extends RuntimeVisibleTypeAnnotationsAttrInfo { 9 | 10 | /** 11 | * Instantiates a new Runtime invisible type annotations attr info. 12 | * 13 | * @param cf the cf 14 | * @param attrNameIndex the attr name index 15 | * @param attrLength the attr length 16 | */ 17 | public RuntimeInvisibleTypeAnnotationsAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) { 18 | super(cf, attrNameIndex, attrLength); 19 | } 20 | 21 | protected String getAttrName() { 22 | return ClassConstants.ATTR_RuntimeInvisibleTypeAnnotations; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/RuntimeVisibleParameterAnnotationsAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * The type Runtime visible parameter annotations attr info. 5 | * 6 | * @author muellese 7 | */ 8 | public class RuntimeVisibleParameterAnnotationsAttrInfo extends AttrInfo 9 | { 10 | private int u1parameterCount; 11 | private ParameterAnnotationInfo[] annotations; 12 | 13 | /** 14 | * Creates a new instance of RuntimeVisibleParameterAnnotationsAttrInfo 15 | * 16 | * @param cf the cf 17 | * @param attrNameIndex the attr name index 18 | * @param attrLength the attr length 19 | */ 20 | public RuntimeVisibleParameterAnnotationsAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 21 | { 22 | super(cf, attrNameIndex, attrLength); 23 | } 24 | 25 | /** 26 | * Get parameter annotations parameter annotation info [ ]. 27 | * 28 | * @return the parameter annotation info [ ] 29 | */ 30 | protected ParameterAnnotationInfo[] getParameterAnnotations(){ 31 | return annotations; 32 | } 33 | 34 | protected String getAttrName() 35 | { 36 | return ClassConstants.ATTR_RuntimeVisibleParameterAnnotations; 37 | } 38 | 39 | public void writeInfo(java.io.DataOutput dout) throws java.io.IOException 40 | { 41 | dout.writeByte(u1parameterCount); 42 | for (int i = 0; i < u1parameterCount; i++){ 43 | annotations[i].write(dout); 44 | } 45 | } 46 | 47 | protected void markUtf8RefsInInfo(ConstantPool pool) { 48 | for (int i = 0; i < u1parameterCount; i++){ 49 | annotations[i].markUtf8RefsInInfo(pool); 50 | } 51 | } 52 | 53 | 54 | protected void readInfo(java.io.DataInput din) throws java.io.IOException 55 | { 56 | u1parameterCount = din.readUnsignedByte(); 57 | annotations = new ParameterAnnotationInfo[u1parameterCount]; 58 | for (int i = 0; i < u1parameterCount; i++){ 59 | annotations[i] = ParameterAnnotationInfo.create(din); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/RuntimeVisibleTypeAnnotationsAttrInfo.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.classfile; 2 | 3 | /** 4 | * The type Runtime visible type annotations attr info. 5 | * 6 | * @author mfk 7 | */ 8 | public class RuntimeVisibleTypeAnnotationsAttrInfo extends AttrInfo { 9 | private int u2AnnotationCount; 10 | private TypeAnnotationInfo[] annotations; 11 | 12 | /** 13 | * Instantiates a new Runtime visible type annotations attr info. 14 | * 15 | * @param cf the cf 16 | * @param attrNameIndex the attr name index 17 | * @param attrLength the attr length 18 | */ 19 | public RuntimeVisibleTypeAnnotationsAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) { 20 | super(cf, attrNameIndex, attrLength); 21 | } 22 | 23 | protected String getAttrName() { 24 | return ClassConstants.ATTR_RuntimeVisibleTypeAnnotations; 25 | } 26 | 27 | /** 28 | * Get annotations type annotation info [ ]. 29 | * 30 | * @return the type annotation info [ ] 31 | */ 32 | public TypeAnnotationInfo[] getAnnotations() { 33 | return annotations; 34 | } 35 | 36 | /** 37 | * Gets owner. 38 | * 39 | * @return the owner 40 | */ 41 | public ClassFile getOwner() { 42 | return owner; 43 | } 44 | 45 | public void writeInfo(java.io.DataOutput dout) throws java.io.IOException { 46 | dout.writeShort(u2AnnotationCount); 47 | for (int i = 0; i < u2AnnotationCount; i++) { 48 | annotations[i].write(dout); 49 | } 50 | } 51 | 52 | protected void readInfo(java.io.DataInput din) throws java.io.IOException { 53 | u2AnnotationCount = din.readUnsignedShort(); 54 | annotations = new TypeAnnotationInfo[u2AnnotationCount]; 55 | for (int i = 0; i < u2AnnotationCount; i++) { 56 | annotations[i] = TypeAnnotationInfo.create(din); 57 | } 58 | } 59 | 60 | protected void markUtf8RefsInInfo(ConstantPool pool) { 61 | for (int i = 0; i < u2AnnotationCount; i++) { 62 | annotations[i].markUtf8RefsInInfo(pool); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/StringCpInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.DataInput; 11 | import java.io.DataOutput; 12 | 13 | /** 14 | * Representation of a 'string' entry in the ConstantPool. 15 | * 16 | * @author Mark Welsh 17 | */ 18 | public class StringCpInfo extends CpInfo 19 | { 20 | // Constants ------------------------------------------------------------- 21 | 22 | 23 | // Fields ---------------------------------------------------------------- 24 | private int u2stringIndex; 25 | 26 | 27 | // Class Methods --------------------------------------------------------- 28 | 29 | 30 | /** 31 | * Instantiates a new String cp info. 32 | */ 33 | protected StringCpInfo() 34 | { 35 | super(CONSTANT_String); 36 | } 37 | 38 | public int getStringIndex() { 39 | return u2stringIndex; 40 | } 41 | 42 | public void setStringIndex( final int stringIndex ) { 43 | u2stringIndex = stringIndex; 44 | } 45 | 46 | // Instance Methods ------------------------------------------------------ 47 | /** Check for Utf8 references to constant pool and mark them. */ 48 | protected void markUtf8Refs(ConstantPool pool) 49 | { 50 | pool.incRefCount(u2stringIndex); 51 | } 52 | 53 | /** Read the 'info' data following the u1tag byte. */ 54 | protected void readInfo(DataInput din) throws java.io.IOException 55 | { 56 | u2stringIndex = din.readUnsignedShort(); 57 | } 58 | 59 | /** Write the 'info' data following the u1tag byte. */ 60 | protected void writeInfo(DataOutput dout) throws java.io.IOException 61 | { 62 | dout.writeShort(u2stringIndex); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/obf/classfile/SyntheticAttrInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YGuard -- an obfuscation library for Java(TM) classfiles. 3 | * 4 | * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com) 5 | * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com) 6 | * 7 | */ 8 | package com.yworks.yguard.obf.classfile; 9 | 10 | import java.io.DataInput; 11 | import java.io.DataOutput; 12 | 13 | /** 14 | * Representation of an attribute. 15 | * 16 | * @author Mark Welsh 17 | */ 18 | public class SyntheticAttrInfo extends AttrInfo 19 | { 20 | // Constants ------------------------------------------------------------- 21 | 22 | 23 | // Fields ---------------------------------------------------------------- 24 | 25 | 26 | // Class Methods --------------------------------------------------------- 27 | 28 | 29 | /** 30 | * Instantiates a new Synthetic attr info. 31 | * 32 | * @param cf the cf 33 | * @param attrNameIndex the attr name index 34 | * @param attrLength the attr length 35 | */ 36 | protected SyntheticAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 37 | { 38 | super(cf, attrNameIndex, attrLength); 39 | } 40 | 41 | // Instance Methods ------------------------------------------------------ 42 | /** Return the String name of the attribute. */ 43 | protected String getAttrName() 44 | { 45 | return ATTR_Synthetic; 46 | } 47 | 48 | /** Read the data following the header. */ 49 | protected void readInfo(DataInput din) {} 50 | 51 | /** Export data following the header to a DataOutput stream. */ 52 | public void writeInfo(DataOutput dout) {} 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yguard/yguard.properties: -------------------------------------------------------------------------------- 1 | obfuscate=com.yworks.yguard.ObfuscatorTask -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/YShrinkInvoker.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink; 2 | 3 | import com.yworks.common.ant.EntryPointsSection; 4 | import com.yworks.common.ShrinkBag; 5 | import com.yworks.yguard.ant.MethodSection; 6 | import com.yworks.yguard.ant.ClassSection; 7 | import com.yworks.yguard.ant.FieldSection; 8 | import org.apache.tools.ant.Task; 9 | import org.apache.tools.ant.types.Path; 10 | 11 | import java.io.File; 12 | 13 | /** 14 | * The interface Y shrink invoker. 15 | * 16 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 17 | */ 18 | public interface YShrinkInvoker { 19 | 20 | /** 21 | * Execute. 22 | */ 23 | public void execute(); 24 | 25 | /** 26 | * Add pair. 27 | * 28 | * @param pair the pair 29 | */ 30 | public void addPair( ShrinkBag pair ); 31 | 32 | /** 33 | * Sets resource class path. 34 | * 35 | * @param path the path 36 | */ 37 | public void setResourceClassPath( Path path ); 38 | 39 | /** 40 | * Add class section. 41 | * 42 | * @param cs the cs 43 | */ 44 | public void addClassSection( ClassSection cs ); 45 | 46 | /** 47 | * Add method section. 48 | * 49 | * @param ms the ms 50 | */ 51 | void addMethodSection( MethodSection ms ); 52 | 53 | /** 54 | * Add field section. 55 | * 56 | * @param fs the fs 57 | */ 58 | void addFieldSection( FieldSection fs ); 59 | 60 | /** 61 | * Sets enty points. 62 | * 63 | * @param eps the eps 64 | */ 65 | void setEntyPoints( EntryPointsSection eps ); 66 | 67 | /** 68 | * Sets log file. 69 | * 70 | * @param shrinkLog the shrink log 71 | */ 72 | void setLogFile( File shrinkLog ); 73 | 74 | /** 75 | * Sets context. 76 | * 77 | * @param task the task 78 | */ 79 | void setContext(Task task); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/YShrinkModel.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink; 2 | 3 | import com.yworks.common.ShrinkBag; 4 | import org.apache.tools.ant.Task; 5 | import org.apache.tools.ant.types.Path; 6 | 7 | import java.util.List; 8 | import java.util.Collection; 9 | import java.util.Set; 10 | import java.io.IOException; 11 | 12 | /** 13 | * The interface Y shrink model. 14 | * 15 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 16 | */ 17 | public interface YShrinkModel { 18 | 19 | /** 20 | * Create simple model. 21 | * 22 | * @param bags the bags 23 | * @throws IOException the io exception 24 | */ 25 | public void createSimpleModel( List bags ) throws IOException; 26 | 27 | /** 28 | * Gets all ancestor classes. 29 | * 30 | * @param className the class name 31 | * @return the all ancestor classes 32 | */ 33 | Set getAllAncestorClasses( String className ); 34 | 35 | /** 36 | * Gets all implemented interfaces. 37 | * 38 | * @param className the class name 39 | * @return the all implemented interfaces 40 | */ 41 | Set getAllImplementedInterfaces( String className ); 42 | 43 | /** 44 | * Gets all class names. 45 | * 46 | * @return the all class names 47 | */ 48 | Collection getAllClassNames(); 49 | 50 | /** 51 | * Sets resource class path. 52 | * 53 | * @param resourceClassPath the resource class path 54 | * @param target the target 55 | */ 56 | void setResourceClassPath(Path resourceClassPath, Task target); 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/YShrinkModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink; 2 | 3 | import com.yworks.common.ShrinkBag; 4 | import com.yworks.yshrink.ant.ResourceCpResolver; 5 | import com.yworks.yshrink.model.Model; 6 | import com.yworks.yshrink.core.Analyzer; 7 | import org.apache.tools.ant.Task; 8 | import org.apache.tools.ant.types.Path; 9 | 10 | import java.util.Collection; 11 | import java.util.Set; 12 | import java.util.HashSet; 13 | import java.util.List; 14 | import java.io.IOException; 15 | 16 | /** 17 | * The type Y shrink model. 18 | * 19 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 20 | */ 21 | public class YShrinkModelImpl implements YShrinkModel { 22 | 23 | /** 24 | * The Model. 25 | */ 26 | Model model; 27 | 28 | /** 29 | * Instantiates a new Y shrink model. 30 | */ 31 | public YShrinkModelImpl() { 32 | model = new Model(); 33 | } 34 | 35 | public void createSimpleModel( List bags ) throws IOException { 36 | 37 | Analyzer analyzer = new Analyzer(); 38 | analyzer.initModel( model, bags ); 39 | analyzer.createInheritanceEdges( model ); 40 | 41 | } 42 | 43 | public Set getAllAncestorClasses( String className ) { 44 | Set parents = new HashSet( 3 ); 45 | model.getAllAncestorClasses( className, parents ); 46 | return parents; 47 | } 48 | 49 | public Set getAllImplementedInterfaces( String className ) { 50 | Set interfaces = new HashSet( 3 ); 51 | model.getAllImplementedInterfaces( className, interfaces ); 52 | return interfaces; 53 | } 54 | 55 | public Collection getAllClassNames() { 56 | return model.getAllClassNames(); 57 | } 58 | 59 | public void setResourceClassPath(Path resourceClassPath, Task target) { 60 | ResourceCpResolver resourceCpResolver = new ResourceCpResolver(resourceClassPath, target); 61 | model.setClassResolver(resourceCpResolver); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/AntLogger.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant; 2 | 3 | import com.yworks.logging.Logger; 4 | import org.apache.tools.ant.Project; 5 | import org.apache.tools.ant.Task; 6 | 7 | /** 8 | * The type Ant logger. 9 | * 10 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 11 | */ 12 | public class AntLogger extends Logger { 13 | 14 | private final Task task; 15 | private final Project project; 16 | 17 | /** 18 | * Instantiates a new Ant logger. 19 | * 20 | * @param project the project 21 | * @param task the task 22 | */ 23 | public AntLogger( final Project project, final Task task ) { 24 | this.project = project; 25 | this.task = task; 26 | register(); 27 | } 28 | 29 | public void doLog( final String s ) { 30 | project.log( task, s, Project.MSG_INFO ); 31 | } 32 | 33 | public void doErr( final String s ) { 34 | project.log( task, "ERROR: "+s, Project.MSG_ERR ); 35 | } 36 | 37 | public void doWarn( String s ) { 38 | //project.log( task, "WARNING: "+s, Project.MSG_WARN ); 39 | } 40 | 41 | public void doWarnToLog( String s ) { 42 | } 43 | 44 | public void doShrinkLog( String s ) { 45 | // project.log( s, Project.MSG_INFO ); 46 | } 47 | 48 | public void doErr( String s, Throwable ex ) { 49 | project.log( task, "ERROR: "+s + "\n" + ex.getMessage(), Project.MSG_ERR ); 50 | } 51 | 52 | public void close() { 53 | unregister(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/filters/AbstractEntryPointFilter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant.filters; 2 | 3 | import com.yworks.yshrink.model.ClassDescriptor; 4 | import com.yworks.yshrink.model.FieldDescriptor; 5 | import com.yworks.yshrink.model.MethodDescriptor; 6 | import com.yworks.yshrink.model.Model; 7 | 8 | /** 9 | * The type Abstract entry point filter. 10 | * 11 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 12 | */ 13 | public class AbstractEntryPointFilter implements EntryPointFilter { 14 | 15 | public boolean isEntryPointClass( final Model model, final ClassDescriptor cd ) { 16 | return false; 17 | } 18 | 19 | public boolean isEntryPointMethod( final Model model, final ClassDescriptor cd, final MethodDescriptor md ) { 20 | return false; 21 | } 22 | 23 | public boolean isEntryPointField( final Model model, final ClassDescriptor cd, final FieldDescriptor fd ) { 24 | return false; 25 | } 26 | 27 | public void setRetainAttribute( final ClassDescriptor cd ) { 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/filters/AllMainMethodsFilter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant.filters; 2 | 3 | import com.yworks.yshrink.model.ClassDescriptor; 4 | import com.yworks.yshrink.model.MethodDescriptor; 5 | import com.yworks.yshrink.model.Model; 6 | import com.yworks.logging.Logger; 7 | 8 | /** 9 | * marks all main methods as entry points 10 | * 11 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 12 | */ 13 | public class AllMainMethodsFilter extends AbstractEntryPointFilter { 14 | 15 | /** 16 | * The Main desc. 17 | */ 18 | static String MAIN_DESC = "([Ljava/lang/String;)V"; 19 | 20 | @Override 21 | public boolean isEntryPointMethod( final Model model, final ClassDescriptor cd, final MethodDescriptor md ) { 22 | 23 | if ( "main".equals( md.getName() ) ) { 24 | Logger.log( "MainMethodFilter: main found in " + cd.getName() ); 25 | return true; 26 | } else { 27 | return false; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/filters/AttributeFilter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant.filters; 2 | 3 | import com.yworks.common.ant.AttributesSection; 4 | import com.yworks.yshrink.model.ClassDescriptor; 5 | import com.yworks.yshrink.util.Util; 6 | import com.yworks.common.ant.TypePatternSet; 7 | 8 | import java.util.List; 9 | import java.util.ArrayList; 10 | 11 | import org.apache.tools.ant.Project; 12 | 13 | /** 14 | * The type Attribute filter. 15 | * 16 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 17 | */ 18 | public class AttributeFilter extends PatternMatchedFilter { 19 | 20 | private List sections = new ArrayList( ); 21 | 22 | /** 23 | * Instantiates a new Attribute filter. 24 | * 25 | * @param p the p 26 | */ 27 | public AttributeFilter( Project p ) { 28 | super( p ); 29 | } 30 | 31 | /** 32 | * Add attributes section. 33 | * 34 | * @param as the as 35 | */ 36 | public void addAttributesSection( AttributesSection as ) { 37 | sections.add( as ); 38 | } 39 | 40 | public void setRetainAttribute( ClassDescriptor cd ) { 41 | 42 | String className = cd.getName(); 43 | String javaClassName = Util.toJavaClass( cd.getName() ); 44 | 45 | for ( AttributesSection section : sections ) { 46 | if ( match( TypePatternSet.Type.NAME, javaClassName, section ) || 47 | match( TypePatternSet.Type.NAME, className, section ) ) { 48 | 49 | for ( String attr : section.getAttributes() ) { 50 | cd.setRetainAttribute( attr ); 51 | } 52 | } 53 | } 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/filters/EntryPointFilter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant.filters; 2 | 3 | import com.yworks.yshrink.model.ClassDescriptor; 4 | import com.yworks.yshrink.model.FieldDescriptor; 5 | import com.yworks.yshrink.model.MethodDescriptor; 6 | import com.yworks.yshrink.model.Model; 7 | 8 | /** 9 | * The interface Entry point filter. 10 | * 11 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 12 | */ 13 | public interface EntryPointFilter { 14 | 15 | /** 16 | * Is entry point class boolean. 17 | * 18 | * @param model the model 19 | * @param cd the cd 20 | * @return the boolean 21 | */ 22 | public boolean isEntryPointClass( final Model model, final ClassDescriptor cd ); 23 | 24 | /** 25 | * Is entry point method boolean. 26 | * 27 | * @param model the model 28 | * @param cd the cd 29 | * @param md the md 30 | * @return the boolean 31 | */ 32 | public boolean isEntryPointMethod( final Model model, final ClassDescriptor cd, final MethodDescriptor md ); 33 | 34 | /** 35 | * Is entry point field boolean. 36 | * 37 | * @param model the model 38 | * @param cd the cd 39 | * @param fd the fd 40 | * @return the boolean 41 | */ 42 | public boolean isEntryPointField( final Model model, final ClassDescriptor cd, final FieldDescriptor fd ); 43 | 44 | /** 45 | * Sets retain attribute. 46 | * 47 | * @param cd the cd 48 | */ 49 | public void setRetainAttribute( final ClassDescriptor cd ); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/filters/EntryPointJarFilter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant.filters; 2 | 3 | import com.yworks.common.ant.EntryPointJar; 4 | import com.yworks.yshrink.model.ClassDescriptor; 5 | import com.yworks.yshrink.model.FieldDescriptor; 6 | import com.yworks.yshrink.model.MethodDescriptor; 7 | import com.yworks.yshrink.model.Model; 8 | 9 | /** 10 | * The type Entry point jar filter. 11 | * 12 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 13 | */ 14 | public class EntryPointJarFilter extends AbstractEntryPointFilter { 15 | 16 | private final EntryPointJar entryPointJar; 17 | 18 | /** 19 | * Instantiates a new Entry point jar filter. 20 | * 21 | * @param entryPointJar the entry point jar 22 | */ 23 | public EntryPointJarFilter( EntryPointJar entryPointJar ) { 24 | this.entryPointJar = entryPointJar; 25 | } 26 | 27 | @Override 28 | public boolean isEntryPointClass( final Model model, final ClassDescriptor cd ) { 29 | return cd.getSourceJar().equals( entryPointJar.getIn() ); 30 | } 31 | 32 | @Override 33 | public boolean isEntryPointMethod( final Model model, final ClassDescriptor cd, final MethodDescriptor md ) { 34 | return md.getSourceJar().equals( entryPointJar.getIn() ); 35 | } 36 | 37 | @Override 38 | public boolean isEntryPointField( final Model model, final ClassDescriptor cd, final FieldDescriptor fd ) { 39 | return fd.getSourceJar().equals( entryPointJar.getIn() ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/ant/filters/SerializationFilter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant.filters; 2 | 3 | import org.apache.tools.ant.Project; 4 | import com.yworks.yshrink.ant.MethodSection; 5 | import com.yworks.yshrink.model.Model; 6 | import com.yworks.yshrink.model.ClassDescriptor; 7 | import com.yworks.yshrink.model.MethodDescriptor; 8 | 9 | import java.util.Collection; 10 | 11 | /** 12 | * The type Serialization filter. 13 | * 14 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 15 | */ 16 | public class SerializationFilter extends MethodFilter { 17 | 18 | /** 19 | * Instantiates a new Serialization filter. 20 | * 21 | * @param project the project 22 | */ 23 | public SerializationFilter( Project project ) { 24 | super( project ); 25 | 26 | MethodSection msWrite = new MethodSection(); 27 | msWrite.setSignature( "void writeObject(java.io.ObjectOutputStream)" ); 28 | msWrite.setAccess( "private" ); 29 | addMethodSection( msWrite ); 30 | 31 | MethodSection msRead = new MethodSection(); 32 | msRead.setSignature( "void readObject(java.io.ObjectInputStream)" ); 33 | msRead.setAccess( "private" ); 34 | addMethodSection( msRead ); 35 | 36 | } 37 | 38 | @Override 39 | public boolean isEntryPointMethod( final Model model, final ClassDescriptor cd, final MethodDescriptor md ) { 40 | 41 | boolean r = false; 42 | 43 | Collection interfaces = cd.getAllImplementedInterfaces( model ); 44 | if ( interfaces.contains( "java/io/Serializable" ) ) { 45 | r = true; 46 | } 47 | 48 | return r && super.isEntryPointMethod( model, cd, md ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/core/ClassResolver.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.core; 2 | 3 | /** 4 | * The interface Class resolver. 5 | * 6 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 7 | */ 8 | public interface ClassResolver extends AutoCloseable { 9 | 10 | /** 11 | * Resolve class. 12 | * 13 | * @param className the class name 14 | * @return the class 15 | * @throws ClassNotFoundException the class not found exception 16 | */ 17 | Class resolve(String className) throws ClassNotFoundException; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/core/DirectoryWriter.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.core; 2 | 3 | import com.yworks.util.abstractjar.impl.DirectoryWriterImpl; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.jar.Manifest; 8 | 9 | /** 10 | * Placeholder for a directory writer with support for digests. 11 | * 12 | * @author Thomas Behr 13 | */ 14 | class DirectoryWriter extends DirectoryWriterImpl { 15 | DirectoryWriter( 16 | final File outFile, final Manifest manifest 17 | ) throws IOException { 18 | super(outFile, manifest); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/core/URLCpResolver.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.core; 2 | 3 | import java.net.URL; 4 | import java.net.URLClassLoader; 5 | 6 | /** 7 | * The type Url cp resolver. 8 | * 9 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 10 | */ 11 | public class URLCpResolver implements ClassResolver { 12 | 13 | /** 14 | * The Url class loader. 15 | */ 16 | URLClassLoader urlClassLoader; 17 | 18 | /** 19 | * Instantiates a new Url cp resolver. 20 | * 21 | * @param urls the urls 22 | */ 23 | public URLCpResolver( final URL[] urls ) { 24 | urlClassLoader = URLClassLoader.newInstance( urls, ClassLoader.getSystemClassLoader() ); 25 | } 26 | 27 | public Class resolve( final String className ) throws ClassNotFoundException { 28 | try { 29 | return Class.forName( className, false, urlClassLoader ); 30 | } catch ( NoClassDefFoundError ncdfe ) { 31 | String message = ncdfe.getMessage(); 32 | if ( message == null || message.equals( className ) ) { 33 | message = className; 34 | } else { 35 | message = message + "[" + className + "]"; 36 | } 37 | throw new ClassNotFoundException( message, ncdfe ); 38 | } catch ( LinkageError le ) { 39 | throw new ClassNotFoundException( className, le ); 40 | } 41 | } 42 | 43 | @Override 44 | public void close() throws Exception { 45 | urlClassLoader.close(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/model/AnnotationUsage.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.model; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | 6 | /** 7 | * The type Annotation usage. 8 | * 9 | * @author schroede 10 | */ 11 | public class AnnotationUsage { 12 | private String descriptor; 13 | 14 | private List fieldUsages = new ArrayList(); 15 | 16 | /** 17 | * Instantiates a new Annotation usage. 18 | * 19 | * @param descriptor the descriptor 20 | */ 21 | public AnnotationUsage(String descriptor) { 22 | this.descriptor = descriptor; 23 | } 24 | 25 | /** 26 | * Add field usage. 27 | * 28 | * @param name the name 29 | */ 30 | public void addFieldUsage(String name) { 31 | if (name != null) { 32 | fieldUsages.add(name); 33 | } 34 | } 35 | 36 | /** 37 | * Gets descriptor. 38 | * 39 | * @return the descriptor 40 | */ 41 | public String getDescriptor() { 42 | return descriptor; 43 | } 44 | 45 | /** 46 | * Gets field usages. 47 | * 48 | * @return the field usages 49 | */ 50 | public List getFieldUsages() { 51 | return fieldUsages; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/model/FieldDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.model; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * The type Field descriptor. 7 | * 8 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 9 | */ 10 | public class FieldDescriptor extends AbstractDescriptor { 11 | 12 | private String desc; 13 | private String name; 14 | 15 | /** 16 | * Instantiates a new Field descriptor. 17 | * 18 | * @param desc the desc 19 | * @param name the name 20 | * @param access the access 21 | * @param sourceJar the source jar 22 | */ 23 | protected FieldDescriptor( final String desc, final String name, final int access, File sourceJar ) { 24 | super( access, sourceJar ); 25 | this.desc = desc; 26 | this.name = name; 27 | } 28 | 29 | /** 30 | * Gets desc. 31 | * 32 | * @return the desc 33 | */ 34 | public String getDesc() { 35 | return desc; 36 | } 37 | 38 | /** 39 | * Gets name. 40 | * 41 | * @return the name 42 | */ 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public String toString() { 48 | return "FieldDescriptor{" + 49 | "name='" + name + '\'' + 50 | ", type='" + desc + '\'' + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/model/Invocation.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.model; 2 | 3 | /** 4 | * The type Invocation. 5 | * 6 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 7 | */ 8 | public class Invocation { 9 | 10 | private int opcode; 11 | private String type; 12 | private String name; 13 | private String desc; 14 | 15 | /** 16 | * Instantiates a new Invocation. 17 | * 18 | * @param opcode the opcode 19 | * @param type the type 20 | * @param name the name 21 | * @param desc the desc 22 | */ 23 | public Invocation( int opcode, String type, String name, String desc ) { 24 | this.opcode = opcode; 25 | this.type = type; 26 | this.name = name; 27 | this.desc = desc; 28 | } 29 | 30 | /** 31 | * Gets opcode. 32 | * 33 | * @return the opcode 34 | */ 35 | public int getOpcode() { 36 | return opcode; 37 | } 38 | 39 | /** 40 | * Gets type. 41 | * 42 | * @return the type 43 | */ 44 | public String getType() { 45 | return type; 46 | } 47 | 48 | /** 49 | * Gets name. 50 | * 51 | * @return the name 52 | */ 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | /** 58 | * Gets desc. 59 | * 60 | * @return the desc 61 | */ 62 | public String getDesc() { 63 | return desc; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/model/InvocationFactory.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.model; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * The type Invocation factory. 8 | * 9 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 10 | */ 11 | public class InvocationFactory { 12 | 13 | private static final InvocationFactory instance = new InvocationFactory(); 14 | 15 | /** 16 | * Gets instance. 17 | * 18 | * @return the instance 19 | */ 20 | protected static InvocationFactory getInstance() { 21 | return instance; 22 | } 23 | 24 | private Map invocations = new HashMap(); 25 | 26 | /** 27 | * Gets invocation. 28 | * 29 | * @param opcode the opcode 30 | * @param type the type 31 | * @param name the name 32 | * @param desc the desc 33 | * @return the invocation 34 | */ 35 | protected Invocation getInvocation( final int opcode, final String type, final String name, final String desc ) { 36 | String key = new StringBuilder( type ).append( name ).append( desc ).append( opcode ).toString(); 37 | Invocation val = invocations.get( key ); 38 | if ( null == val ) { 39 | val = new Invocation( opcode, type, name, desc ); 40 | invocations.put( key, val ); 41 | } 42 | return val; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/model/NewNodeDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.model; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * The type New node descriptor. 7 | * 8 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 9 | */ 10 | public class NewNodeDescriptor extends AbstractDescriptor { 11 | 12 | /** 13 | * Instantiates a new New node descriptor. 14 | * 15 | * @param access the access 16 | * @param sourceJar the source jar 17 | */ 18 | protected NewNodeDescriptor( int access, File sourceJar ) { 19 | super( access, sourceJar ); 20 | } 21 | 22 | public String toString() { 23 | return "NewNodeDescriptor{}"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/yworks/yshrink/util/MultiReleaseException.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.util; 2 | 3 | public class MultiReleaseException extends RuntimeException { 4 | @Override 5 | public String getMessage() { 6 | return "Multi-release archives containing classes in META-INF are incompatible with yGuard."; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/com/yworks/yguard/jdk118.bits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/resources/com/yworks/yguard/jdk118.bits -------------------------------------------------------------------------------- /src/main/resources/com/yworks/yguard/jdk131.bits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/resources/com/yworks/yguard/jdk131.bits -------------------------------------------------------------------------------- /src/main/resources/com/yworks/yguard/jdk142.bits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/resources/com/yworks/yguard/jdk142.bits -------------------------------------------------------------------------------- /src/main/resources/com/yworks/yguard/jdk15.bits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/resources/com/yworks/yguard/jdk15.bits -------------------------------------------------------------------------------- /src/main/resources/com/yworks/yguard/jdk15b.bits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/resources/com/yworks/yguard/jdk15b.bits -------------------------------------------------------------------------------- /src/main/resources/com/yworks/yguard/jdks.bits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yWorks/yGuard/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/resources/com/yworks/yguard/jdks.bits -------------------------------------------------------------------------------- /src/test/java/com/yworks/util/abstractjar/ArchiveTest.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import org.junit.Assert; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.Enumeration; 8 | import java.util.List; 9 | import java.util.jar.Manifest; 10 | 11 | /** 12 | * Tests archive reader behavior. 13 | * 14 | * @author Thomas Behr 15 | */ 16 | public class ArchiveTest extends AbstractArchiveTest { 17 | public void testDirectoryReader() throws Exception { 18 | checkArchiveImpl(Utils.createTempDir("ArchiveTest")); 19 | } 20 | 21 | public void testJarReader() throws Exception { 22 | checkArchiveImpl(File.createTempFile("ArchiveTest", ".jar")); 23 | } 24 | 25 | @Override 26 | void checkArchiveCore( final File archive, final List entries ) throws IOException { 27 | final Archive reader = Factory.newArchive(archive); 28 | final Manifest manifest = reader.getManifest(); 29 | Assert.assertNotNull("Could not read manifest", manifest); 30 | 31 | for (Enumeration en = reader.getEntries(); en.hasMoreElements();) { 32 | entries.add(en.nextElement()); 33 | } 34 | 35 | reader.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/util/abstractjar/StreamProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | /** 9 | * Tests stream provider behavior. 10 | * 11 | * @author Thomas Behr 12 | */ 13 | public class StreamProviderTest extends AbstractArchiveTest { 14 | public void testDirectoryReader() throws Exception { 15 | checkArchiveImpl(Utils.createTempDir("ArchiveTest")); 16 | } 17 | 18 | public void testJarReader() throws Exception { 19 | checkArchiveImpl(File.createTempFile("ArchiveTest", ".jar")); 20 | } 21 | 22 | 23 | @Override 24 | void checkArchiveCore( 25 | final File archive, final List entries 26 | ) throws IOException { 27 | final StreamProvider provider = Factory.newStreamProvider(archive); 28 | 29 | for (DataInputStream stream = provider.getNextClassEntryStream(); 30 | stream != null; 31 | stream = provider.getNextClassEntryStream()) { 32 | entries.add(provider.getCurrentEntry()); 33 | stream.close(); 34 | } 35 | 36 | provider.reset(); 37 | for (DataInputStream stream = provider.getNextResourceEntryStream(); 38 | stream != null; 39 | stream = provider.getNextResourceEntryStream()) { 40 | entries.add(provider.getCurrentEntry()); 41 | stream.close(); 42 | } 43 | 44 | provider.close(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/util/abstractjar/Utils.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.abstractjar; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | /** 7 | * todo TBE: add documentation 8 | * 9 | * @author Thomas Behr 10 | */ 11 | class Utils { 12 | private Utils() { 13 | } 14 | 15 | 16 | static File createTempDir( final String prefix ) throws IOException { 17 | final File file = File.createTempFile(prefix, "_tempdir"); 18 | 19 | if (!file.delete()) { 20 | throw new IOException( 21 | "Could not delete temporary file " + file.getAbsolutePath() + '.'); 22 | } 23 | 24 | if (!file.mkdir()) { 25 | throw new IOException( 26 | "Could not create temporary directory " + file.getAbsolutePath() + '.'); 27 | } 28 | 29 | return file; 30 | } 31 | 32 | static void delete( final File file ) throws IOException { 33 | if (file.isDirectory()) { 34 | final File[] contents = file.listFiles(); 35 | if (contents != null) { 36 | for (int i = 0; i < contents.length; i++) { 37 | delete(contents[i]); 38 | } 39 | } 40 | if (!file.delete()) { 41 | throw new IOException( 42 | "Could not delete directory " + file.getAbsolutePath() + '.'); 43 | } 44 | } else { 45 | if (!file.delete()) { 46 | throw new IOException( 47 | "Could not delete file " + file.getAbsolutePath() + '.'); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/util/compiler/Streams.java: -------------------------------------------------------------------------------- 1 | package com.yworks.util.compiler; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | /** 7 | * Provides factory methods for streams 8 | * 9 | * @author Thomas Behr 10 | */ 11 | class Streams { 12 | private Streams() { 13 | } 14 | 15 | /** 16 | * New guard output stream. 17 | * 18 | * @param os the os 19 | * @return the output stream 20 | */ 21 | static OutputStream newGuard( final OutputStream os ) { 22 | return new Guard(os); 23 | } 24 | 25 | 26 | private static final class Guard extends OutputStream { 27 | private final OutputStream os; 28 | 29 | /** 30 | * Instantiates a new Guard. 31 | * 32 | * @param os the os 33 | */ 34 | Guard( final OutputStream os ) { 35 | this.os = os; 36 | } 37 | 38 | public void write( final int b ) throws IOException { 39 | os.write(b); 40 | } 41 | 42 | public void write( final byte[] b ) throws IOException { 43 | os.write(b); 44 | } 45 | 46 | public void write( final byte[] b, final int off, final int len ) throws IOException { 47 | os.write(b, off, len); 48 | } 49 | 50 | public void flush() throws IOException { 51 | os.flush(); 52 | } 53 | 54 | public void close() throws IOException { 55 | // do not close - this is the whole point of the guard 56 | os.flush(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yguard/annotations/AnnoTestKEEP.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.annotations; 2 | 3 | import com.yworks.util.annotation.Obfuscation; 4 | 5 | /** 6 | * Keep everything 7 | */ 8 | @Obfuscation 9 | public class AnnoTestKEEP { 10 | 11 | /** 12 | * The Bool 1 keep. 13 | */ 14 | public boolean bool1KEEP; 15 | 16 | /** 17 | * The Bool 2 keep. 18 | */ 19 | protected boolean bool2KEEP; 20 | 21 | private boolean bool3KEEP; 22 | 23 | /** 24 | * Instantiates a new Anno test keep. 25 | * 26 | * @param bool1KEEP the bool 1 keep 27 | * @param bool2KEEP the bool 2 keep 28 | * @param bool3KEEP the bool 3 keep 29 | */ 30 | public AnnoTestKEEP(boolean bool1KEEP, boolean bool2KEEP, boolean bool3KEEP) { 31 | this.bool1KEEP = bool1KEEP; 32 | this.bool2KEEP = bool2KEEP; 33 | this.bool3KEEP = bool3KEEP; 34 | } 35 | 36 | /** 37 | * Is bool 1 keep boolean. 38 | * 39 | * @return the boolean 40 | */ 41 | public boolean isBool1KEEP() { 42 | return bool1KEEP; 43 | } 44 | 45 | /** 46 | * Sets bool 1 keep. 47 | * 48 | * @param bool1KEEP the bool 1 keep 49 | */ 50 | public void setBool1KEEP(boolean bool1KEEP) { 51 | this.bool1KEEP = bool1KEEP; 52 | } 53 | 54 | /** 55 | * Is bool 2 keep boolean. 56 | * 57 | * @return the boolean 58 | */ 59 | protected boolean isBool2KEEP() { 60 | return bool2KEEP; 61 | } 62 | 63 | /** 64 | * Sets bool 2 keep. 65 | * 66 | * @param bool2KEEP the bool 2 keep 67 | */ 68 | protected void setBool2KEEP(boolean bool2KEEP) { 69 | this.bool2KEEP = bool2KEEP; 70 | } 71 | 72 | private boolean isBool3KEEP() { 73 | return bool3KEEP; 74 | } 75 | 76 | private void setBool3KEEP(boolean bool3KEEP) { 77 | this.bool3KEEP = bool3KEEP; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yguard/annotations/TestAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TestAnnotation.java 3 | * 4 | * Created on May 25, 2005, 3:53 PM 5 | * 6 | * To change this template, choose Tools | Options and locate the template under 7 | * the Source Creation and Management node. Right-click the template and choose 8 | * Open. You can then make changes to the template in the Source Editor. 9 | */ 10 | 11 | package com.yworks.yguard.annotations; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * The interface Test annotation. 20 | * 21 | * @author muellese 22 | */ 23 | @Target(value = ElementType.CONSTRUCTOR) 24 | @Retention(value=RetentionPolicy.RUNTIME) 25 | public @interface TestAnnotation 26 | { 27 | /** 28 | * Id int. 29 | * 30 | * @return the int 31 | */ 32 | int id(); 33 | 34 | /** 35 | * Test 1 string. 36 | * 37 | * @return the string 38 | */ 39 | String test1(); 40 | 41 | /** 42 | * Test 2 string. 43 | * 44 | * @return the string 45 | */ 46 | String test2() default "test"; 47 | 48 | /** 49 | * Test 3 byte. 50 | * 51 | * @return the byte 52 | */ 53 | byte test3() default (byte) 3; 54 | 55 | /** 56 | * Class type class. 57 | * 58 | * @return the class 59 | */ 60 | Class classType() default String.class; 61 | 62 | /** 63 | * Int array int [ ]. 64 | * 65 | * @return the int [ ] 66 | */ 67 | int[] intArray() default {1,2,3,4}; 68 | 69 | /** 70 | * Class array class [ ]. 71 | * 72 | * @return the class [ ] 73 | */ 74 | Class[] classArray() default {String.class, Object.class, int.class}; 75 | 76 | /** 77 | * Recursive yat annotation. 78 | * 79 | * @return the yat annotation 80 | */ 81 | YATAnnotation recursive() default @YATAnnotation(blah = "blub"); 82 | 83 | /** 84 | * Enum test test enum. 85 | * 86 | * @return the test enum 87 | */ 88 | TestEnum enumTest() default TestEnum.V2; 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yguard/annotations/TestEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TestEnum.java 3 | * 4 | * Created on May 30, 2005, 9:53 AM 5 | * 6 | * To change this template, choose Tools | Options and locate the template under 7 | * the Source Creation and Management node. Right-click the template and choose 8 | * Open. You can then make changes to the template in the Source Editor. 9 | */ 10 | 11 | package com.yworks.yguard.annotations; 12 | 13 | /** 14 | * The enum Test enum. 15 | * 16 | * @author muellese 17 | */ 18 | public enum TestEnum 19 | { 20 | /** 21 | * V 1 test enum. 22 | */ 23 | V1, 24 | /** 25 | * V 2 test enum. 26 | */ 27 | V2, 28 | /** 29 | * V 3 test enum. 30 | */ 31 | V3; 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yguard/annotations/YATAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * YATAnnotation.java 3 | * 4 | * Created on May 30, 2005, 9:51 AM 5 | * 6 | * To change this template, choose Tools | Options and locate the template under 7 | * the Source Creation and Management node. Right-click the template and choose 8 | * Open. You can then make changes to the template in the Source Editor. 9 | */ 10 | 11 | package com.yworks.yguard.annotations; 12 | 13 | /** 14 | * The interface Yat annotation. 15 | * 16 | * @author muellese 17 | */ 18 | public @interface YATAnnotation 19 | { 20 | /** 21 | * Blah string. 22 | * 23 | * @return the string 24 | */ 25 | String blah() default "blub"; 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yguard/generics/MyType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MyType.java 3 | * 4 | * Created on 22. April 2005, 09:31 5 | */ 6 | 7 | package com.yworks.yguard.generics; 8 | 9 | /** 10 | * The type My type. 11 | * 12 | * @param the type parameter 13 | * @author muellese 14 | */ 15 | public class MyType { 16 | 17 | private T t; 18 | 19 | /** 20 | * Creates a new instance of MyType 21 | * 22 | * @param t the t 23 | */ 24 | public MyType(T t) { 25 | this.t = t; 26 | } 27 | 28 | /** 29 | * Get content t. 30 | * 31 | * @return the t 32 | */ 33 | public T getContent(){ 34 | return t; 35 | } 36 | 37 | /** 38 | * Set content. 39 | * 40 | * @param t the t 41 | */ 42 | public void setContent(T t){ 43 | this.t = t; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yguard/generics/ParameterizedType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ParameterizedType.java 3 | * 4 | * Created on 22. April 2005, 09:30 5 | */ 6 | 7 | package com.yworks.yguard.generics; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * The type Parameterized type. 14 | * 15 | * @param the type parameter 16 | * @author muellese 17 | */ 18 | public class ParameterizedType> { 19 | 20 | private ArrayList list = new ArrayList(); 21 | 22 | /** 23 | * Creates a new instance of ParameterizedType 24 | */ 25 | public ParameterizedType() { 26 | } 27 | 28 | /** 29 | * Get list list. 30 | * 31 | * @return the list 32 | */ 33 | public List getList(){ 34 | return list; 35 | } 36 | 37 | /** 38 | * Add. 39 | * 40 | * @param t the t 41 | */ 42 | public void add(T t){ 43 | this.list.add(t); 44 | System.out.println(t.getClass()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yshrink/ant/TestPatternMatchedSection.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.ant; 2 | 3 | import org.junit.Test; 4 | import org.objectweb.asm.Opcodes; 5 | import com.yworks.common.ant.PatternMatchedSection; 6 | 7 | import static junit.framework.TestCase.assertFalse; 8 | import static junit.framework.TestCase.assertTrue; 9 | 10 | /** 11 | * The type Test pattern matched section. 12 | * 13 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 14 | */ 15 | public class TestPatternMatchedSection { 16 | /** 17 | * Test is access level. 18 | */ 19 | @Test 20 | public void testIsAccessLevel() { 21 | assertTrue( 22 | PatternMatchedSection.Access.PUBLIC.isAccessLevel( 23 | Opcodes.ACC_PUBLIC ) ); 24 | 25 | assertFalse( 26 | PatternMatchedSection.Access.PUBLIC.isAccessLevel( 27 | Opcodes.ACC_PRIVATE ) ); 28 | 29 | assertFalse( 30 | PatternMatchedSection.Access.PUBLIC.isAccessLevel( 31 | Opcodes.ACC_PROTECTED ) ); 32 | 33 | assertFalse( 34 | PatternMatchedSection.Access.PROTECTED.isAccessLevel( 35 | Opcodes.ACC_PRIVATE ) ); 36 | 37 | assertFalse( 38 | PatternMatchedSection.Access.PUBLIC.isAccessLevel( 39 | PatternMatchedSection.Access.FRIENDLY ) ); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yshrink/java13/Utils.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.java13; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Provides utility methods. 8 | * 9 | * @author Thomas Behr 10 | */ 11 | class Utils { 12 | private Utils() { 13 | } 14 | 15 | 16 | static List listOf( T item ) { 17 | final ArrayList list = new ArrayList(1); 18 | list.add(item); 19 | return list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/yworks/yshrink/util/TestUtil.java: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.util; 2 | 3 | import org.junit.Test; 4 | 5 | import static junit.framework.TestCase.assertEquals; 6 | 7 | /** 8 | * The type Test util. 9 | * 10 | * @author Michael Schroeder, yWorks GmbH http://www.yworks.com 11 | */ 12 | public class TestUtil { 13 | /** 14 | * Test verbose to native type. 15 | */ 16 | @Test 17 | public void testVerboseToNativeType() { 18 | String query = "double[][][]"; 19 | String expected = "[[[D"; 20 | String result = Util.verboseToNativeType( query ); 21 | assertEquals( expected, result ); 22 | 23 | query = "java.lang.String"; 24 | expected = "Ljava/lang/String;"; 25 | result = Util.verboseToNativeType( query ); 26 | assertEquals( expected, result ); 27 | 28 | query = "java.lang.String[]"; 29 | expected = "[Ljava/lang/String;"; 30 | result = Util.verboseToNativeType( query ); 31 | assertEquals( expected, result ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/ConstantBootstraps.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class ConstantBootstraps { 6 | public static void main( String[] args ) { 7 | System.err.println("com.yworks.yguard.obf.ConstantBootstraps$Coin"); 8 | run(System.out); 9 | } 10 | 11 | public static void run( final PrintStream out ) { 12 | out.println(check(Coin.HEADS)); 13 | } 14 | 15 | private static String check( final Object o ) { 16 | return switch (o) { 17 | case Coin.HEADS -> "yes"; 18 | case String s when s.equalsIgnoreCase("NO") -> "no"; 19 | default -> "Error"; 20 | }; 21 | } 22 | 23 | public enum Coin { 24 | HEADS, TAILS 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/LambdaMetaFactoryTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class LambdaMetaFactoryTest { 6 | private interface MyInterface { 7 | void doStuff(final PrintStream out); 8 | } 9 | 10 | private LambdaMetaFactoryTest() { 11 | 12 | } 13 | 14 | public static void main( String[] args ) { 15 | run(System.out); 16 | } 17 | 18 | public static void run( final PrintStream out) { 19 | MyInterface myInterface = (stream) -> stream.println("implementation"); 20 | myInterface.doStuff(out); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/SimpleMethodParametersTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | /** 4 | * @author Thomas Behr 5 | */ 6 | public class SimpleMethodParametersTest { 7 | void f(int j, final int k) {} 8 | } 9 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/StringConcatFactoryTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.PrintStream; 4 | 5 | /** 6 | * Uses string concatenation that results in the Java 11 compiler using 7 | * {@link java.lang.invoke.StringConcatFactory} bootstrap methods. 8 | * @author Thomas Behr 9 | */ 10 | public class StringConcatFactoryTest { 11 | private StringConcatFactoryTest() { 12 | } 13 | 14 | public static void main( String[] args ) { 15 | run(System.out); 16 | } 17 | 18 | public static void run( final PrintStream out ) { 19 | out.println(concat("Hello ", "world!")); 20 | out.println(new MyInteger(1) + " < " + new MyInteger(2)); 21 | } 22 | 23 | private static String concat( String s1, String s2 ) { 24 | return s1 + s2; 25 | } 26 | 27 | 28 | 29 | private static final class MyInteger { 30 | private final int i; 31 | 32 | MyInteger( final int i ) { 33 | this.i = i; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return Integer.toString(i); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/SwitchBootstraps_enumSwitch.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class SwitchBootstraps_enumSwitch { 6 | public static void main( String[] args ) { 7 | run(System.out); 8 | } 9 | 10 | public static void run( final PrintStream out ) { 11 | out.println(flip(Coin.HEADS)); 12 | } 13 | 14 | private static String flip( final Coin coin ) { 15 | return switch (coin) { 16 | case Coin c when c == Coin.HEADS -> "It is heads."; 17 | case Coin c when c == Coin.TAILS -> "It is tails."; 18 | default -> "Error"; 19 | }; 20 | } 21 | 22 | public enum Coin { 23 | HEADS, 24 | TAILS 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/SwitchBootstraps_enumSwitch_string.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class SwitchBootstraps_enumSwitch_string { 6 | public static void main( String[] args ) { 7 | run(System.out); 8 | } 9 | 10 | public static void run( final PrintStream out ) { 11 | Fruit fruit = Fruit.APPLE; 12 | switch (fruit) { 13 | case APPLE -> out.println("apple"); 14 | case BANANA -> out.println("banana"); 15 | case null -> out.println("null"); 16 | default -> out.println("default"); 17 | } 18 | } 19 | 20 | public enum Fruit { 21 | APPLE, 22 | BANANA, 23 | CURRANT 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/SwitchBootstraps_typeSwitch.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class SwitchBootstraps_typeSwitch { 6 | public static void main( String[] args ) { 7 | run(System.out); 8 | } 9 | 10 | public static void run( final PrintStream out ) { 11 | out.println(check("y")); 12 | } 13 | 14 | private static String check( final Object o ) { 15 | return switch (o) { 16 | case String s when s.equals("y") -> "yes"; 17 | case String s when s.equals("n") -> "no"; 18 | default -> "Error"; 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/adjust/ClassWithResources.properties: -------------------------------------------------------------------------------- 1 | javaclassname1 = com.yworks.yguard.obf.ClassWithResources 2 | javaclassname2 = com.yworks.yguard.obf.ClassWithResources$NestedClass 3 | javaclassname3 = com.yworks.yguard.obf.ClassWithResources.NestedClass 4 | javapackagename = com.yworks.yguard.obf 5 | javaresourcename = com.yworks.yguard.obf.GlobalResources 6 | 7 | pathclassname1 = com/yworks/yguard/obf/ClassWithResources 8 | pathclassname2 = com/yworks/yguard/obf/ClassWithResources$NestedClass 9 | pathpackagename = com/yworks/yguard/obf 10 | pathresourcename1 = com/yworks/yguard/obf/ClassWithResources.properties 11 | pathresourcename2 = com/yworks/yguard/obf/ClassWithResources_en.properties 12 | pathresourcename3 = com/yworks/yguard/obf/GlobalResources 13 | pathresourcename4 = com/yworks/yguard/obf/GlobalResources.properties 14 | pathresourcename5 = com/yworks/yguard/obf/GlobalResources$Fragment.properties 15 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/adjust/ClassWithResources.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf; 2 | 3 | public class ClassWithResources { 4 | public static class NestedClass { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/adjust/GlobalResources.properties: -------------------------------------------------------------------------------- 1 | javaclassname1 = com.yworks.yguard.obf.ClassWithResources 2 | 3 | pathclassname1 = com/yworks/yguard/obf/ClassWithResources 4 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/AbstractBaseClass.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.ext.test; 2 | 3 | public abstract class AbstractBaseClass { 4 | protected AbstractBaseClass() { 5 | } 6 | 7 | public abstract void run(); 8 | } 9 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/Impl.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.impl.test; 2 | 3 | import com.yworks.ext.test.AbstractBaseClass; 4 | 5 | public class Impl extends AbstractBaseClass { 6 | public Impl() { 7 | } 8 | 9 | public void run() { 10 | System.out.println("Impl: Hello world."); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/Main.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.impl.test; 2 | 3 | public class Main { 4 | private Main() { 5 | } 6 | 7 | public static void main( String[] args ) { 8 | new Sample().run(new Impl()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/OuterClass.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.asm; 2 | 3 | public class OuterClass { 4 | private static class InnerClass { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/Sample.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.impl.test; 2 | 3 | import com.yworks.ext.test.AbstractBaseClass; 4 | 5 | /** 6 | * Will be completely obfuscated 7 | */ 8 | public class Sample { 9 | public void run( AbstractBaseClass other ) { 10 | other.run(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/SealedClassImpl.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.asm; 2 | 3 | public final class SealedClassImpl extends SealedSerializableClass { 4 | public SealedClassImpl() { 5 | super(666); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/SealedSerializableClass.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.asm; 2 | 3 | import java.io.Serializable; 4 | 5 | public sealed class SealedSerializableClass implements Serializable permits SealedClassImpl { 6 | private int data; 7 | 8 | public SealedSerializableClass( final int data ) { 9 | this.data = data; 10 | } 11 | 12 | public int getData() { 13 | return data; 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yguard/obf/asm/SimpleClass.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yguard.obf.asm; 2 | 3 | public class SimpleClass { 4 | private int data; 5 | 6 | public SimpleClass( final int data ) { 7 | this.data = data; 8 | } 9 | 10 | public int getData() { 11 | return data; 12 | } 13 | } -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yshrink/java13/DirectSuperInterfaceTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.java13; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class DirectSuperInterfaceTest { 6 | interface SuperInterface { 7 | default void print(PrintStream out) { 8 | out.println("Hello from interface"); 9 | } 10 | } 11 | 12 | static class Direct implements SuperInterface { } 13 | 14 | public static void run( final PrintStream out ) { 15 | Direct direct = new Direct(); 16 | direct.print( out ); 17 | } 18 | 19 | public static void main( String[] args ) { 20 | run(System.out); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yshrink/java13/LambdaMetaFactoryTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.java13; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class LambdaMetaFactoryTest { 6 | private interface MyInterface { 7 | void doStuff(final PrintStream out, boolean ok); 8 | } 9 | 10 | public static void run( final PrintStream out ) { 11 | MyInterface myInterface = (stream, ok) -> stream.println("Hello from lambda invoke"); 12 | myInterface.doStuff(out, true); 13 | } 14 | 15 | public static void main( String[] args ) { 16 | run(System.out); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yshrink/java13/NestHostStubTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.java13; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class NestHostStubTest { 6 | static class DoNotKeep { 7 | public String neverUsed() { 8 | return "Hello from unused class"; 9 | } 10 | } 11 | 12 | static class Nested { 13 | protected String nestedResponse() { 14 | return "Hello from nested class"; 15 | } 16 | } 17 | 18 | static class NestedCaller { 19 | public String forwardResponse() { 20 | return new Nested().nestedResponse(); 21 | } 22 | } 23 | 24 | public static void run( final PrintStream out ) { 25 | out.println(new NestedCaller().forwardResponse()); 26 | } 27 | 28 | public static void main( String[] args ) { 29 | run(System.out); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yshrink/java13/SimpleChainTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.java13; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class SimpleChainTest { 6 | interface SuperInterface { 7 | default void print(PrintStream out) { 8 | out.println("Hello from first interface"); 9 | } 10 | } 11 | 12 | interface SuperSuperInterface extends SuperInterface { 13 | default void print(PrintStream out) { 14 | out.println("Hello from second interface"); 15 | } 16 | } 17 | 18 | interface SuperSuperSuperInterface extends SuperSuperInterface { } 19 | 20 | static class Klass implements SuperSuperInterface { } 21 | 22 | public static void run( final PrintStream out ) { 23 | Klass klass = new Klass(); 24 | klass.print( out ); 25 | } 26 | 27 | public static void main( String[] args ) { 28 | run(System.out); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/resources/com/yworks/yshrink/java13/StringConcatFactoryTest.txt: -------------------------------------------------------------------------------- 1 | package com.yworks.yshrink.java13; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class StringConcatFactoryTest { 6 | public static void run( final PrintStream out ) { 7 | String caller = "concat"; 8 | String concatString = "hello " + "from " + caller + " factory"; 9 | out.println(concatString); 10 | } 11 | 12 | public static void main( String[] args ) { 13 | run(System.out); 14 | } 15 | } 16 | --------------------------------------------------------------------------------