├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── gradle.properties
└── src
├── main
├── java
│ └── org
│ │ └── mve
│ │ ├── asm
│ │ ├── AccessFlag.java
│ │ ├── AnnotationWriter.java
│ │ ├── ClassWriter.java
│ │ ├── ConstantPoolFinder.java
│ │ ├── FieldWriter.java
│ │ ├── MethodWriter.java
│ │ ├── Opcodes.java
│ │ ├── OperandStack.java
│ │ ├── attribute
│ │ │ ├── AnnotationArray.java
│ │ │ ├── AnnotationDefaultWriter.java
│ │ │ ├── AttributeWriter.java
│ │ │ ├── BootstrapMethodWriter.java
│ │ │ ├── ClassArrayWriter.java
│ │ │ ├── CodeWriter.java
│ │ │ ├── ConstantValueWriter.java
│ │ │ ├── DeprecatedWriter.java
│ │ │ ├── EnclosingMethodWriter.java
│ │ │ ├── ExceptionWriter.java
│ │ │ ├── InnerClassWriter.java
│ │ │ ├── LineNumberTableWriter.java
│ │ │ ├── LocalVariableTableWriter.java
│ │ │ ├── LocalVariableTypeTableWriter.java
│ │ │ ├── MethodArgumentWriter.java
│ │ │ ├── ModuleMainWriter.java
│ │ │ ├── ModulePackageWriter.java
│ │ │ ├── ModuleWriter.java
│ │ │ ├── NestHostWriter.java
│ │ │ ├── NestMemberWriter.java
│ │ │ ├── ParameterAnnotationArray.java
│ │ │ ├── PermittedSubclassWriter.java
│ │ │ ├── RecordWriter.java
│ │ │ ├── RuntimeInvisibleAnnotationWriter.java
│ │ │ ├── RuntimeInvisibleParameterAnnotationWriter.java
│ │ │ ├── RuntimeInvisibleTypeAnnotationWriter.java
│ │ │ ├── RuntimeVisibleAnnotationWriter.java
│ │ │ ├── RuntimeVisibleParameterAnnotationWriter.java
│ │ │ ├── RuntimeVisibleTypeAnnotationWriter.java
│ │ │ ├── SignatureWriter.java
│ │ │ ├── SourceWriter.java
│ │ │ ├── StackMapTableWriter.java
│ │ │ ├── TypeAnnotationArray.java
│ │ │ ├── UnknownWriter.java
│ │ │ ├── annotation
│ │ │ │ ├── Annotation.java
│ │ │ │ ├── NameAndValue.java
│ │ │ │ ├── ParameterAnnotation.java
│ │ │ │ ├── TypeAnnotation.java
│ │ │ │ ├── type
│ │ │ │ │ ├── Catch.java
│ │ │ │ │ ├── Empty.java
│ │ │ │ │ ├── FormalParameter.java
│ │ │ │ │ ├── LocalVariable.java
│ │ │ │ │ ├── Offset.java
│ │ │ │ │ ├── Supertype.java
│ │ │ │ │ ├── Throws.java
│ │ │ │ │ ├── TypeAnnotationValue.java
│ │ │ │ │ ├── TypeArgument.java
│ │ │ │ │ ├── TypeParameter.java
│ │ │ │ │ ├── TypeParameterBound.java
│ │ │ │ │ ├── local
│ │ │ │ │ │ └── Variable.java
│ │ │ │ │ └── location
│ │ │ │ │ │ └── Location.java
│ │ │ │ └── value
│ │ │ │ │ ├── Array.java
│ │ │ │ │ └── Enum.java
│ │ │ ├── bootstrap
│ │ │ │ └── BootstrapMethod.java
│ │ │ ├── code
│ │ │ │ ├── Constant.java
│ │ │ │ ├── Dynamic.java
│ │ │ │ ├── Element.java
│ │ │ │ ├── Field.java
│ │ │ │ ├── Iinc.java
│ │ │ │ ├── Instruction.java
│ │ │ │ ├── InterfaceMethod.java
│ │ │ │ ├── Jump.java
│ │ │ │ ├── LocalVariable.java
│ │ │ │ ├── Marker.java
│ │ │ │ ├── Method.java
│ │ │ │ ├── Multianewarray.java
│ │ │ │ ├── Newarray.java
│ │ │ │ ├── Number.java
│ │ │ │ ├── Simple.java
│ │ │ │ ├── Switch.java
│ │ │ │ ├── Type.java
│ │ │ │ ├── exception
│ │ │ │ │ └── Exception.java
│ │ │ │ ├── local
│ │ │ │ │ └── LocalVariable.java
│ │ │ │ └── stack
│ │ │ │ │ ├── AppendFrame.java
│ │ │ │ │ ├── ChopFrame.java
│ │ │ │ │ ├── FullFrame.java
│ │ │ │ │ ├── SameFrame.java
│ │ │ │ │ ├── SameFrameExtended.java
│ │ │ │ │ ├── SameLocals1StackItemFrame.java
│ │ │ │ │ ├── SameLocals1StackItemFrameExtended.java
│ │ │ │ │ ├── StackMapFrame.java
│ │ │ │ │ └── verification
│ │ │ │ │ ├── DoubleVariable.java
│ │ │ │ │ ├── FloatVariable.java
│ │ │ │ │ ├── IntegerVariable.java
│ │ │ │ │ ├── LongVariable.java
│ │ │ │ │ ├── NullVariable.java
│ │ │ │ │ ├── ObjectVariable.java
│ │ │ │ │ ├── TopVariable.java
│ │ │ │ │ ├── UninitializedThisVariable.java
│ │ │ │ │ ├── UninitializedVariable.java
│ │ │ │ │ └── Verification.java
│ │ │ ├── inner
│ │ │ │ └── InnerClass.java
│ │ │ ├── method
│ │ │ │ └── Argument.java
│ │ │ ├── module
│ │ │ │ ├── Export.java
│ │ │ │ ├── Open.java
│ │ │ │ ├── Provide.java
│ │ │ │ └── Require.java
│ │ │ └── record
│ │ │ │ └── Record.java
│ │ ├── constant
│ │ │ ├── ConstantValue.java
│ │ │ ├── MethodHandle.java
│ │ │ ├── MethodType.java
│ │ │ └── Type.java
│ │ └── file
│ │ │ ├── Class.java
│ │ │ ├── ClassParseException.java
│ │ │ ├── ClassSerializeException.java
│ │ │ ├── Field.java
│ │ │ ├── Method.java
│ │ │ ├── attribute
│ │ │ ├── Attribute.java
│ │ │ ├── AttributeAnnotationDefault.java
│ │ │ ├── AttributeBootstrapMethods.java
│ │ │ ├── AttributeCode.java
│ │ │ ├── AttributeConstantValue.java
│ │ │ ├── AttributeDeprecated.java
│ │ │ ├── AttributeEnclosingMethod.java
│ │ │ ├── AttributeExceptions.java
│ │ │ ├── AttributeInnerClasses.java
│ │ │ ├── AttributeLineNumberTable.java
│ │ │ ├── AttributeLocalVariableTable.java
│ │ │ ├── AttributeLocalVariableTypeTable.java
│ │ │ ├── AttributeMethodArguments.java
│ │ │ ├── AttributeModule.java
│ │ │ ├── AttributeModuleMainClass.java
│ │ │ ├── AttributeModulePackages.java
│ │ │ ├── AttributeNestHost.java
│ │ │ ├── AttributeNestMembers.java
│ │ │ ├── AttributePermittedSubclasses.java
│ │ │ ├── AttributeRecord.java
│ │ │ ├── AttributeRuntimeInvisibleAnnotations.java
│ │ │ ├── AttributeRuntimeInvisibleParameterAnnotations.java
│ │ │ ├── AttributeRuntimeInvisibleTypeAnnotations.java
│ │ │ ├── AttributeRuntimeVisibleAnnotations.java
│ │ │ ├── AttributeRuntimeVisibleParameterAnnotations.java
│ │ │ ├── AttributeRuntimeVisibleTypeAnnotations.java
│ │ │ ├── AttributeSignature.java
│ │ │ ├── AttributeSourceDebugExtension.java
│ │ │ ├── AttributeSourceFile.java
│ │ │ ├── AttributeStackMapTable.java
│ │ │ ├── AttributeSynthetic.java
│ │ │ ├── AttributeType.java
│ │ │ ├── AttributeUnknown.java
│ │ │ ├── annotation
│ │ │ │ ├── Annotation.java
│ │ │ │ ├── ParameterAnnotation.java
│ │ │ │ ├── TypeAnnotation.java
│ │ │ │ └── type
│ │ │ │ │ ├── TypeAnnotationCatchValue.java
│ │ │ │ │ ├── TypeAnnotationEmptyValue.java
│ │ │ │ │ ├── TypeAnnotationFormalParameterValue.java
│ │ │ │ │ ├── TypeAnnotationLocalVariableValue.java
│ │ │ │ │ ├── TypeAnnotationLocation.java
│ │ │ │ │ ├── TypeAnnotationOffsetValue.java
│ │ │ │ │ ├── TypeAnnotationPath.java
│ │ │ │ │ ├── TypeAnnotationSupertypeValue.java
│ │ │ │ │ ├── TypeAnnotationThrowsValue.java
│ │ │ │ │ ├── TypeAnnotationTypeArgumentValue.java
│ │ │ │ │ ├── TypeAnnotationTypeParameterBoundValue.java
│ │ │ │ │ ├── TypeAnnotationTypeParameterValue.java
│ │ │ │ │ ├── TypeAnnotationValue.java
│ │ │ │ │ ├── local
│ │ │ │ │ └── LocalVariableValue.java
│ │ │ │ │ └── location
│ │ │ │ │ └── Location.java
│ │ │ ├── bootstrap
│ │ │ │ └── BootstrapMethod.java
│ │ │ ├── code
│ │ │ │ └── exception
│ │ │ │ │ └── Exception.java
│ │ │ ├── element
│ │ │ │ ├── ElementAnnotationValue.java
│ │ │ │ ├── ElementArrayValue.java
│ │ │ │ ├── ElementClassValue.java
│ │ │ │ ├── ElementConstantValue.java
│ │ │ │ ├── ElementEnumValue.java
│ │ │ │ ├── ElementNameAndValue.java
│ │ │ │ ├── ElementValue.java
│ │ │ │ └── ElementValueType.java
│ │ │ ├── inner
│ │ │ │ └── InnerClass.java
│ │ │ ├── line
│ │ │ │ └── LineNumber.java
│ │ │ ├── local
│ │ │ │ ├── LocalVariable.java
│ │ │ │ └── LocalVariableType.java
│ │ │ ├── method
│ │ │ │ └── Argument.java
│ │ │ ├── module
│ │ │ │ ├── ModuleExport.java
│ │ │ │ ├── ModuleOpen.java
│ │ │ │ ├── ModuleProvide.java
│ │ │ │ └── ModuleRequire.java
│ │ │ ├── record
│ │ │ │ └── RecordComponent.java
│ │ │ └── stack
│ │ │ │ ├── StackMapAppendFrame.java
│ │ │ │ ├── StackMapChopFrame.java
│ │ │ │ ├── StackMapFrame.java
│ │ │ │ ├── StackMapFrameType.java
│ │ │ │ ├── StackMapFullFrame.java
│ │ │ │ ├── StackMapSameFrame.java
│ │ │ │ ├── StackMapSameFrameExtended.java
│ │ │ │ ├── StackMapSameLocals1StackItemFrame.java
│ │ │ │ ├── StackMapSameLocals1StackItemFrameExtended.java
│ │ │ │ └── verification
│ │ │ │ ├── Verification.java
│ │ │ │ ├── VerificationDoubleVariable.java
│ │ │ │ ├── VerificationFloatVariable.java
│ │ │ │ ├── VerificationIntegerVariable.java
│ │ │ │ ├── VerificationLongVariable.java
│ │ │ │ ├── VerificationNullVariable.java
│ │ │ │ ├── VerificationObjectVariable.java
│ │ │ │ ├── VerificationTopVariable.java
│ │ │ │ ├── VerificationType.java
│ │ │ │ ├── VerificationUninitializedThisVariable.java
│ │ │ │ └── VerificationUninitializedVariable.java
│ │ │ └── constant
│ │ │ ├── Constant.java
│ │ │ ├── ConstantArray.java
│ │ │ ├── ConstantClass.java
│ │ │ ├── ConstantDouble.java
│ │ │ ├── ConstantDynamic.java
│ │ │ ├── ConstantFieldReference.java
│ │ │ ├── ConstantFloat.java
│ │ │ ├── ConstantInteger.java
│ │ │ ├── ConstantInterfaceMethodReference.java
│ │ │ ├── ConstantInvokeDynamic.java
│ │ │ ├── ConstantLong.java
│ │ │ ├── ConstantMethodHandle.java
│ │ │ ├── ConstantMethodReference.java
│ │ │ ├── ConstantMethodType.java
│ │ │ ├── ConstantModule.java
│ │ │ ├── ConstantNameAndType.java
│ │ │ ├── ConstantNull.java
│ │ │ ├── ConstantPackage.java
│ │ │ ├── ConstantString.java
│ │ │ ├── ConstantType.java
│ │ │ └── ConstantUTF8.java
│ │ ├── invoke
│ │ ├── ConstructorAccessor.java
│ │ ├── EnumHelper.java
│ │ ├── FieldAccessor.java
│ │ ├── MagicAccess.java
│ │ ├── MagicAccessFactory.java
│ │ ├── MagicAccessor.java
│ │ ├── MethodAccessor.java
│ │ ├── MethodKind.java
│ │ ├── ModuleAccess.java
│ │ ├── PolymorphismFactory.java
│ │ ├── ReflectionAccessor.java
│ │ ├── ReflectionFactory.java
│ │ ├── StackFrame.java
│ │ ├── Unsafe.java
│ │ └── common
│ │ │ ├── Generator.java
│ │ │ ├── JavaVM.java
│ │ │ ├── polymorphism
│ │ │ ├── MagicPolymorphismConstructGenerator.java
│ │ │ ├── MagicPolymorphismFieldGenerator.java
│ │ │ ├── MagicPolymorphismInstantiationGenerator.java
│ │ │ ├── MagicPolymorphismMethodGenerator.java
│ │ │ ├── NativePolymorphismConstructGenerator.java
│ │ │ ├── NativePolymorphismFieldGenerator.java
│ │ │ ├── NativePolymorphismInstantiationGenerator.java
│ │ │ ├── NativePolymorphismMethodGenerator.java
│ │ │ ├── PolymorphismConstructGenerator.java
│ │ │ ├── PolymorphismEnumHelperGenerator.java
│ │ │ ├── PolymorphismFieldGenerator.java
│ │ │ ├── PolymorphismGenerator.java
│ │ │ ├── PolymorphismInstantiationGenerator.java
│ │ │ └── PolymorphismMethodGenerator.java
│ │ │ └── standard
│ │ │ ├── AccessibleObjectAccessorGenerator.java
│ │ │ ├── AccessorGenerator.java
│ │ │ ├── AllocatorGenerator.java
│ │ │ ├── ConstructorAccessorGenerator.java
│ │ │ ├── FieldAccessorGenerator.java
│ │ │ ├── FieldGetterGenerator.java
│ │ │ ├── FieldModifierGenerator.java
│ │ │ ├── FieldSetterGenerator.java
│ │ │ ├── MagicAllocatorGenerator.java
│ │ │ ├── MagicConstructorAccessorGenerator.java
│ │ │ ├── MagicFieldGetterGenerator.java
│ │ │ ├── MagicFieldSetterGenerator.java
│ │ │ ├── MagicMethodAccessorGenerator.java
│ │ │ ├── MethodAccessorGenerator.java
│ │ │ ├── NativeAllocatorGenerator.java
│ │ │ ├── NativeConstructorAccessorGenerator.java
│ │ │ ├── NativeMethodAccessorGenerator.java
│ │ │ ├── UnsafeFieldGetterGenerator.java
│ │ │ └── UnsafeFieldSetterGenerator.java
│ │ └── io
│ │ ├── ByteArrayAccessor.java
│ │ └── RandomAccessByteArray.java
└── resources
│ └── module-info.class
└── test
└── java
└── org
└── mve
├── Main.java
├── Main1.java
├── Main2.java
├── Main3.java
├── Main4.java
├── Main5.java
├── Main6.java
└── Test.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /.debug/
2 | /.idea/
3 | /out/
4 | /target/
5 | ReflectionFX.iml
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020-2021 MeiVinEight
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [](https://www.jitpack.io/#MeiVinEight/ReflectionFX)
6 |
7 |
8 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | group 'org.mve'
4 | version '1.10-SNAPSHOT-1'
5 |
6 | java
7 | {
8 | withSourcesJar()
9 | }
10 |
11 | jar.dependsOn(tasks.sourcesJar)
12 |
13 | sourceCompatibility = JavaVersion.VERSION_1_8
14 | targetCompatibility = JavaVersion.VERSION_1_8
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.daemon=false
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/AccessFlag.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm;
2 |
3 | public class AccessFlag
4 | {
5 | public static final int PUBLIC = 0x0001;
6 | public static final int PRIVATE = 0x0002;
7 | public static final int PROTECTED = 0x0004;
8 | public static final int STATIC = 0x0008;
9 | public static final int FINAL = 0x0010;
10 | public static final int SUPER = 0x0020;
11 | public static final int SYNCHRONIZED = 0x0020;
12 | public static final int OPEN = 0x0020;
13 | public static final int VOLATILE = 0x0040;
14 | public static final int BRIDGE = 0x0040;
15 | public static final int STATIC_PHASE = 0x0040;
16 | public static final int VARARGS = 0x0080;
17 | public static final int TRANSIENT = 0x0080;
18 | public static final int PRIMITIVE = 0x0100;
19 | public static final int NATIVE = 0x0100;
20 | public static final int INTERFACE = 0x0200;
21 | public static final int ABSTRACT = 0x0400;
22 | public static final int STRICT = 0x0800;
23 | public static final int SYNTHETIC = 0x1000;
24 | public static final int ANNOTATION = 0x2000;
25 | public static final int ENUM = 0x4000;
26 | public static final int MODULE = 0x8000;
27 | public static final int MANDATED = 0x8000;
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/AnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.annotation.Annotation;
5 |
6 | public class AnnotationWriter
7 | {
8 | private String type;
9 |
10 | public AnnotationWriter set(String type)
11 | {
12 | this.type = type;
13 | return this;
14 | }
15 |
16 | public Annotation get(ConstantArray pool)
17 | {
18 | Annotation annotation = new Annotation();
19 | annotation.type = ConstantPoolFinder.findUTF8(pool, type);
20 | return annotation;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/FieldWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm;
2 |
3 | import org.mve.asm.attribute.AttributeWriter;
4 |
5 | import java.util.Arrays;
6 |
7 | public class FieldWriter
8 | {
9 | public int access;
10 | public String name;
11 | public String type;
12 | public AttributeWriter[] attribute = new AttributeWriter[0];
13 |
14 | public FieldWriter set(int accessFlag, String name, String desc)
15 | {
16 | this.access = accessFlag;
17 | this.name = name;
18 | this.type = desc;
19 | return this;
20 | }
21 |
22 | public FieldWriter access(int access)
23 | {
24 | this.access = access;
25 | return this;
26 | }
27 |
28 | public FieldWriter name(String name)
29 | {
30 | this.name = name;
31 | return this;
32 | }
33 |
34 | public FieldWriter type(String type)
35 | {
36 | this.type = type;
37 | return this;
38 | }
39 |
40 | public FieldWriter attribute(AttributeWriter writer)
41 | {
42 | int i = this.attribute.length;
43 | this.attribute = Arrays.copyOf(this.attribute, i+1);
44 | this.attribute[i] = writer;
45 | return this;
46 | }
47 |
48 | public AttributeWriter[] getAttribute()
49 | {
50 | return Arrays.copyOf(this.attribute, this.attribute.length);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/MethodWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm;
2 |
3 | import org.mve.asm.attribute.AttributeWriter;
4 |
5 | import java.util.Arrays;
6 | import java.util.function.Consumer;
7 |
8 | public class MethodWriter
9 | {
10 | public int access;
11 | public String name;
12 | public String type;
13 | public AttributeWriter[] attribute = new AttributeWriter[0];
14 |
15 | public MethodWriter set(int accessFlag, String name, String desc)
16 | {
17 | this.access = accessFlag;
18 | this.name = name;
19 | this.type = desc;
20 | return this;
21 | }
22 |
23 | public MethodWriter access(int access)
24 | {
25 | this.access = access;
26 | return this;
27 | }
28 |
29 | public MethodWriter name(String name)
30 | {
31 | this.name = name;
32 | return this;
33 | }
34 |
35 | public MethodWriter type(String type)
36 | {
37 | this.type = type;
38 | return this;
39 | }
40 |
41 | public MethodWriter attribute(AttributeWriter writer)
42 | {
43 | int i = this.attribute.length;
44 | this.attribute = Arrays.copyOf(this.attribute, i+1);
45 | this.attribute[i] = writer;
46 | return this;
47 | }
48 |
49 | public MethodWriter consume(Consumer consumer)
50 | {
51 | consumer.accept(this);
52 | return this;
53 | }
54 |
55 | public AttributeWriter[] getAttribute()
56 | {
57 | return Arrays.copyOf(this.attribute, this.attribute.length);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/OperandStack.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm;
2 |
3 | public class OperandStack
4 | {
5 | private int max;
6 | private int used;
7 |
8 | public void push()
9 | {
10 | used++;
11 | max = Math.max(used, max);
12 | }
13 |
14 | public void pop()
15 | {
16 | used--;
17 | }
18 |
19 | public int getMaxSize()
20 | {
21 | return max;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/AnnotationArray.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.attribute.annotation.Annotation;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | import java.util.Arrays;
7 |
8 | public abstract class AnnotationArray>
9 | {
10 | public Annotation[] annotation;
11 |
12 | public AnnotationArray(Annotation[] annotation)
13 | {
14 | this.annotation = annotation;
15 | }
16 |
17 | @SuppressWarnings("unchecked")
18 | public T annotation(Annotation annotation)
19 | {
20 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length+1);
21 | this.annotation[this.annotation.length-1] = annotation;
22 | return (T) this;
23 | }
24 |
25 | public org.mve.asm.file.attribute.annotation.Annotation[] array(ConstantArray constant)
26 | {
27 | org.mve.asm.file.attribute.annotation.Annotation[] array = new org.mve.asm.file.attribute.annotation.Annotation[this.annotation.length];
28 | for (int i = 0; i < this.annotation.length; i++)
29 | {
30 | array[i] = this.annotation[i].annotation(constant);
31 | }
32 | return array;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/AnnotationDefaultWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.annotation.NameAndValue;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeAnnotationDefault;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.constant.ConstantArray;
9 |
10 | public class AnnotationDefaultWriter implements AttributeWriter
11 | {
12 | public Object value;
13 |
14 | public AnnotationDefaultWriter(Object value)
15 | {
16 | this.value = value;
17 | }
18 |
19 | public AnnotationDefaultWriter()
20 | {
21 | }
22 |
23 | public AnnotationDefaultWriter value(Object value)
24 | {
25 | this.value = value;
26 | return this;
27 | }
28 |
29 | @Override
30 | public Attribute getAttribute(ConstantArray pool)
31 | {
32 | AttributeAnnotationDefault attribute = new AttributeAnnotationDefault();
33 | attribute.name = ConstantPoolFinder.findUTF8(pool, AttributeType.ANNOTATION_DEFAULT.getName());
34 | attribute.value = NameAndValue.value(pool, this.value);
35 | return attribute;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/AttributeWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.file.attribute.Attribute;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public interface AttributeWriter
7 | {
8 | public abstract Attribute getAttribute(ConstantArray pool);
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/ClassArrayWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | import java.util.Arrays;
7 |
8 | public abstract class ClassArrayWriter implements AttributeWriter
9 | {
10 | public String[] classes;
11 |
12 | public ClassArrayWriter(String... member)
13 | {
14 | this.classes = member;
15 | }
16 |
17 | public ClassArrayWriter classes(String name)
18 | {
19 | this.classes = Arrays.copyOf(this.classes, this.classes.length+1);
20 | this.classes[this.classes.length-1] = name;
21 | return this;
22 | }
23 |
24 | public int[] array(ConstantArray array)
25 | {
26 | int[] arr = new int[this.classes.length];
27 | for (int i = 0; i < this.classes.length; i++)
28 | {
29 | arr[i] = ConstantPoolFinder.findClass(array, this.classes[i]);
30 | }
31 | return arr;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/ConstantValueWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.constant.ConstantValue;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeConstantValue;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.constant.ConstantArray;
9 |
10 | public class ConstantValueWriter implements AttributeWriter
11 | {
12 | public Object value;
13 |
14 | public ConstantValueWriter(Object value)
15 | {
16 | this.value = value;
17 | }
18 |
19 | public ConstantValueWriter()
20 | {
21 | }
22 |
23 | public ConstantValueWriter value(Object value)
24 | {
25 | this.value = value;
26 | return this;
27 | }
28 |
29 | @Override
30 | public Attribute getAttribute(ConstantArray pool)
31 | {
32 | AttributeConstantValue attribute = new AttributeConstantValue();
33 | attribute.name = ConstantPoolFinder.findUTF8(pool, AttributeType.CONSTANT_VALUE.getName());
34 | attribute.value = ConstantValue.constant(pool, this.value);
35 | return attribute;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/DeprecatedWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeDeprecated;
6 | import org.mve.asm.file.attribute.AttributeType;
7 | import org.mve.asm.file.constant.ConstantArray;
8 |
9 | public class DeprecatedWriter implements AttributeWriter
10 | {
11 | @Override
12 | public Attribute getAttribute(ConstantArray pool)
13 | {
14 | AttributeDeprecated deprecated = new AttributeDeprecated();
15 | deprecated.name = ConstantPoolFinder.findUTF8(pool, AttributeType.DEPRECATED.getName());
16 | return deprecated;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/EnclosingMethodWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeEnclosingMethod;
6 | import org.mve.asm.file.attribute.AttributeType;
7 | import org.mve.asm.file.constant.ConstantArray;
8 |
9 | public class EnclosingMethodWriter implements AttributeWriter
10 | {
11 | public String type;
12 | public String name;
13 | public String sign;
14 |
15 | public EnclosingMethodWriter(String type, String name, String sign)
16 | {
17 | this.type = type;
18 | this.name = name;
19 | this.sign = sign;
20 | }
21 |
22 | public EnclosingMethodWriter()
23 | {
24 | }
25 |
26 | public EnclosingMethodWriter type(String type)
27 | {
28 | this.type = type;
29 | return this;
30 | }
31 |
32 | public EnclosingMethodWriter name(String name)
33 | {
34 | this.name = name;
35 | return this;
36 | }
37 |
38 | public EnclosingMethodWriter sign(String sign)
39 | {
40 | this.sign = sign;
41 | return this;
42 | }
43 |
44 | @Override
45 | public Attribute getAttribute(ConstantArray pool)
46 | {
47 | AttributeEnclosingMethod attribute = new AttributeEnclosingMethod();
48 | attribute.name = ConstantPoolFinder.findUTF8(pool, AttributeType.ENCLOSING_METHOD.getName());
49 | attribute.clazz = ConstantPoolFinder.findClass(pool, this.type);
50 | attribute.method = ConstantPoolFinder.findNameAndType(pool, this.name, this.sign);
51 | return attribute;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/ExceptionWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.code.Marker;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeExceptions;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.constant.ConstantArray;
9 |
10 | import java.util.Arrays;
11 |
12 | public class ExceptionWriter implements AttributeWriter
13 | {
14 | public String[] exception = new String[0];
15 |
16 | public ExceptionWriter(String... exception)
17 | {
18 | this.exception = exception;
19 | }
20 |
21 | public ExceptionWriter()
22 | {
23 | }
24 |
25 | public ExceptionWriter exception(String exception)
26 | {
27 | this.exception = Arrays.copyOf(this.exception, this.exception.length+1);
28 | this.exception[this.exception.length-1] = exception;
29 | return this;
30 | }
31 |
32 | public ExceptionWriter mark(Marker marker)
33 | {
34 | marker.address = this.exception.length;
35 | return this;
36 | }
37 |
38 | @Override
39 | public Attribute getAttribute(ConstantArray pool)
40 | {
41 | AttributeExceptions attribute = new AttributeExceptions();
42 | attribute.name = ConstantPoolFinder.findUTF8(pool, AttributeType.EXCEPTIONS.getName());
43 | for (String exception : this.exception)
44 | {
45 | attribute.exception(ConstantPoolFinder.findClass(pool, exception));
46 | }
47 | return attribute;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/InnerClassWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.inner.InnerClass;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeInnerClasses;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.constant.ConstantArray;
9 |
10 | import java.util.Arrays;
11 |
12 | public class InnerClassWriter implements AttributeWriter
13 | {
14 | public InnerClass[] inner = new InnerClass[0];
15 |
16 | public InnerClassWriter inner(String inner, String outer, String name, int access)
17 | {
18 | return this.inner(new InnerClass(inner, outer, name, access));
19 | }
20 |
21 | public InnerClassWriter inner(InnerClass inner)
22 | {
23 | this.inner = Arrays.copyOf(this.inner, this.inner.length+1);
24 | this.inner[this.inner.length-1] = inner;
25 | return this;
26 | }
27 |
28 | @Override
29 | public Attribute getAttribute(ConstantArray pool)
30 | {
31 | AttributeInnerClasses attribute = new AttributeInnerClasses();
32 | attribute.name = ConstantPoolFinder.findUTF8(pool, AttributeType.INNER_CLASSES.getName());
33 | for (InnerClass inner : this.inner)
34 | {
35 | org.mve.asm.file.attribute.inner.InnerClass ic = new org.mve.asm.file.attribute.inner.InnerClass();
36 | ic.inner = ConstantPoolFinder.findClass(pool, inner.inner);
37 | ic.outer = ConstantPoolFinder.findClass(pool, inner.outer);
38 | ic.name = ConstantPoolFinder.findUTF8(pool, inner.name);
39 | ic.access = inner.access;
40 | attribute.inner(ic);
41 | }
42 | return attribute;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/LineNumberTableWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.code.Marker;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeLineNumberTable;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.attribute.line.LineNumber;
9 | import org.mve.asm.file.constant.ConstantArray;
10 |
11 | import java.util.Arrays;
12 |
13 | public class LineNumberTableWriter implements AttributeWriter
14 | {
15 | public Marker[] offset = new Marker[0];
16 | public int[] number = new int[0];
17 |
18 | public LineNumberTableWriter line(Marker offset, int number)
19 | {
20 | this.offset = Arrays.copyOf(this.offset, this.offset.length+1);
21 | this.offset[this.offset.length-1] = offset;
22 |
23 | this.number = Arrays.copyOf(this.number, this.number.length+1);
24 | this.number[this.number.length-1] = number;
25 |
26 | return this;
27 | }
28 |
29 | @Override
30 | public Attribute getAttribute(ConstantArray pool)
31 | {
32 | AttributeLineNumberTable table = new AttributeLineNumberTable();
33 | table.name = ConstantPoolFinder.findUTF8(pool, AttributeType.LINE_NUMBER_TABLE.getName());
34 | for (int i=0; i>
9 | {
10 | public ParameterAnnotation[] annotation = new ParameterAnnotation[0];
11 |
12 | @SuppressWarnings("unchecked")
13 | public T annotation(ParameterAnnotation annotation)
14 | {
15 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length+1);
16 | this.annotation[this.annotation.length-1] = annotation;
17 | return (T) this;
18 | }
19 |
20 | public org.mve.asm.file.attribute.annotation.ParameterAnnotation[] array(ConstantArray array)
21 | {
22 | org.mve.asm.file.attribute.annotation.ParameterAnnotation[] value = new org.mve.asm.file.attribute.annotation.ParameterAnnotation[this.annotation.length];
23 | for (int i = 0; i < this.annotation.length; i++)
24 | {
25 | org.mve.asm.file.attribute.annotation.ParameterAnnotation annotation = new org.mve.asm.file.attribute.annotation.ParameterAnnotation();
26 | annotation.annotation = this.annotation[i].array(array);
27 | value[i] = annotation;
28 | }
29 | return value;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/PermittedSubclassWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributePermittedSubclasses;
6 | import org.mve.asm.file.constant.ConstantArray;
7 |
8 | public class PermittedSubclassWriter extends ClassArrayWriter
9 | {
10 | public PermittedSubclassWriter(String... member)
11 | {
12 | super(member);
13 | }
14 |
15 | public PermittedSubclassWriter()
16 | {
17 | super();
18 | }
19 |
20 | @Override
21 | public Attribute getAttribute(ConstantArray pool)
22 | {
23 | AttributePermittedSubclasses attribute = new AttributePermittedSubclasses();
24 | attribute.name = ConstantPoolFinder.findUTF8(pool, attribute.type().getName());
25 | attribute.classes = this.array(pool);
26 | return attribute;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/RuntimeInvisibleAnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.annotation.Annotation;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeRuntimeInvisibleAnnotations;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.constant.ConstantArray;
9 |
10 | public class RuntimeInvisibleAnnotationWriter extends AnnotationArray implements AttributeWriter
11 | {
12 | public RuntimeInvisibleAnnotationWriter(Annotation[] annotation)
13 | {
14 | super(annotation);
15 | }
16 |
17 | public RuntimeInvisibleAnnotationWriter()
18 | {
19 | super(new Annotation[0]);
20 | }
21 |
22 | @Override
23 | public Attribute getAttribute(ConstantArray pool)
24 | {
25 | AttributeRuntimeInvisibleAnnotations attr = new AttributeRuntimeInvisibleAnnotations();
26 | attr.name = ConstantPoolFinder.findUTF8(pool, AttributeType.RUNTIME_VISIBLE_ANNOTATIONS.getName());
27 | attr.annotation = this.array(pool);
28 | return attr;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/RuntimeInvisibleParameterAnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeRuntimeInvisibleParameterAnnotations;
6 | import org.mve.asm.file.constant.ConstantArray;
7 |
8 | public class RuntimeInvisibleParameterAnnotationWriter extends ParameterAnnotationArray implements AttributeWriter
9 | {
10 | @Override
11 | public Attribute getAttribute(ConstantArray pool)
12 | {
13 | AttributeRuntimeInvisibleParameterAnnotations attribute = new AttributeRuntimeInvisibleParameterAnnotations();
14 | attribute.name = ConstantPoolFinder.findUTF8(pool, attribute.type().getName());
15 | attribute.annotation = this.array(pool);
16 | return attribute;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/RuntimeInvisibleTypeAnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeRuntimeInvisibleTypeAnnotations;
6 | import org.mve.asm.file.constant.ConstantArray;
7 |
8 | public class RuntimeInvisibleTypeAnnotationWriter extends TypeAnnotationArray implements AttributeWriter
9 | {
10 | @Override
11 | public Attribute getAttribute(ConstantArray pool)
12 | {
13 | AttributeRuntimeInvisibleTypeAnnotations attribute = new AttributeRuntimeInvisibleTypeAnnotations();
14 | attribute.name = ConstantPoolFinder.findUTF8(pool, attribute.type().getName());
15 | attribute.annotation = this.array(pool);
16 | return attribute;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/RuntimeVisibleAnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.annotation.Annotation;
5 | import org.mve.asm.file.attribute.Attribute;
6 | import org.mve.asm.file.attribute.AttributeRuntimeVisibleAnnotations;
7 | import org.mve.asm.file.attribute.AttributeType;
8 | import org.mve.asm.file.constant.ConstantArray;
9 |
10 | public class RuntimeVisibleAnnotationWriter extends AnnotationArray implements AttributeWriter
11 | {
12 | public RuntimeVisibleAnnotationWriter(Annotation[] annotation)
13 | {
14 | super(annotation);
15 | }
16 |
17 | public RuntimeVisibleAnnotationWriter()
18 | {
19 | super(new Annotation[0]);
20 | }
21 |
22 | @Override
23 | public Attribute getAttribute(ConstantArray pool)
24 | {
25 | AttributeRuntimeVisibleAnnotations attr = new AttributeRuntimeVisibleAnnotations();
26 | attr.name = ConstantPoolFinder.findUTF8(pool, AttributeType.RUNTIME_VISIBLE_ANNOTATIONS.getName());
27 | attr.annotation = this.array(pool);
28 | return attr;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/RuntimeVisibleParameterAnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeRuntimeVisibleParameterAnnotations;
6 | import org.mve.asm.file.constant.ConstantArray;
7 |
8 | public class RuntimeVisibleParameterAnnotationWriter extends ParameterAnnotationArray implements AttributeWriter
9 | {
10 | @Override
11 | public Attribute getAttribute(ConstantArray pool)
12 | {
13 | AttributeRuntimeVisibleParameterAnnotations attribute = new AttributeRuntimeVisibleParameterAnnotations();
14 | attribute.name = ConstantPoolFinder.findUTF8(pool, attribute.type().getName());
15 | attribute.annotation = this.array(pool);
16 | return attribute;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/RuntimeVisibleTypeAnnotationWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeRuntimeVisibleTypeAnnotations;
6 | import org.mve.asm.file.constant.ConstantArray;
7 |
8 | public class RuntimeVisibleTypeAnnotationWriter extends TypeAnnotationArray implements AttributeWriter
9 | {
10 | @Override
11 | public Attribute getAttribute(ConstantArray pool)
12 | {
13 | AttributeRuntimeVisibleTypeAnnotations attribute = new AttributeRuntimeVisibleTypeAnnotations();
14 | attribute.name = ConstantPoolFinder.findUTF8(pool, attribute.type().getName());
15 | attribute.annotation = this.array(pool);
16 | return attribute;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/SignatureWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeSignature;
6 | import org.mve.asm.file.attribute.AttributeType;
7 | import org.mve.asm.file.constant.ConstantArray;
8 |
9 | public class SignatureWriter implements AttributeWriter
10 | {
11 | public String signature;
12 |
13 | public SignatureWriter(String signature)
14 | {
15 | this.signature = signature;
16 | }
17 |
18 | @Override
19 | public Attribute getAttribute(ConstantArray pool)
20 | {
21 | AttributeSignature attr = new AttributeSignature();
22 | attr.name = ConstantPoolFinder.findUTF8(pool, AttributeType.SIGNATURE.getName());
23 | attr.signature = ConstantPoolFinder.findUTF8(pool, signature);
24 | return attr;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/SourceWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeSourceFile;
6 | import org.mve.asm.file.attribute.AttributeType;
7 | import org.mve.asm.file.constant.ConstantArray;
8 |
9 | public class SourceWriter implements AttributeWriter
10 | {
11 | public String source;
12 |
13 | public SourceWriter(String source)
14 | {
15 | this.source = source;
16 | }
17 |
18 | @Override
19 | public Attribute getAttribute(ConstantArray pool)
20 | {
21 | AttributeSourceFile attr = new AttributeSourceFile();
22 | attr.name = ConstantPoolFinder.findUTF8(pool, AttributeType.SOURCE_FILE.getName());
23 | attr.source = ConstantPoolFinder.findUTF8(pool, this.source);
24 | return attr;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/UnknownWriter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.attribute.Attribute;
5 | import org.mve.asm.file.attribute.AttributeUnknown;
6 | import org.mve.asm.file.constant.ConstantArray;
7 |
8 | public class UnknownWriter implements AttributeWriter
9 | {
10 | public String name;
11 | public byte[] data;
12 |
13 | public UnknownWriter(String name, byte[] data)
14 | {
15 | this.name = name;
16 | this.data = data;
17 | }
18 |
19 | public UnknownWriter name(String name)
20 | {
21 | this.name = name;
22 | return this;
23 | }
24 |
25 | public UnknownWriter data(byte[] data)
26 | {
27 | this.data = data;
28 | return this;
29 | }
30 |
31 | @Override
32 | public Attribute getAttribute(ConstantArray pool)
33 | {
34 | AttributeUnknown attribute = new AttributeUnknown();
35 | attribute.name = ConstantPoolFinder.findUTF8(pool, this.name);
36 | attribute.code = this.data;
37 | return attribute;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/ParameterAnnotation.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation;
2 |
3 | import org.mve.asm.attribute.AnnotationArray;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public class ParameterAnnotation extends AnnotationArray
7 | {
8 | public ParameterAnnotation(Annotation... annotation)
9 | {
10 | super(annotation);
11 | }
12 |
13 | public ParameterAnnotation()
14 | {
15 | super(new Annotation[0]);
16 | }
17 |
18 | public org.mve.asm.file.attribute.annotation.ParameterAnnotation annotation(ConstantArray array)
19 | {
20 | org.mve.asm.file.attribute.annotation.ParameterAnnotation annotation = new org.mve.asm.file.attribute.annotation.ParameterAnnotation();
21 | annotation.annotation = this.array(array);
22 | return annotation;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/Catch.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationCatchValue;
5 | import org.mve.asm.file.constant.ConstantArray;
6 |
7 | public class Catch extends TypeAnnotationValue
8 | {
9 | public Marker exception;
10 |
11 | public Catch(int type, Marker exception)
12 | {
13 | super(type);
14 | this.exception = exception;
15 | }
16 |
17 | public Catch()
18 | {
19 | super(0);
20 | }
21 |
22 | public Catch exception(Marker exception)
23 | {
24 | this.exception = exception;
25 | return this;
26 | }
27 |
28 | @Override
29 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
30 | {
31 | TypeAnnotationCatchValue value = new TypeAnnotationCatchValue();
32 | value.type = this.type;
33 | value.exception = this.exception.address;
34 | return value;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/Empty.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationEmptyValue;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public class Empty extends TypeAnnotationValue
7 | {
8 | public Empty(int type)
9 | {
10 | super(type);
11 | }
12 |
13 | public Empty()
14 | {
15 | super(0);
16 | }
17 |
18 | @Override
19 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
20 | {
21 | TypeAnnotationEmptyValue value = new TypeAnnotationEmptyValue();
22 | value.type = this.type;
23 | return value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/FormalParameter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationFormalParameterValue;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public class FormalParameter extends TypeAnnotationValue
7 | {
8 | public int parameter;
9 |
10 | public FormalParameter(int type, int parameter)
11 | {
12 | super(type);
13 | this.parameter = parameter;
14 | }
15 |
16 | public FormalParameter()
17 | {
18 | super(0);
19 | }
20 |
21 | public FormalParameter parameter(int parameter)
22 | {
23 | this.parameter = parameter;
24 | return this;
25 | }
26 |
27 | @Override
28 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
29 | {
30 | TypeAnnotationFormalParameterValue value = new TypeAnnotationFormalParameterValue();
31 | value.type = this.type;
32 | value.parameter = this.parameter;
33 | return value;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/LocalVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.attribute.annotation.type.local.Variable;
4 | import org.mve.asm.attribute.code.Marker;
5 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationLocalVariableValue;
6 | import org.mve.asm.file.attribute.annotation.type.local.LocalVariableValue;
7 | import org.mve.asm.file.constant.ConstantArray;
8 |
9 | import java.util.Arrays;
10 |
11 | public class LocalVariable extends TypeAnnotationValue
12 | {
13 | public Variable[] variable = new Variable[0];
14 |
15 | public LocalVariable(int type)
16 | {
17 | super(type);
18 | }
19 |
20 | public LocalVariable()
21 | {
22 | super(0);
23 | }
24 |
25 | public LocalVariable variable(Marker from, Marker to, int slot)
26 | {
27 | this.variable = Arrays.copyOf(this.variable, this.variable.length+1);
28 | this.variable[this.variable.length-1] = new Variable(from, to, slot);
29 | return this;
30 | }
31 |
32 | @Override
33 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
34 | {
35 | TypeAnnotationLocalVariableValue value = new TypeAnnotationLocalVariableValue();
36 | value.type = this.type;
37 | for (Variable variable : this.variable)
38 | {
39 | LocalVariableValue local = new LocalVariableValue();
40 | local.start = variable.from.address;
41 | local.length = variable.from.address = local.start;
42 | local.slot = variable.slot;
43 | value.local(local);
44 | }
45 | return value;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/Offset.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationOffsetValue;
5 | import org.mve.asm.file.constant.ConstantArray;
6 |
7 | public class Offset extends TypeAnnotationValue
8 | {
9 | public Marker offset;
10 |
11 | public Offset(int type, Marker offset)
12 | {
13 | super(type);
14 | this.offset = offset;
15 | }
16 |
17 | public Offset()
18 | {
19 | super(0);
20 | }
21 |
22 | public Offset offset(Marker offset)
23 | {
24 | this.offset = offset;
25 | return this;
26 | }
27 |
28 | @Override
29 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
30 | {
31 | TypeAnnotationOffsetValue value = new TypeAnnotationOffsetValue();
32 | value.type = this.type;
33 | value.offset = this.offset.address;
34 | return value;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/Supertype.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationSupertypeValue;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public class Supertype extends TypeAnnotationValue
7 | {
8 | public int supertype;
9 |
10 | public Supertype(int type, int supertype)
11 | {
12 | super(type);
13 | this.supertype = supertype;
14 | }
15 |
16 | public Supertype()
17 | {
18 | super(0);
19 | }
20 |
21 | public Supertype supertype(int supertype)
22 | {
23 | this.supertype = supertype;
24 | return this;
25 | }
26 |
27 | @Override
28 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
29 | {
30 | TypeAnnotationSupertypeValue value = new TypeAnnotationSupertypeValue();
31 | value.type = this.type;
32 | value.supertype = this.supertype;
33 | return value;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/Throws.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationThrowsValue;
5 | import org.mve.asm.file.constant.ConstantArray;
6 |
7 | public class Throws extends TypeAnnotationValue
8 | {
9 | public Marker exception;
10 |
11 | public Throws(int type, Marker exception)
12 | {
13 | super(type);
14 | this.exception = exception;
15 | }
16 |
17 | public Throws()
18 | {
19 | super(0);
20 | }
21 |
22 | public Throws exception(Marker exception)
23 | {
24 | this.exception = exception;
25 | return this;
26 | }
27 |
28 | @Override
29 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
30 | {
31 | TypeAnnotationThrowsValue value = new TypeAnnotationThrowsValue();
32 | value.type = this.type;
33 | value.thrown = this.exception.address;
34 | return null;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/TypeAnnotationValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 |
5 | public abstract class TypeAnnotationValue>
6 | {
7 | public int type;
8 |
9 | public TypeAnnotationValue(int type)
10 | {
11 | this.type = type;
12 | }
13 |
14 | @SuppressWarnings("unchecked")
15 | public T type(int type)
16 | {
17 | this.type = type;
18 | return (T) this;
19 | }
20 |
21 | public abstract org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/TypeArgument.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationTypeArgumentValue;
5 | import org.mve.asm.file.constant.ConstantArray;
6 |
7 | public class TypeArgument extends TypeAnnotationValue
8 | {
9 | public Marker offset;
10 | public int argument;
11 |
12 | public TypeArgument(int type, Marker offset, int argument)
13 | {
14 | super(type);
15 | this.offset = offset;
16 | this.argument = argument;
17 | }
18 |
19 | public TypeArgument()
20 | {
21 | super(0);
22 | }
23 |
24 | public TypeArgument offset(Marker offset)
25 | {
26 | this.offset = offset;
27 | return this;
28 | }
29 |
30 | public TypeArgument argument(int argument)
31 | {
32 | this.argument = argument;
33 | return this;
34 | }
35 |
36 | @Override
37 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
38 | {
39 | TypeAnnotationTypeArgumentValue value = new TypeAnnotationTypeArgumentValue();
40 | value.type = this.type;
41 | value.offset = this.offset.address;
42 | value.argument = this.argument;
43 | return value;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/TypeParameter.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationTypeParameterValue;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public class TypeParameter extends TypeAnnotationValue
7 | {
8 | public int parameter;
9 |
10 | public TypeParameter(int type, int parameter)
11 | {
12 | super(type);
13 | this.parameter = parameter;
14 | }
15 |
16 | public TypeParameter()
17 | {
18 | super(0);
19 | }
20 |
21 | public TypeParameter parameter(int parameter)
22 | {
23 | this.parameter = parameter;
24 | return this;
25 | }
26 |
27 | @Override
28 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
29 | {
30 | TypeAnnotationTypeParameterValue value = new TypeAnnotationTypeParameterValue();
31 | value.type = this.type;
32 | value.parameter = this.parameter;
33 | return value;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/TypeParameterBound.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.TypeAnnotationTypeParameterBoundValue;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public class TypeParameterBound extends TypeAnnotationValue
7 | {
8 | public int parameter;
9 | public int bound;
10 |
11 | public TypeParameterBound(int type, int parameter, int bound)
12 | {
13 | super(type);
14 | this.parameter = parameter;
15 | this.bound = bound;
16 | }
17 |
18 | public TypeParameterBound()
19 | {
20 | super(0);
21 | }
22 |
23 | public TypeParameterBound parameter(int parameter)
24 | {
25 | this.parameter = parameter;
26 | return this;
27 | }
28 |
29 | public TypeParameterBound bound(int bound)
30 | {
31 | this.bound = bound;
32 | return this;
33 | }
34 |
35 | @Override
36 | public org.mve.asm.file.attribute.annotation.type.TypeAnnotationValue value(ConstantArray array)
37 | {
38 | TypeAnnotationTypeParameterBoundValue value = new TypeAnnotationTypeParameterBoundValue();
39 | value.type = this.type;
40 | value.parameter = this.parameter;
41 | value.bound = this.bound;
42 | return value;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/local/Variable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type.local;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 |
5 | public class Variable
6 | {
7 | public Marker from;
8 | public Marker to;
9 | public int slot;
10 |
11 | public Variable(Marker from, Marker to, int slot)
12 | {
13 | this.from = from;
14 | this.to = to;
15 | this.slot = slot;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/type/location/Location.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.type.location;
2 |
3 | public class Location
4 | {
5 | public int kind;
6 | public int argument;
7 |
8 | public Location(int kind, int argument)
9 | {
10 | this.kind = kind;
11 | this.argument = argument;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/value/Array.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.value;
2 |
3 | import org.mve.asm.attribute.annotation.NameAndValue;
4 |
5 | import java.util.Arrays;
6 |
7 | public class Array
8 | {
9 | public NameAndValue[] value;
10 |
11 | public Array(NameAndValue... value)
12 | {
13 | this.value = value;
14 | }
15 |
16 | public Array()
17 | {
18 | this.value = new NameAndValue[0];
19 | }
20 |
21 | public Array value(String name, Object value)
22 | {
23 | return this.value(new NameAndValue(name, value));
24 | }
25 |
26 | public Array value(NameAndValue value)
27 | {
28 | this.value = Arrays.copyOf(this.value, this.value.length+1);
29 | this.value[this.value.length-1] = value;
30 | return this;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/annotation/value/Enum.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.annotation.value;
2 |
3 | public class Enum
4 | {
5 | public String name;
6 | public String value;
7 |
8 | public Enum(String name, String value)
9 | {
10 | this.name = name;
11 | this.value = value;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/bootstrap/BootstrapMethod.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.bootstrap;
2 |
3 | import org.mve.asm.constant.MethodHandle;
4 |
5 | import java.util.Arrays;
6 |
7 | public class BootstrapMethod
8 | {
9 | public MethodHandle method;
10 | public Object[] argument = new Object[0];
11 |
12 | public BootstrapMethod(MethodHandle method, Object... argument)
13 | {
14 | this.method = method;
15 | this.argument = argument;
16 | }
17 |
18 | public BootstrapMethod()
19 | {
20 | }
21 |
22 | public BootstrapMethod method(MethodHandle method)
23 | {
24 | this.method = method;
25 | return this;
26 | }
27 |
28 | public BootstrapMethod argument(Object value)
29 | {
30 | this.argument = Arrays.copyOf(this.argument, this.argument.length+1);
31 | this.argument[this.argument.length-1] = value;
32 | return this;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Constant.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.Opcodes;
4 | import org.mve.asm.constant.ConstantValue;
5 | import org.mve.asm.file.constant.ConstantArray;
6 | import org.mve.io.RandomAccessByteArray;
7 |
8 | import java.util.Map;
9 |
10 | public class Constant extends Instruction
11 | {
12 | public final Object value;
13 |
14 | public Constant(Object value)
15 | {
16 | super(Opcodes.LDC);
17 | this.value = value;
18 | }
19 |
20 | @Override
21 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
22 | {
23 | int i = ConstantValue.constant(pool, this.value);
24 | if (this.value instanceof Long || this.value instanceof Double)
25 | {
26 | array.write(Opcodes.LDC2_W);
27 | array.writeShort(i);
28 | }
29 | else if (i > 255)
30 | {
31 | array.write(Opcodes.LDC_W);
32 | array.writeShort(i);
33 | }
34 | else
35 | {
36 | array.write(Opcodes.LDC);
37 | array.write(i);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Dynamic.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.Opcodes;
5 | import org.mve.asm.file.constant.ConstantArray;
6 | import org.mve.io.RandomAccessByteArray;
7 |
8 | import java.util.Map;
9 |
10 | public class Dynamic extends Instruction
11 | {
12 | public Marker bootstrap;
13 | public String name;
14 | public String type;
15 | public boolean constant;
16 |
17 | public Dynamic(Marker bootstrap, String name, String type, boolean constant)
18 | {
19 | super(Opcodes.INVOKEDYNAMIC);
20 | this.bootstrap = bootstrap;
21 | this.name = name;
22 | this.type = type;
23 | this.constant = constant;
24 | }
25 |
26 | @Override
27 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
28 | {
29 | if (this.constant)
30 | {
31 | int dynamic = ConstantPoolFinder.findDynamic(pool, this.bootstrap.address, this.name, this.type);
32 | if (dynamic > 255)
33 | {
34 | array.write(Opcodes.LDC_W);
35 | array.writeShort(dynamic);
36 | }
37 | else
38 | {
39 | array.write(Opcodes.LDC);
40 | array.write(dynamic);
41 | }
42 | }
43 | else
44 | {
45 | array.write(this.opcode);
46 | array.writeShort(ConstantPoolFinder.findInvokeDynamic(pool, this.bootstrap.address, this.name, this.type));
47 | array.writeShort(0);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Element.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.io.RandomAccessByteArray;
5 |
6 | import java.util.Map;
7 |
8 | public interface Element
9 | {
10 | void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker);
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Field.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.io.RandomAccessByteArray;
6 |
7 | import java.util.Map;
8 |
9 | public class Field extends Instruction
10 | {
11 | public final String type;
12 | public final String name;
13 | public final String desc;
14 |
15 | public Field(int opcode, String type, String name, String desc)
16 | {
17 | super(opcode);
18 | this.type = type;
19 | this.name = name;
20 | this.desc = desc;
21 | }
22 |
23 | @Override
24 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
25 | {
26 | super.consume(pool, array, wide, marker);
27 | array.writeShort(ConstantPoolFinder.findField(pool, this.type, this.name, this.desc));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Iinc.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.Opcodes;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.io.RandomAccessByteArray;
6 |
7 | import java.util.Map;
8 |
9 | public class Iinc extends Instruction
10 | {
11 | public final int indexbyte;
12 | public final int constbyte;
13 |
14 | public Iinc(int indexbyte, int constbyte)
15 | {
16 | super(Opcodes.IINC);
17 | this.indexbyte = indexbyte;
18 | this.constbyte = constbyte;
19 | }
20 |
21 | @Override
22 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
23 | {
24 | super.consume(pool, array, wide, marker);
25 | if (wide[0])
26 | {
27 | array.writeShort(this.indexbyte);
28 | array.writeShort(this.constbyte);
29 | }
30 | else
31 | {
32 | array.write(this.indexbyte);
33 | array.write(this.constbyte);
34 | }
35 | wide[0] = false;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Instruction.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.io.RandomAccessByteArray;
5 |
6 | import java.util.Map;
7 |
8 | public abstract class Instruction implements Element
9 | {
10 | public final int opcode;
11 |
12 | public Instruction(int opcode)
13 | {
14 | this.opcode = opcode;
15 | }
16 |
17 | @Override
18 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
19 | {
20 | array.write(this.opcode);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/InterfaceMethod.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | public class InterfaceMethod extends Method
4 | {
5 | public final int count;
6 |
7 | public InterfaceMethod(int opcode, String type, String name, String desc, int count)
8 | {
9 | super(opcode, type, name, desc, true);
10 | this.count = count;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Jump.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.Opcodes;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.io.RandomAccessByteArray;
6 |
7 | import java.util.Map;
8 |
9 | public class Jump extends Instruction
10 | {
11 | public final Marker marker;
12 |
13 | public Jump(int opcode, Marker marker)
14 | {
15 | super(opcode);
16 | this.marker = marker;
17 | }
18 |
19 | @Override
20 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
21 | {
22 | int base = array.position();
23 | super.consume(pool, array, wide, marker);
24 | marker.put(new int[]{array.position(), this.opcode, base}, this.marker);
25 | if (this.opcode == Opcodes.GOTO_W)
26 | {
27 | array.writeInt(0);
28 | }
29 | else
30 | {
31 | array.writeShort(0);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/LocalVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.io.RandomAccessByteArray;
5 |
6 | import java.util.Map;
7 |
8 | public class LocalVariable extends Instruction
9 | {
10 | public final int index;
11 |
12 | public LocalVariable(int opcode, int index)
13 | {
14 | super(opcode);
15 | this.index = index;
16 | }
17 |
18 | @Override
19 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
20 | {
21 | super.consume(pool, array, wide, marker);
22 | if (wide[0])
23 | {
24 | array.writeShort(this.index);
25 | }
26 | else
27 | {
28 | array.write(this.index);
29 | }
30 | wide[0] = false;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Marker.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.io.RandomAccessByteArray;
5 |
6 | import java.util.Map;
7 |
8 | public class Marker implements Element
9 | {
10 | public int address = 0;
11 |
12 | @Override
13 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
14 | {
15 | this.address = array.position();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Method.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.Opcodes;
5 | import org.mve.asm.file.constant.ConstantArray;
6 | import org.mve.io.RandomAccessByteArray;
7 |
8 | import java.util.Map;
9 |
10 | public class Method extends Instruction
11 | {
12 | public final String type;
13 | public final String name;
14 | public final String desc;
15 | public final boolean isAbstract;
16 |
17 | public Method(int opcode, String type, String name, String desc, boolean isAbstract)
18 | {
19 | super(opcode);
20 | this.type = type;
21 | this.name = name;
22 | this.desc = desc;
23 | this.isAbstract = isAbstract;
24 | }
25 |
26 | @Override
27 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
28 | {
29 | super.consume(pool, array, wide, marker);
30 | array.writeShort(ConstantPoolFinder.findMethod(pool, this.type, this.name, this.desc, this.isAbstract));
31 | if (this.opcode == Opcodes.INVOKEINTERFACE)
32 | {
33 | array.write(((InterfaceMethod)this).count);
34 | array.write(0);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Multianewarray.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.Opcodes;
5 | import org.mve.asm.file.constant.ConstantArray;
6 | import org.mve.io.RandomAccessByteArray;
7 |
8 | import java.util.Map;
9 |
10 | public class Multianewarray extends Instruction
11 | {
12 | public String type;
13 | public int dimension;
14 |
15 | public Multianewarray(String type, int dimension)
16 | {
17 | super(Opcodes.MULTIANEWARRAY);
18 | this.type = type;
19 | this.dimension = dimension;
20 | }
21 |
22 | @Override
23 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
24 | {
25 | super.consume(pool, array, wide, marker);
26 | array.writeShort(ConstantPoolFinder.findClass(pool, this.type));
27 | array.write(this.dimension);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Newarray.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.Opcodes;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.io.RandomAccessByteArray;
6 |
7 | import java.util.Map;
8 |
9 | public class Newarray extends Instruction
10 | {
11 | public int type;
12 |
13 | public Newarray(int type)
14 | {
15 | super(Opcodes.NEWARRAY);
16 | this.type = type;
17 | }
18 |
19 | @Override
20 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
21 | {
22 | super.consume(pool, array, wide, marker);
23 | array.write(this.type);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Number.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.Opcodes;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.io.RandomAccessByteArray;
6 |
7 | import java.util.Map;
8 |
9 | public class Number extends Instruction
10 | {
11 | public final int num;
12 |
13 | public Number(int opcode, int num)
14 | {
15 | super(opcode);
16 | this.num = num;
17 | }
18 |
19 | @Override
20 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
21 | {
22 | super.consume(pool, array, wide, marker);
23 | if (this.opcode == Opcodes.BIPUSH) array.write(this.num);
24 | else if (this.opcode == Opcodes.SIPUSH) array.writeShort(this.num);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Simple.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | public class Simple extends Instruction
4 | {
5 | public Simple(int opcode)
6 | {
7 | super(opcode);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/Type.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.io.RandomAccessByteArray;
6 |
7 | import java.util.Map;
8 |
9 | public class Type extends Instruction
10 | {
11 | public final String type;
12 |
13 | public Type(int opcode, String type)
14 | {
15 | super(opcode);
16 | this.type = type;
17 | }
18 |
19 | @Override
20 | public void consume(ConstantArray pool, RandomAccessByteArray array, boolean[] wide, Map marker)
21 | {
22 | super.consume(pool, array, wide, marker);
23 | array.writeShort(ConstantPoolFinder.findClass(pool, this.type));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/exception/Exception.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.exception;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 |
5 | public class Exception
6 | {
7 | public Marker start;
8 | public Marker end;
9 | public Marker caught;
10 | public String type;
11 |
12 | public Exception(Marker start, Marker end, Marker caught, String type)
13 | {
14 | this.start = start;
15 | this.end = end;
16 | this.caught = caught;
17 | this.type = type;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/local/LocalVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.local;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.attribute.code.Marker;
5 | import org.mve.asm.file.constant.ConstantArray;
6 |
7 | public class LocalVariable
8 | {
9 | public Marker from;
10 | public Marker to;
11 | public int slot;
12 | public String name;
13 | public String type;
14 |
15 | public LocalVariable(Marker from, Marker to, int slot, String name, String type)
16 | {
17 | this.from = from;
18 | this.to = to;
19 | this.slot = slot;
20 | this.name = name;
21 | this.type = type;
22 | }
23 |
24 | public org.mve.asm.file.attribute.local.LocalVariable transform(ConstantArray pool)
25 | {
26 | org.mve.asm.file.attribute.local.LocalVariable lvt = new org.mve.asm.file.attribute.local.LocalVariable();
27 | lvt.start = this.from.address;
28 | lvt.length = (this.to.address - this.from.address);
29 | lvt.slot = this.slot;
30 | lvt.name = ConstantPoolFinder.findUTF8(pool, this.name);
31 | lvt.type = ConstantPoolFinder.findUTF8(pool, this.type);
32 | return lvt;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/AppendFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.asm.file.attribute.stack.StackMapAppendFrame;
6 | import org.mve.asm.file.attribute.stack.StackMapFrameType;
7 | import org.mve.asm.attribute.code.stack.verification.Verification;
8 |
9 | import java.util.Arrays;
10 |
11 | public class AppendFrame extends StackMapFrame
12 | {
13 | /**
14 | * length = k
15 | * k = frame_type - 251
16 | */
17 | public Verification[] verification;
18 |
19 | public AppendFrame verification(Verification verification)
20 | {
21 | this.verification = Arrays.copyOf(this.verification, this.verification.length+1);
22 | this.verification[this.verification.length-1] = verification;
23 | return this;
24 | }
25 |
26 | @Override
27 | public AppendFrame mark(Marker marker)
28 | {
29 | return (AppendFrame) super.mark(marker);
30 | }
31 |
32 | @Override
33 | public org.mve.asm.file.attribute.stack.StackMapFrame transform(int previous, ConstantArray pool)
34 | {
35 | StackMapAppendFrame frame = new StackMapAppendFrame();
36 | frame.type = StackMapFrameType.STACK_MAP_APPEND_FRAME.low() + this.verification.length - 1;
37 | frame.verification = new org.mve.asm.file.attribute.stack.verification.Verification[this.verification.length];
38 | frame.offset = this.marker.address - previous;
39 | for (int i = 0; i < this.verification.length; i++)
40 | {
41 | frame.verification[i] = this.verification[i].transform(pool);
42 | }
43 | return frame;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/ChopFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.asm.file.attribute.stack.StackMapChopFrame;
6 | import org.mve.asm.file.attribute.stack.StackMapFrameType;
7 |
8 | public class ChopFrame extends StackMapFrame
9 | {
10 | /**
11 | * k, k = 251 - frame_type
12 | */
13 | public int chop;
14 |
15 | /**
16 | * k, frame_type = 251 - k
17 | *
18 | * @param i count of local variables to chop
19 | * @return this
20 | */
21 | public ChopFrame chop(int i)
22 | {
23 | this.chop = (StackMapFrameType.STACK_MAP_CHOP_FRAME.high() - i) + 1;
24 | return this;
25 | }
26 |
27 | @Override
28 | public ChopFrame mark(Marker marker)
29 | {
30 | return (ChopFrame) super.mark(marker);
31 | }
32 |
33 | @Override
34 | public org.mve.asm.file.attribute.stack.StackMapFrame transform(int previous, ConstantArray pool)
35 | {
36 | StackMapChopFrame frame = new StackMapChopFrame();
37 | frame.type = this.chop;
38 | frame.offset = this.marker.address - previous;
39 | return frame;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/SameFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.attribute.stack.StackMapFrameType;
5 | import org.mve.asm.file.attribute.stack.StackMapSameFrameExtended;
6 | import org.mve.asm.file.constant.ConstantArray;
7 | import org.mve.asm.file.attribute.stack.StackMapSameFrame;
8 |
9 | public class SameFrame extends StackMapFrame
10 | {
11 | @Override
12 | public SameFrame mark(Marker marker)
13 | {
14 | return (SameFrame) super.mark(marker);
15 | }
16 |
17 | @Override
18 | public org.mve.asm.file.attribute.stack.StackMapFrame transform(int previous, ConstantArray pool)
19 | {
20 | int offset = this.marker.address - previous;
21 | if (offset > 63)
22 | {
23 | StackMapSameFrameExtended frame = new StackMapSameFrameExtended();
24 | frame.type = StackMapFrameType.STACK_MAP_SAME_FRAME_EXTENDED.low();
25 | frame.offset = offset;
26 | return frame;
27 | }
28 | else
29 | {
30 | StackMapSameFrame frame = new StackMapSameFrame();
31 | frame.type = this.marker.address - previous;
32 | return frame;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/SameFrameExtended.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.asm.file.attribute.stack.StackMapFrameType;
6 | import org.mve.asm.file.attribute.stack.StackMapSameFrameExtended;
7 |
8 | public class SameFrameExtended extends StackMapFrame
9 | {
10 | @Override
11 | public SameFrameExtended mark(Marker marker)
12 | {
13 | return (SameFrameExtended) super.mark(marker);
14 | }
15 |
16 | @Override
17 | public org.mve.asm.file.attribute.stack.StackMapFrame transform(int previous, ConstantArray pool)
18 | {
19 | StackMapSameFrameExtended frame = new StackMapSameFrameExtended();
20 | frame.type = StackMapFrameType.STACK_MAP_SAME_FRAME_EXTENDED.high();
21 | frame.offset = this.marker.address - previous;
22 | return frame;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/SameLocals1StackItemFrameExtended.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.asm.file.attribute.stack.StackMapFrameType;
6 | import org.mve.asm.file.attribute.stack.StackMapSameLocals1StackItemFrameExtended;
7 | import org.mve.asm.attribute.code.stack.verification.Verification;
8 |
9 | public class SameLocals1StackItemFrameExtended extends StackMapFrame
10 | {
11 | public Verification verification;
12 |
13 | @Override
14 | public SameLocals1StackItemFrameExtended mark(Marker marker)
15 | {
16 | return (SameLocals1StackItemFrameExtended) super.mark(marker);
17 | }
18 |
19 | public SameLocals1StackItemFrameExtended verification(Verification verification)
20 | {
21 | this.verification = verification;
22 | return this;
23 | }
24 |
25 | @Override
26 | public org.mve.asm.file.attribute.stack.StackMapFrame transform(int previous, ConstantArray pool)
27 | {
28 | StackMapSameLocals1StackItemFrameExtended frame = new StackMapSameLocals1StackItemFrameExtended();
29 | frame.type = StackMapFrameType.STACK_MAP_SAME_LOCALS_1_ITEM_FRAME_EXTENDED.low();
30 | frame.offset = this.marker.address - previous;
31 | frame.verification = this.verification.transform(pool);
32 | return frame;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/StackMapFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public abstract class StackMapFrame
7 | {
8 | public Marker marker;
9 |
10 | public StackMapFrame mark(Marker marker)
11 | {
12 | this.marker = marker;
13 | return this;
14 | }
15 |
16 | public int mark()
17 | {
18 | return this.marker.address;
19 | }
20 |
21 | public abstract org.mve.asm.file.attribute.stack.StackMapFrame transform(int previous, ConstantArray pool);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/DoubleVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationDoubleVariable;
5 |
6 | public class DoubleVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationDoubleVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/FloatVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationFloatVariable;
5 |
6 | public class FloatVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationFloatVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/IntegerVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationIntegerVariable;
5 |
6 | public class IntegerVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationIntegerVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/LongVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationLongVariable;
5 |
6 | public class LongVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationLongVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/NullVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationNullVariable;
5 |
6 | public class NullVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationNullVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/ObjectVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.ConstantPoolFinder;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.asm.file.attribute.stack.verification.VerificationObjectVariable;
6 |
7 | public class ObjectVariable implements Verification
8 | {
9 | private final String type;
10 |
11 | public ObjectVariable(String type)
12 | {
13 | this.type = type;
14 | }
15 |
16 | @Override
17 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
18 | {
19 | VerificationObjectVariable variable = new VerificationObjectVariable();
20 | variable.type = (short) ConstantPoolFinder.findClass(pool, this.type);
21 | return variable;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/TopVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationTopVariable;
5 |
6 | public class TopVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationTopVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/UninitializedThisVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.file.constant.ConstantArray;
4 | import org.mve.asm.file.attribute.stack.verification.VerificationUninitializedThisVariable;
5 |
6 | public class UninitializedThisVariable implements Verification
7 | {
8 | @Override
9 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
10 | {
11 | return new VerificationUninitializedThisVariable();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/UninitializedVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 | import org.mve.asm.file.attribute.stack.verification.VerificationUninitializedVariable;
6 |
7 | public class UninitializedVariable implements Verification
8 | {
9 | private final Marker offset;
10 |
11 | public UninitializedVariable(Marker offset)
12 | {
13 | this.offset = offset;
14 | }
15 |
16 | @Override
17 | public org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool)
18 | {
19 | VerificationUninitializedVariable variable = new VerificationUninitializedVariable();
20 | variable.offset = (short) this.offset.address;
21 | return variable;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/code/stack/verification/Verification.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.code.stack.verification;
2 |
3 | import org.mve.asm.attribute.code.Marker;
4 | import org.mve.asm.file.constant.ConstantArray;
5 |
6 | public interface Verification
7 | {
8 | org.mve.asm.file.attribute.stack.verification.Verification transform(ConstantArray pool);
9 |
10 | static Verification topVariable()
11 | {
12 | return new TopVariable();
13 | }
14 |
15 | static Verification integerVariable()
16 | {
17 | return new IntegerVariable();
18 | }
19 |
20 | static Verification floatVariable()
21 | {
22 | return new FloatVariable();
23 | }
24 |
25 | static Verification nullVariable()
26 | {
27 | return new NullVariable();
28 | }
29 |
30 | static Verification uninitializedThisVariable()
31 | {
32 | return new UninitializedThisVariable();
33 | }
34 |
35 | static Verification objectVariable(String type)
36 | {
37 | return new ObjectVariable(type);
38 | }
39 |
40 | static Verification uninitializedVariable(Marker marker)
41 | {
42 | return new UninitializedVariable(marker);
43 | }
44 |
45 | static Verification longVariable()
46 | {
47 | return new LongVariable();
48 | }
49 |
50 | static Verification doubleVariable()
51 | {
52 | return new DoubleVariable();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/inner/InnerClass.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.inner;
2 |
3 | public class InnerClass
4 | {
5 | public String inner;
6 | public String outer;
7 | public String name;
8 | public int access;
9 |
10 | public InnerClass(String inner, String outer, String name, int access)
11 | {
12 | this.inner = inner;
13 | this.outer = outer;
14 | this.name = name;
15 | this.access = access;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/method/Argument.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.method;
2 |
3 | public class Argument
4 | {
5 | public String name;
6 | public int access;
7 |
8 | public Argument(String name, int access)
9 | {
10 | this.name = name;
11 | this.access = access;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/module/Export.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.module;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Export
6 | {
7 | public String name;
8 | public int flag;
9 | public String[] to = new String[0];
10 |
11 | public Export name(String name)
12 | {
13 | this.name = name;
14 | return this;
15 | }
16 |
17 | public Export flag(int flag)
18 | {
19 | this.flag = flag;
20 | return this;
21 | }
22 |
23 | public Export to(String name)
24 | {
25 | this.to = Arrays.copyOf(this.to, this.to.length+1);
26 | this.to[this.to.length-1] = name;
27 | return this;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/module/Open.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.module;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Open
6 | {
7 | public String name;
8 | public int flag;
9 | public String[] to = new String[0];
10 |
11 | public Open name(String name)
12 | {
13 | this.name = name;
14 | return this;
15 | }
16 |
17 | public Open flag(int flag)
18 | {
19 | this.flag = flag;
20 | return this;
21 | }
22 |
23 | public Open to(String name)
24 | {
25 | this.to = Arrays.copyOf(this.to, this.to.length+1);
26 | this.to[this.to.length-1] = name;
27 | return this;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/module/Provide.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.module;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Provide
6 | {
7 | public String name;
8 | public String[] with = new String[0];
9 |
10 | public Provide name(String name)
11 | {
12 | this.name = name;
13 | return this;
14 | }
15 |
16 | public Provide with(String name)
17 | {
18 | this.with = Arrays.copyOf(this.with, this.with.length+1);
19 | this.with[this.with.length-1] = name;
20 | return this;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/module/Require.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.module;
2 |
3 | public class Require
4 | {
5 | public String name;
6 | public int flag;
7 | public String version;
8 |
9 | public Require name(String name)
10 | {
11 | this.name = name;
12 | return this;
13 | }
14 |
15 | public Require flag(int flag)
16 | {
17 | this.flag = flag;
18 | return this;
19 | }
20 |
21 | public Require version(String version)
22 | {
23 | this.version = version;
24 | return this;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/attribute/record/Record.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.attribute.record;
2 |
3 | import org.mve.asm.attribute.AttributeWriter;
4 |
5 | import java.util.Arrays;
6 |
7 | public class Record
8 | {
9 | public String name;
10 | public String type;
11 | public AttributeWriter[] attribute;
12 |
13 | public Record(String name, String type, AttributeWriter... attribute)
14 | {
15 | this.name = name;
16 | this.type = type;
17 | this.attribute = attribute;
18 | }
19 |
20 | public Record()
21 | {
22 | }
23 |
24 | public Record name(String name)
25 | {
26 | this.name = name;
27 | return this;
28 | }
29 |
30 | public Record type(String type)
31 | {
32 | this.type = type;
33 | return this;
34 | }
35 |
36 | public Record attribute(AttributeWriter attribute)
37 | {
38 | this.attribute = Arrays.copyOf(this.attribute, this.attribute.length+1);
39 | this.attribute[this.attribute.length-1] = attribute;
40 | return this;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/constant/MethodHandle.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.constant;
2 |
3 | public class MethodHandle
4 | {
5 | public int kind;
6 | public String type;
7 | public String name;
8 | public String sign;
9 |
10 | public MethodHandle(int kind, String type, String name, String sign)
11 | {
12 | this.kind = kind;
13 | this.type = type;
14 | this.name = name;
15 | this.sign = sign;
16 | }
17 |
18 | public MethodHandle()
19 | {
20 | }
21 |
22 | public MethodHandle kind(int kind)
23 | {
24 | this.kind = kind;
25 | return this;
26 | }
27 |
28 | public MethodHandle type(String clazz)
29 | {
30 | this.type = clazz;
31 | return this;
32 | }
33 |
34 | public MethodHandle name(String name)
35 | {
36 | this.name = name;
37 | return this;
38 | }
39 |
40 | public MethodHandle sign(String type)
41 | {
42 | this.sign = type;
43 | return this;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/constant/MethodType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.constant;
2 |
3 | public class MethodType
4 | {
5 | public String type;
6 |
7 | public MethodType(String type)
8 | {
9 | this.type = type;
10 | }
11 |
12 | public MethodType()
13 | {
14 | }
15 |
16 | public MethodType type(String type)
17 | {
18 | this.type = type;
19 | return this;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/ClassParseException.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file;
2 |
3 | public class ClassParseException extends RuntimeException
4 | {
5 | public ClassParseException(Throwable caused)
6 | {
7 | super(caused);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/ClassSerializeException.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file;
2 |
3 | public class ClassSerializeException extends RuntimeException
4 | {
5 | public ClassSerializeException(){}
6 |
7 | public ClassSerializeException(String msg)
8 | {
9 | super(msg);
10 | }
11 |
12 | public ClassSerializeException(String msg, Throwable caused)
13 | {
14 | super(msg, caused);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/Field.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file;
2 |
3 | import org.mve.asm.file.attribute.Attribute;
4 |
5 | import java.util.Arrays;
6 |
7 | public class Field
8 | {
9 | public int access;
10 | public int name;
11 | public int type;
12 | public Attribute[] attribute = new Attribute[0];
13 |
14 | public void attribute(Attribute attribute)
15 | {
16 | this.attribute = Arrays.copyOf(this.attribute, this.attribute.length+1);
17 | this.attribute[this.attribute.length-1] = attribute;
18 | }
19 |
20 | public byte[] toByteArray()
21 | {
22 | int len = 8;
23 | for (Attribute a : this.attribute) len += a.length();
24 | byte[] b = new byte[len];
25 | int index = 0;
26 | b[index++] = (byte) ((this.access >>> 8) & 0XFF);
27 | b[index++] = (byte) (this.access & 0XFF);
28 | b[index++] = (byte) ((this.name >>> 8) & 0XFF);
29 | b[index++] = (byte) (this.name & 0XFF);
30 | b[index++] = (byte) ((this.type >>> 8) & 0XFF);
31 | b[index++] = (byte) (this.type & 0XFF);
32 | b[index++] = (byte) ((this.attribute.length >>> 8) & 0XFF);
33 | b[index++] = (byte) (this.attribute.length & 0XFF);
34 | for (Attribute a : this.attribute)
35 | {
36 | int l = a.length();
37 | System.arraycopy(a.toByteArray(), 0, b, index, l);
38 | index+=l;
39 | }
40 | return b;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/Method.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file;
2 |
3 | import org.mve.asm.file.attribute.Attribute;
4 |
5 | import java.util.Arrays;
6 |
7 | public class Method
8 | {
9 | public int access;
10 | public int name;
11 | public int type;
12 | public Attribute[] attribute = new Attribute[0];
13 |
14 | public void attribute(Attribute attribute)
15 | {
16 | this.attribute = Arrays.copyOf(this.attribute, this.attribute.length+1);
17 | this.attribute[this.attribute.length-1] = attribute;
18 | }
19 |
20 | public byte[] toByteArray()
21 | {
22 | int len = 8;
23 | for (Attribute a : this.attribute) len += a.length();
24 | byte[] b = new byte[len];
25 | int index = 0;
26 | b[index++] = (byte) ((this.access >>> 8) & 0XFF);
27 | b[index++] = (byte) (this.access & 0XFF);
28 | b[index++] = (byte) ((this.name >>> 8) & 0XFF);
29 | b[index++] = (byte) (this.name & 0XFF);
30 | b[index++] = (byte) ((this.type >>> 8) & 0XFF);
31 | b[index++] = (byte) (this.type & 0XFF);
32 | b[index++] = (byte) ((this.attribute.length >>> 8) & 0XFF);
33 | b[index++] = (byte) (this.attribute.length & 0XFF);
34 | for (Attribute a : this.attribute)
35 | {
36 | int l = a.length();
37 | System.arraycopy(a.toByteArray(), 0, b, index, l);
38 | index+=l;
39 | }
40 | return b;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeAnnotationDefault.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.element.ElementValue;
4 |
5 | public class AttributeAnnotationDefault extends Attribute
6 | {
7 | public ElementValue value;
8 |
9 | @Override
10 | public AttributeType type()
11 | {
12 | return AttributeType.ANNOTATION_DEFAULT;
13 | }
14 |
15 | @Override
16 | public int length()
17 | {
18 | return this.value.length() + 6;
19 | }
20 |
21 | @Override
22 | public byte[] toByteArray()
23 | {
24 | int len = this.length();
25 | byte[] b = new byte[len];
26 | b[0] = (byte) ((this.name >>> 8) & 0xFF);
27 | b[1] = (byte) (this.name & 0xFF);
28 | len -= 6;
29 | b[2] = (byte) ((len >>> 24) & 0xFF);
30 | b[3] = (byte) ((len >>> 16) & 0xFF);
31 | b[4] = (byte) ((len >>> 8) & 0xFF);
32 | b[5] = (byte) (len & 0xFF);
33 | System.arraycopy(this.value.toByteArray(), 0, b, 6, len);
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeBootstrapMethods.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.bootstrap.BootstrapMethod;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeBootstrapMethods extends Attribute
8 | {
9 | public BootstrapMethod[] bootstrap = new BootstrapMethod[0];
10 |
11 | public void bootstrap(BootstrapMethod method)
12 | {
13 | this.bootstrap = Arrays.copyOf(this.bootstrap, this.bootstrap.length + 1);
14 | this.bootstrap[this.bootstrap.length-1] = method;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.BOOTSTRAP_METHODS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 8;
27 | for (BootstrapMethod s : this.bootstrap) len += s.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | b[0] = (byte) ((this.name >>> 8) & 0xFF);
37 | b[1] = (byte) (this.name & 0xFF);
38 | len -= 6;
39 | b[2] = (byte) ((len >>> 24) & 0xFF);
40 | b[3] = (byte) ((len >>> 16) & 0xFF);
41 | b[4] = (byte) ((len >>> 8) & 0xFF);
42 | b[5] = (byte) (len & 0xFF);
43 | b[6] = (byte) ((this.bootstrap.length >>> 8) & 0XFF);
44 | b[7] = (byte) (this.bootstrap.length & 0XFF);
45 | int index = 8;
46 | for (BootstrapMethod s : this.bootstrap)
47 | {
48 | int l = s.length();
49 | System.arraycopy(s.toByteArray(), 0, b, index, l);
50 | index+=l;
51 | }
52 | return b;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeConstantValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeConstantValue extends Attribute
4 | {
5 | public int value;
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return AttributeType.CONSTANT_VALUE;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 8;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | byte[] b = new byte[len];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | b[index++] = (byte) ((this.value >>> 8) & 0XFF);
33 | b[index] = (byte) (this.value & 0XFF);
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeDeprecated.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeDeprecated extends Attribute
4 | {
5 | @Override
6 | public AttributeType type()
7 | {
8 | return AttributeType.DEPRECATED;
9 | }
10 |
11 | @Override
12 | public int length()
13 | {
14 | return 6;
15 | }
16 |
17 | @Override
18 | public byte[] toByteArray()
19 | {
20 | byte[] b = new byte[6];
21 | b[0] = (byte) ((name >>> 8) & 0XFF);
22 | b[1] = (byte) (name & 0XFF);
23 | return b;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeEnclosingMethod.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeEnclosingMethod extends Attribute
4 | {
5 | public int clazz;
6 | public int method;
7 |
8 | @Override
9 | public AttributeType type()
10 | {
11 | return AttributeType.ENCLOSING_METHOD;
12 | }
13 |
14 | @Override
15 | public int length()
16 | {
17 | return 10;
18 | }
19 |
20 | @Override
21 | public byte[] toByteArray()
22 | {
23 | byte[] b = new byte[10];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | b[index++] = 0;
28 | b[index++] = 0;
29 | b[index++] = 0;
30 | b[index++] = 4;
31 | b[index++] = (byte) ((this.clazz >>> 8) & 0XFF);
32 | b[index++] = (byte) (this.clazz & 0XFF);
33 | b[index++] = (byte) ((this.method >>> 8) & 0XFF);
34 | b[index] = (byte) (this.method & 0XFF);
35 | return b;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeExceptions.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import java.util.Arrays;
4 |
5 | public class AttributeExceptions extends Attribute
6 | {
7 | public int[] exception = new int[0];
8 |
9 | public void exception(int cp)
10 | {
11 | this.exception = Arrays.copyOf(this.exception, this.exception.length + 1);
12 | this.exception[this.exception.length - 1] = cp;
13 | }
14 |
15 | @Override
16 | public AttributeType type()
17 | {
18 | return AttributeType.EXCEPTIONS;
19 | }
20 |
21 | @Override
22 | public int length()
23 | {
24 | return 8 + (2 * this.exception.length);
25 | }
26 |
27 | @Override
28 | public byte[] toByteArray()
29 | {
30 | int len = this.length();
31 | byte[] b = new byte[len];
32 | int index = 0;
33 | b[index++] = (byte) ((name >>> 8) & 0XFF);
34 | b[index++] = (byte) (name & 0XFF);
35 | len -= 6;
36 | b[index++] = (byte) ((len >>> 24) & 0XFF);
37 | b[index++] = (byte) ((len >>> 16) & 0XFF);
38 | b[index++] = (byte) ((len >>> 8) & 0XFF);
39 | b[index++] = (byte) (len & 0XFF);
40 | b[index++] = (byte) ((this.exception.length >>> 8) & 0XFF);
41 | b[index++] = (byte) (this.exception.length & 0XFF);
42 | for (int s : this.exception)
43 | {
44 | b[index++] = (byte) ((s >>> 8) & 0XFF);
45 | b[index++] = (byte) (s & 0XFF);
46 | }
47 | return b;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeInnerClasses.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.inner.InnerClass;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeInnerClasses extends Attribute
8 | {
9 | public InnerClass[] inner = new InnerClass[0];
10 |
11 | public void inner(InnerClass inner)
12 | {
13 | this.inner = Arrays.copyOf(this.inner, this.inner.length + 1);
14 | this.inner[this.inner.length - 1] = inner;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.INNER_CLASSES;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | return 8 + (8 * this.inner.length);
27 | }
28 |
29 | @Override
30 | public byte[] toByteArray()
31 | {
32 | int len = this.length();
33 | byte[] b = new byte[len];
34 | int index = 0;
35 | b[index++] = (byte) ((name >>> 8) & 0XFF);
36 | b[index++] = (byte) (name & 0XFF);
37 | len -= 6;
38 | b[index++] = (byte) ((len >>> 24) & 0XFF);
39 | b[index++] = (byte) ((len >>> 16) & 0XFF);
40 | b[index++] = (byte) ((len >>> 8) & 0XFF);
41 | b[index++] = (byte) (len & 0XFF);
42 | b[index++] = (byte) ((this.inner.length >>> 8) & 0XFF);
43 | b[index++] = (byte) (this.inner.length & 0XFF);
44 | for (InnerClass s : this.inner)
45 | {
46 | System.arraycopy(s.toByteArray(), 0, b, index, 8);
47 | index+=8;
48 | }
49 | return b;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeLineNumberTable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.line.LineNumber;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeLineNumberTable extends Attribute
8 | {
9 | public LineNumber[] line = new LineNumber[0];
10 |
11 | public void line(LineNumber line)
12 | {
13 | this.line = Arrays.copyOf(this.line, this.line.length + 1);
14 | this.line[this.line.length - 1] = line;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.LINE_NUMBER_TABLE;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | return 8 + (4 * this.line.length);
27 | }
28 |
29 | @Override
30 | public byte[] toByteArray()
31 | {
32 | int len = this.length();
33 | byte[] b = new byte[len];
34 | int index = 0;
35 | b[index++] = (byte) ((name >>> 8) & 0XFF);
36 | b[index++] = (byte) (name & 0XFF);
37 | len -= 6;
38 | b[index++] = (byte) ((len >>> 24) & 0XFF);
39 | b[index++] = (byte) ((len >>> 16) & 0XFF);
40 | b[index++] = (byte) ((len >>> 8) & 0XFF);
41 | b[index++] = (byte) (len & 0XFF);
42 | b[index++] = (byte) ((this.line.length >>> 8) & 0XFF);
43 | b[index++] = (byte) (this.line.length & 0XFF);
44 | for (LineNumber s : this.line)
45 | {
46 | System.arraycopy(s.toByteArray(), 0, b, index, 4);
47 | index+=4;
48 | }
49 | return b;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeLocalVariableTable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.local.LocalVariable;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeLocalVariableTable extends Attribute
8 | {
9 | public LocalVariable[] local = new LocalVariable[0];
10 |
11 | public void local(LocalVariable local)
12 | {
13 | this.local = Arrays.copyOf(this.local, this.local.length + 1);
14 | this.local[this.local.length - 1] = local;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.LOCAL_VARIABLE_TABLE;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | return 8 + (10 * this.local.length);
27 | }
28 |
29 | @Override
30 | public byte[] toByteArray()
31 | {
32 | int len = this.length();
33 | byte[] b = new byte[len];
34 | int index = 0;
35 | b[index++] = (byte) ((name >>> 8) & 0XFF);
36 | b[index++] = (byte) (name & 0XFF);
37 | len -= 6;
38 | b[index++] = (byte) ((len >>> 24) & 0XFF);
39 | b[index++] = (byte) ((len >>> 16) & 0XFF);
40 | b[index++] = (byte) ((len >>> 8) & 0XFF);
41 | b[index++] = (byte) (len & 0XFF);
42 | b[index++] = (byte) ((this.local.length >>> 8) & 0XFF);
43 | b[index++] = (byte) (this.local.length & 0XFF);
44 | for (LocalVariable s : this.local)
45 | {
46 | System.arraycopy(s.toByteArray(), 0, b, index, 10);
47 | index+=10;
48 | }
49 | return b;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeLocalVariableTypeTable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeLocalVariableTypeTable extends AttributeLocalVariableTable
4 | {
5 | @Override
6 | public AttributeType type()
7 | {
8 | return AttributeType.LOCAL_VARIABLE_TYPE_TABLE;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeMethodArguments.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.method.Argument;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeMethodArguments extends Attribute
8 | {
9 | public Argument[] argument = new Argument[0];
10 |
11 | public void argument(Argument argument)
12 | {
13 | this.argument = Arrays.copyOf(this.argument, this.argument.length + 1);
14 | this.argument[this.argument.length-1] = argument;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.METHOD_PARAMETERS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | return 7 + (this.argument.length * 4);
27 | }
28 |
29 | @Override
30 | public byte[] toByteArray()
31 | {
32 | int len = this.length();
33 | byte[] b = new byte[len];
34 | int index = 0;
35 | b[index++] = (byte) ((name >>> 8) & 0XFF);
36 | b[index++] = (byte) (name & 0XFF);
37 | len -= 6;
38 | b[index++] = (byte) ((len >>> 24) & 0XFF);
39 | b[index++] = (byte) ((len >>> 16) & 0XFF);
40 | b[index++] = (byte) ((len >>> 8) & 0XFF);
41 | b[index++] = (byte) (len & 0XFF);
42 | b[index++] = (byte) this.argument.length;
43 | for (Argument s : this.argument)
44 | {
45 | System.arraycopy(s.toByteArray(), 0, b, index, 4);
46 | index+=4;
47 | }
48 | return b;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeModuleMainClass.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeModuleMainClass extends Attribute
4 | {
5 | public int main;
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return AttributeType.MODULE_MAIN_CLASS;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 8;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | byte[] b = new byte[len];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | b[index++] = (byte) ((this.main >>> 8) & 0XFF);
33 | b[index] = (byte) (this.main & 0XFF);
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeModulePackages.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import java.util.Arrays;
4 |
5 | public class AttributeModulePackages extends Attribute
6 | {
7 | public int[] packages = new int[0];
8 |
9 | public void packages(int pkg)
10 | {
11 | this.packages = Arrays.copyOf(this.packages, this.packages.length+1);
12 | this.packages[this.packages.length-1] = pkg;
13 | }
14 |
15 | @Override
16 | public AttributeType type()
17 | {
18 | return AttributeType.MODULE_PACKAGES;
19 | }
20 |
21 | @Override
22 | public int length()
23 | {
24 | return 8 + (2 * this.packages.length);
25 | }
26 |
27 | @Override
28 | public byte[] toByteArray()
29 | {
30 | int len = this.length();
31 | byte[] b = new byte[len];
32 | int index = 0;
33 | b[index++] = (byte) ((name >>> 8) & 0XFF);
34 | b[index++] = (byte) (name & 0XFF);
35 | len -= 6;
36 | b[index++] = (byte) ((len >>> 24) & 0XFF);
37 | b[index++] = (byte) ((len >>> 16) & 0XFF);
38 | b[index++] = (byte) ((len >>> 8) & 0XFF);
39 | b[index++] = (byte) (len & 0XFF);
40 | b[index++] = (byte) ((this.packages.length >>> 8) & 0XFF);
41 | b[index++] = (byte) (this.packages.length & 0XFF);
42 | for (int s : this.packages)
43 | {
44 | b[index++] = (byte) ((s >>> 8) & 0XFF);
45 | b[index++] = (byte) (s & 0XFF);
46 | }
47 | return b;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeNestHost.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeNestHost extends Attribute
4 | {
5 | public int host;
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return AttributeType.NEST_HOST;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 8;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | byte[] b = new byte[len];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | b[index++] = (byte) ((this.host >>> 8) & 0XFF);
33 | b[index] = (byte) (this.host & 0XFF);
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeNestMembers.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import java.util.Arrays;
4 |
5 | public class AttributeNestMembers extends Attribute
6 | {
7 | public int[] classes = new int[0];
8 |
9 | public void classes(int c)
10 | {
11 | this.classes = Arrays.copyOf(this.classes, this.classes.length+1);
12 | this.classes[this.classes.length-1] = c;
13 | }
14 |
15 | @Override
16 | public AttributeType type()
17 | {
18 | return AttributeType.NEST_MEMBERS;
19 | }
20 |
21 | @Override
22 | public int length()
23 | {
24 | return 8 + (2 * this.classes.length);
25 | }
26 |
27 | @Override
28 | public byte[] toByteArray()
29 | {
30 | int len = this.length();
31 | byte[] b = new byte[len];
32 | int index = 0;
33 | b[index++] = (byte) ((name >>> 8) & 0XFF);
34 | b[index++] = (byte) (name & 0XFF);
35 | len -= 6;
36 | b[index++] = (byte) ((len >>> 24) & 0XFF);
37 | b[index++] = (byte) ((len >>> 16) & 0XFF);
38 | b[index++] = (byte) ((len >>> 8) & 0XFF);
39 | b[index++] = (byte) (len & 0XFF);
40 | b[index++] = (byte) ((this.classes.length >>> 8) & 0XFF);
41 | b[index++] = (byte) (this.classes.length & 0XFF);
42 | for (int s : this.classes)
43 | {
44 | b[index++] = (byte) ((s >>> 8) & 0XFF);
45 | b[index++] = (byte) (s & 0XFF);
46 | }
47 | return b;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributePermittedSubclasses.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import java.util.Arrays;
4 |
5 | public class AttributePermittedSubclasses extends Attribute
6 | {
7 | public int[] classes = new int[0];
8 |
9 | public void classes(int index)
10 | {
11 | int i = this.classes.length;
12 | this.classes = Arrays.copyOf(classes, i+1);
13 | this.classes[i] = index;
14 | }
15 |
16 | @Override
17 | public AttributeType type()
18 | {
19 | return AttributeType.PERMITTED_SUBCLASSES;
20 | }
21 |
22 | @Override
23 | public int length()
24 | {
25 | return 8 + (2 * this.classes.length);
26 | }
27 |
28 | @Override
29 | public byte[] toByteArray()
30 | {
31 | return new byte[0];
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeRecord.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.record.RecordComponent;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeRecord extends Attribute
8 | {
9 | public RecordComponent[] component = new RecordComponent[0];
10 |
11 | public void component(RecordComponent component)
12 | {
13 | this.component = Arrays.copyOf(this.component, this.component.length+1);
14 | this.component[this.component.length-1] = component;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.RECORD;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int l = 8;
27 | for (RecordComponent component : this.component)
28 | {
29 | l += component.length();
30 | }
31 | return l;
32 | }
33 |
34 | @Override
35 | public byte[] toByteArray()
36 | {
37 | int len = this.length();
38 | int i = 0;
39 | byte[] array = new byte[len];
40 | array[i++] = (byte) ((this.name >>> 8) & 0xFF);
41 | array[i++] = (byte) (this.name & 0xFF);
42 | len -= 6;
43 | array[i++] = (byte) (len >>> 24 & 0xFF);
44 | array[i++] = (byte) (len >>> 16 & 0xFF);
45 | array[i++] = (byte) (len >>> 8 & 0xFF);
46 | array[i++] = (byte) (len & 0xFF);
47 | array[i++] = (byte) ((this.component.length >>> 8) & 0xFF);
48 | array[i++] = (byte) (this.component.length & 0xFF);
49 | for (RecordComponent component : this.component)
50 | {
51 | int cl = component.length();
52 | System.arraycopy(component.array(), 0, array, i, cl);
53 | i += cl;
54 | }
55 | return array;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeRuntimeInvisibleAnnotations.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.annotation.Annotation;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeRuntimeInvisibleAnnotations extends Attribute
8 | {
9 | public Annotation[] annotation = new Annotation[0];
10 |
11 | public void annotation(Annotation annotation)
12 | {
13 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length + 1);
14 | this.annotation[this.annotation.length - 1] = annotation;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.RUNTIME_INVISIBLE_ANNOTATIONS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 8;
27 | for (Annotation a : this.annotation) len += a.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | int index = 0;
37 | b[index++] = (byte) ((name >>> 8) & 0XFF);
38 | b[index++] = (byte) (name & 0XFF);
39 | len -= 6;
40 | b[index++] = (byte) ((len >>> 24) & 0XFF);
41 | b[index++] = (byte) ((len >>> 16) & 0XFF);
42 | b[index++] = (byte) ((len >>> 8) & 0XFF);
43 | b[index++] = (byte) (len & 0XFF);
44 | b[index++] = (byte) ((this.annotation.length >>> 8) & 0XFF);
45 | b[index++] = (byte) (this.annotation.length & 0XFF);
46 | for (Annotation s : this.annotation)
47 | {
48 | int l = s.length();
49 | System.arraycopy(s.toByteArray(), 0, b, index, l);
50 | index+=l;
51 | }
52 | return b;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeRuntimeInvisibleParameterAnnotations.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.annotation.ParameterAnnotation;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeRuntimeInvisibleParameterAnnotations extends Attribute
8 | {
9 | public ParameterAnnotation[] annotation = new ParameterAnnotation[0];
10 |
11 | public void annotation(ParameterAnnotation annotation)
12 | {
13 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length + 1);
14 | this.annotation[this.annotation.length - 1] = annotation;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 7;
27 | for (ParameterAnnotation s : this.annotation) len += s.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | int index = 0;
37 | b[index++] = (byte) ((name >>> 8) & 0XFF);
38 | b[index++] = (byte) (name & 0XFF);
39 | len -= 6;
40 | b[index++] = (byte) ((len >>> 24) & 0XFF);
41 | b[index++] = (byte) ((len >>> 16) & 0XFF);
42 | b[index++] = (byte) ((len >>> 8) & 0XFF);
43 | b[index++] = (byte) (len & 0XFF);
44 | b[index++] = (byte) this.annotation.length;
45 | for (ParameterAnnotation s : this.annotation)
46 | {
47 | int l = s.length();
48 | System.arraycopy(s.toByteArray(), 0, b, index, l);
49 | index+=l;
50 | }
51 | return b;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeRuntimeVisibleAnnotations.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.annotation.Annotation;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeRuntimeVisibleAnnotations extends Attribute
8 | {
9 | public Annotation[] annotation = new Annotation[0];
10 |
11 | public void annotation(Annotation annotation)
12 | {
13 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length + 1);
14 | this.annotation[this.annotation.length - 1] = annotation;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.RUNTIME_VISIBLE_ANNOTATIONS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 8;
27 | for (Annotation a : this.annotation) len += a.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | int index = 0;
37 | b[index++] = (byte) ((name >>> 8) & 0XFF);
38 | b[index++] = (byte) (name & 0XFF);
39 | len -= 6;
40 | b[index++] = (byte) ((len >>> 24) & 0XFF);
41 | b[index++] = (byte) ((len >>> 16) & 0XFF);
42 | b[index++] = (byte) ((len >>> 8) & 0XFF);
43 | b[index++] = (byte) (len & 0XFF);
44 | b[index++] = (byte) ((this.annotation.length >>> 8) & 0XFF);
45 | b[index++] = (byte) (this.annotation.length & 0XFF);
46 | for (Annotation s : this.annotation)
47 | {
48 | int l = s.length();
49 | System.arraycopy(s.toByteArray(), 0, b, index, l);
50 | index+=l;
51 | }
52 | return b;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeRuntimeVisibleParameterAnnotations.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.annotation.ParameterAnnotation;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeRuntimeVisibleParameterAnnotations extends Attribute
8 | {
9 | public ParameterAnnotation[] annotation = new ParameterAnnotation[0];
10 |
11 | public void annotation(ParameterAnnotation annotation)
12 | {
13 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length + 1);
14 | this.annotation[this.annotation.length - 1] = annotation;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 7;
27 | for (ParameterAnnotation s : this.annotation) len += s.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | int index = 0;
37 | b[index++] = (byte) ((name >>> 8) & 0XFF);
38 | b[index++] = (byte) (name & 0XFF);
39 | len -= 6;
40 | b[index++] = (byte) ((len >>> 24) & 0XFF);
41 | b[index++] = (byte) ((len >>> 16) & 0XFF);
42 | b[index++] = (byte) ((len >>> 8) & 0XFF);
43 | b[index++] = (byte) (len & 0XFF);
44 | b[index++] = (byte) annotation.length;
45 | for (ParameterAnnotation s : this.annotation)
46 | {
47 | int l = s.length();
48 | System.arraycopy(s.toByteArray(), 0, b, index, l);
49 | index+=l;
50 | }
51 | return b;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeRuntimeVisibleTypeAnnotations.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.annotation.TypeAnnotation;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeRuntimeVisibleTypeAnnotations extends Attribute
8 | {
9 | public TypeAnnotation[] annotation = new TypeAnnotation[0];
10 |
11 | public void annotation(TypeAnnotation annotation)
12 | {
13 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length + 1);
14 | this.annotation[this.annotation.length-1] = annotation;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.RUNTIME_VISIBLE_TYPE_ANNOTATIONS;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 8;
27 | for (TypeAnnotation s : this.annotation) len += s.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | int index = 0;
37 | b[index++] = (byte) ((name >>> 8) & 0XFF);
38 | b[index++] = (byte) (name & 0XFF);
39 | len -= 6;
40 | b[index++] = (byte) ((len >>> 24) & 0XFF);
41 | b[index++] = (byte) ((len >>> 16) & 0XFF);
42 | b[index++] = (byte) ((len >>> 8) & 0XFF);
43 | b[index++] = (byte) (len & 0XFF);
44 | b[index++] = (byte) ((this.annotation.length >>> 8) & 0XFF);
45 | b[index++] = (byte) (this.annotation.length & 0XFF);
46 | for (TypeAnnotation s : this.annotation)
47 | {
48 | int l = s.length();
49 | System.arraycopy(s.toByteArray(), 0, b, index, l);
50 | index+=l;
51 | }
52 | return b;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeSignature.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeSignature extends Attribute
4 | {
5 | public int signature;
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return AttributeType.SIGNATURE;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 8;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | byte[] b = new byte[len];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | b[index++] = (byte) ((this.signature >>> 8) & 0XFF);
33 | b[index] = (byte) (this.signature & 0XFF);
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeSourceDebugExtension.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeSourceDebugExtension extends Attribute
4 | {
5 | public byte[] extension = new byte[0];
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return null;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return this.extension.length + 6;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | byte[] b = new byte[len];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | System.arraycopy(this.extension, 0, b, index, this.extension.length);
33 | return b;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeSourceFile.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeSourceFile extends Attribute
4 | {
5 | public int source;
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return AttributeType.SOURCE_FILE;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 8;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | byte[] b = new byte[len];
24 | int index = 0;
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | b[index++] = (byte) ((this.source >>> 8) & 0XFF);
33 | b[index] = (byte) (this.source & 0XFF);
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeStackMapTable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | import org.mve.asm.file.attribute.stack.StackMapFrame;
4 |
5 | import java.util.Arrays;
6 |
7 | public class AttributeStackMapTable extends Attribute
8 | {
9 | public StackMapFrame[] frame = new StackMapFrame[0];
10 |
11 | public void frame(StackMapFrame frame)
12 | {
13 | this.frame = Arrays.copyOf(this.frame, this.frame.length+1);
14 | this.frame[this.frame.length-1] = frame;
15 | }
16 |
17 | @Override
18 | public AttributeType type()
19 | {
20 | return AttributeType.STACK_MAP_TABLE;
21 | }
22 |
23 | @Override
24 | public int length()
25 | {
26 | int len = 8;
27 | for (StackMapFrame frame : this.frame) len += frame.length();
28 | return len;
29 | }
30 |
31 | @Override
32 | public byte[] toByteArray()
33 | {
34 | int len = this.length();
35 | byte[] b = new byte[len];
36 | int index = 0;
37 | b[index++] = (byte) ((name >>> 8) & 0XFF);
38 | b[index++] = (byte) (name & 0XFF);
39 | len -= 6;
40 | b[index++] = (byte) ((len >>> 24) & 0XFF);
41 | b[index++] = (byte) ((len >>> 16) & 0XFF);
42 | b[index++] = (byte) ((len >>> 8) & 0XFF);
43 | b[index++] = (byte) (len & 0XFF);
44 | b[index++] = (byte) ((this.frame.length >>> 8) & 0XFF);
45 | b[index++] = (byte) (this.frame.length & 0XFF);
46 | for (StackMapFrame s : this.frame)
47 | {
48 | int l = s.length();
49 | System.arraycopy(s.toByteArray(), 0, b, index, l);
50 | index+=l;
51 | }
52 | return b;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeSynthetic.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeSynthetic extends Attribute
4 | {
5 | @Override
6 | public AttributeType type()
7 | {
8 | return AttributeType.SYNTHETIC;
9 | }
10 |
11 | @Override
12 | public int length()
13 | {
14 | return 6;
15 | }
16 |
17 | @Override
18 | public byte[] toByteArray()
19 | {
20 | int len = this.length();
21 | byte[] b = new byte[len];
22 | int index = 0;
23 | b[index++] = (byte) ((name >>> 8) & 0XFF);
24 | b[index++] = (byte) (name & 0XFF);
25 | len -= 6;
26 | b[index++] = (byte) ((len >>> 24) & 0XFF);
27 | b[index++] = (byte) ((len >>> 16) & 0XFF);
28 | b[index++] = (byte) ((len >>> 8) & 0XFF);
29 | b[index] = (byte) (len & 0XFF);
30 | return b;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/AttributeUnknown.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute;
2 |
3 | public class AttributeUnknown extends Attribute
4 | {
5 | public byte[] code = new byte[0];
6 |
7 | @Override
8 | public AttributeType type()
9 | {
10 | return AttributeType.UNKNOWN;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return this.code.length + 6;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | int len = this.length();
23 | int index = 0;
24 | byte[] b = new byte[len];
25 | b[index++] = (byte) ((name >>> 8) & 0XFF);
26 | b[index++] = (byte) (name & 0XFF);
27 | len -= 6;
28 | b[index++] = (byte) ((len >>> 24) & 0XFF);
29 | b[index++] = (byte) ((len >>> 16) & 0XFF);
30 | b[index++] = (byte) ((len >>> 8) & 0XFF);
31 | b[index++] = (byte) (len & 0XFF);
32 | System.arraycopy(this.code, 0, b, index, this.code.length);
33 | return b;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/ParameterAnnotation.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation;
2 |
3 | import java.util.Arrays;
4 |
5 | public class ParameterAnnotation
6 | {
7 | public Annotation[] annotation = new Annotation[0];
8 |
9 | public void annotation(Annotation annotation)
10 | {
11 | this.annotation = Arrays.copyOf(this.annotation, this.annotation.length + 1);
12 | this.annotation[this.annotation.length - 1] = annotation;
13 | }
14 |
15 | public int length()
16 | {
17 | int len = 2;
18 | for (Annotation s : this.annotation) len += s.length();
19 | return len;
20 | }
21 |
22 | public byte[] toByteArray()
23 | {
24 | int len = this.length();
25 | int index = 0;
26 | byte[] b = new byte[len];
27 | b[index++] = (byte) ((this.annotation.length >>> 8) & 0XFF);
28 | b[index++] = (byte) (this.annotation.length & 0XFF);
29 | for (Annotation s : this.annotation)
30 | {
31 | int l = s.length();
32 | System.arraycopy(s.toByteArray(), 0, b, index, l);
33 | index+=l;
34 | }
35 | return b;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationCatchValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationCatchValue extends TypeAnnotationValue
4 | {
5 | public int exception;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 2;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) ((this.exception >>> 8) & 0XFF), (byte) (this.exception & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationEmptyValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationEmptyValue extends TypeAnnotationValue
4 | {
5 | @Override
6 | public int length()
7 | {
8 | return 0;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[0];
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationFormalParameterValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationFormalParameterValue extends TypeAnnotationValue
4 | {
5 | public int parameter;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 1;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) this.parameter};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationLocalVariableValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.local.LocalVariableValue;
4 |
5 | import java.util.Arrays;
6 |
7 | public class TypeAnnotationLocalVariableValue extends TypeAnnotationValue
8 | {
9 | private LocalVariableValue[] value = new LocalVariableValue[0];
10 |
11 | public void local(LocalVariableValue value)
12 | {
13 | this.value = Arrays.copyOf(this.value, this.value.length + 1);
14 | this.value[this.value.length - 1] = value;
15 | }
16 |
17 | @Override
18 | public int length()
19 | {
20 | return 2 + (6 * this.value.length);
21 | }
22 |
23 | @Override
24 | public byte[] toByteArray()
25 | {
26 | int len = this.length();
27 | byte[] b = new byte[len];
28 | int index = 0;
29 | b[index++] = (byte) ((this.value.length >>> 8) & 0XFF);
30 | b[index++] = (byte) (this.value.length & 0XFF);
31 | for (LocalVariableValue s : this.value)
32 | {
33 | System.arraycopy(s.toByteArray(), 0, b, index, 6);
34 | index+=6;
35 | }
36 | return b;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationLocation.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.location.Location;
4 |
5 | import java.util.Arrays;
6 | import java.util.Objects;
7 |
8 | public class TypeAnnotationLocation
9 | {
10 | public Location[] location = new Location[0];
11 |
12 | public void location(Location location)
13 | {
14 | this.location = Arrays.copyOf(this.location, this.location.length+1);
15 | this.location[this.location.length-1] = Objects.requireNonNull(location);
16 | }
17 |
18 | public int length()
19 | {
20 | return 1 + (2 * this.location.length);
21 | }
22 |
23 | public byte[] toByteArray()
24 | {
25 | int len = this.length();
26 | byte[] b = new byte[len];
27 | b[0] = (byte) this.location.length;
28 | int index = 1;
29 | for (Location s : this.location)
30 | {
31 | System.arraycopy(s.toByteArray(), 0, b, index, 2);
32 | index+=2;
33 | }
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationOffsetValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationOffsetValue extends TypeAnnotationValue
4 | {
5 | public int offset;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 2;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) ((this.offset >>> 8) & 0XFF), (byte) (this.offset & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationPath.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | import org.mve.asm.file.attribute.annotation.type.location.Location;
4 |
5 | import java.util.Arrays;
6 | import java.util.Objects;
7 |
8 | public class TypeAnnotationPath
9 | {
10 | public Location[] path = new Location[0];
11 |
12 | public void path(Location path)
13 | {
14 | this.path = Arrays.copyOf(this.path, this.path.length+1);
15 | this.path[this.path.length-1] = Objects.requireNonNull(path);
16 | }
17 |
18 | public int length()
19 | {
20 | return 1 + (2 * this.path.length);
21 | }
22 |
23 | public byte[] toByteArray()
24 | {
25 | int len = this.length();
26 | byte[] b = new byte[len];
27 | b[0] = (byte) this.path.length;
28 | int index = 1;
29 | for (Location s : this.path)
30 | {
31 | System.arraycopy(s.toByteArray(), 0, b, index, 2);
32 | index+=2;
33 | }
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationSupertypeValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationSupertypeValue extends TypeAnnotationValue
4 | {
5 | public int supertype;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 2;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) ((this.supertype >>> 8) & 0XFF), (byte) (this.supertype & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationThrowsValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationThrowsValue extends TypeAnnotationValue
4 | {
5 | public int thrown;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 2;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) ((this.thrown >>> 8) & 0XFF), (byte) (this.thrown & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationTypeArgumentValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationTypeArgumentValue extends TypeAnnotationValue
4 | {
5 | public int offset;
6 | public int argument;
7 |
8 | @Override
9 | public int length()
10 | {
11 | return 3;
12 | }
13 |
14 | @Override
15 | public byte[] toByteArray()
16 | {
17 | return new byte[]{(byte) ((this.offset >>> 8) & 0XFF), (byte) (this.offset & 0XFF), (byte) this.argument};
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationTypeParameterBoundValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationTypeParameterBoundValue extends TypeAnnotationValue
4 | {
5 | public int parameter;
6 | public int bound;
7 |
8 | @Override
9 | public int length()
10 | {
11 | return 2;
12 | }
13 |
14 | @Override
15 | public byte[] toByteArray()
16 | {
17 | return new byte[]{(byte) this.parameter, (byte) this.bound};
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationTypeParameterValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public class TypeAnnotationTypeParameterValue extends TypeAnnotationValue
4 | {
5 | public int parameter;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 1;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) this.parameter};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/TypeAnnotationValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type;
2 |
3 | public abstract class TypeAnnotationValue
4 | {
5 | public int type;
6 |
7 | public int type()
8 | {
9 | return type;
10 | }
11 |
12 | public abstract int length();
13 |
14 | public abstract byte[] toByteArray();
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/local/LocalVariableValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type.local;
2 |
3 | public class LocalVariableValue
4 | {
5 | public int start;
6 | public int length;
7 | public int slot;
8 |
9 | public byte[] toByteArray()
10 | {
11 | return new byte[]
12 | {
13 | (byte) ((this.start >>> 8) & 0XFF),
14 | (byte) (this.start & 0XFF),
15 | (byte) ((this.length >>> 8) & 0XFF),
16 | (byte) (this.length & 0XFF),
17 | (byte) ((this.slot >>> 8) & 0XFF),
18 | (byte) (this.slot & 0XFF)
19 | };
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/annotation/type/location/Location.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.annotation.type.location;
2 |
3 | public class Location
4 | {
5 | public int kind;
6 | public int argument;
7 |
8 | public Location(int kind, int argument)
9 | {
10 | this.kind = kind;
11 | this.argument = argument;
12 | }
13 |
14 | public Location()
15 | {
16 | }
17 |
18 | public byte[] toByteArray()
19 | {
20 | return new byte[]{(byte) kind, (byte) argument};
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/bootstrap/BootstrapMethod.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.bootstrap;
2 |
3 | import java.util.Arrays;
4 |
5 | public class BootstrapMethod
6 | {
7 | public int reference;
8 | public int[] argument = new int[0];
9 |
10 | public void argument(int cp)
11 | {
12 | this.argument = Arrays.copyOf(this.argument, this.argument.length + 1);
13 | this.argument[this.argument.length-1] = cp;
14 | }
15 |
16 | public int length()
17 | {
18 | return 4 + (2 * this.argument.length);
19 | }
20 |
21 | public byte[] toByteArray()
22 | {
23 | byte[] b = new byte[this.length()];
24 | int index = 0;
25 | b[index++] = (byte) ((this.reference >>> 8) & 0XFF);
26 | b[index++] = (byte) (this.reference & 0XFF);
27 | b[index++] = (byte) ((this.argument.length >>> 8) & 0XFF);
28 | b[index++] = (byte) (this.argument.length & 0XFF);
29 | for (int s : this.argument)
30 | {
31 | b[index++] = (byte) ((s >>> 8) & 0XFF);
32 | b[index++] = (byte) (s & 0XFF);
33 | }
34 | return b;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/code/exception/Exception.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.code.exception;
2 |
3 | public class Exception
4 | {
5 | public int start;
6 | public int end;
7 | public int caught;
8 | public int type;
9 |
10 | public byte[] toByteArray()
11 | {
12 | byte[] b = new byte[8];
13 | b[0] = (byte) ((this.start >>> 8) & 0XFF);
14 | b[1] = (byte) (this.start & 0XFF);
15 | b[2] = (byte) ((this.end >>> 8) & 0XFF);
16 | b[3] = (byte) (this.end & 0XFF);
17 | b[4] = (byte) ((this.caught >>> 8) & 0XFF);
18 | b[5] = (byte) (this.caught & 0XFF);
19 | b[6] = (byte) ((this.type >>> 8) & 0XFF);
20 | b[7] = (byte) (this.type & 0XFF);
21 | return b;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementAnnotationValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | import org.mve.asm.file.attribute.annotation.Annotation;
4 |
5 | public class ElementAnnotationValue extends ElementValue
6 | {
7 | public Annotation annotation;
8 |
9 | @Override
10 | public int length()
11 | {
12 | return 1 + this.annotation.length();
13 | }
14 |
15 | @Override
16 | public byte[] toByteArray()
17 | {
18 | int len = this.length();
19 | byte[] b = new byte[len];
20 | b[0] = (byte) type;
21 | System.arraycopy(this.annotation.toByteArray(), 0, b, 1, len-1);
22 | return b;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementArrayValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | import java.util.Arrays;
4 |
5 | public class ElementArrayValue extends ElementValue
6 | {
7 | public ElementValue[] value = new ElementValue[0];
8 |
9 | public void value(ElementValue value)
10 | {
11 | this.value = Arrays.copyOf(this.value, this.value.length + 1);
12 | this.value[this.value.length - 1] = value;
13 | }
14 |
15 | @Override
16 | public int length()
17 | {
18 | int len = 3;
19 | for (ElementValue e : this.value) len += e.length();
20 | return len;
21 | }
22 |
23 | @Override
24 | public byte[] toByteArray()
25 | {
26 | int len = this.length();
27 | int index = 0;
28 | byte[] b = new byte[len];
29 | b[index++] = (byte) type;
30 | b[index++] = (byte) ((this.value.length >>> 8) & 0XFF);
31 | b[index++] = (byte) (this.value.length & 0XFF);
32 | for (ElementValue value : this.value)
33 | {
34 | int l = value.length();
35 | System.arraycopy(value.toByteArray(), 0, b, index, l);
36 | index+=l;
37 | }
38 | return b;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementClassValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | public class ElementClassValue extends ElementValue
4 | {
5 | public int clazz;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 3;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) type, (byte) ((this.clazz >>> 8) & 0XFF), (byte) (this.clazz & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementConstantValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | public class ElementConstantValue extends ElementValue
4 | {
5 | public int value;
6 |
7 | @Override
8 | public int length()
9 | {
10 | return 3;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{(byte) type, (byte) ((this.value >>> 8) & 0XFF), (byte) (this.value & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementEnumValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | public class ElementEnumValue extends ElementValue
4 | {
5 | public int name;
6 | public int value;
7 |
8 | @Override
9 | public int length()
10 | {
11 | return 5;
12 | }
13 |
14 | @Override
15 | public byte[] toByteArray()
16 | {
17 | return new byte[]
18 | {
19 | (byte) type,
20 | (byte) ((this.name >>> 8) & 0XFF),
21 | (byte) (this.name & 0XFF),
22 | (byte) ((this.value >>> 8) & 0XFF),
23 | (byte) (this.value & 0XFF)
24 | };
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementNameAndValue.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | public class ElementNameAndValue
4 | {
5 | public int name;
6 | public ElementValue value;
7 |
8 | public int length()
9 | {
10 | return 2 + this.value.length();
11 | }
12 |
13 | public byte[] toByteArray()
14 | {
15 | int len = this.length();
16 | byte[] b = new byte[len];
17 | b[0] = (byte) ((this.name >>> 8) & 0XFF);
18 | b[1] = (byte) (this.name & 0XFF);
19 | System.arraycopy(this.value.toByteArray(), 0, b, 2, len-2);
20 | return b;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/element/ElementValueType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.element;
2 |
3 | public class ElementValueType
4 | {
5 | public static final int
6 | BYTE ='B',
7 | SHORT ='S',
8 | INT ='I',
9 | BOOLEAN ='Z',
10 | CHAR ='C',
11 | FLOAT ='F',
12 | DOUBLE ='D',
13 | LONG ='J',
14 | STRING ='s',
15 | ENUM ='e',
16 | CLASS ='c',
17 | ANNOTATION ='@',
18 | ARRAY ='[';
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/inner/InnerClass.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.inner;
2 |
3 | public class InnerClass
4 | {
5 | public int inner;
6 | public int outer;
7 | public int name;
8 | public int access;
9 |
10 | public byte[] toByteArray()
11 | {
12 | byte[] b = new byte[8];
13 | b[0] = (byte) ((this.inner >>> 8) & 0XFF);
14 | b[1] = (byte) (this.inner & 0XFF);
15 | b[2] = (byte) ((this.outer >>> 8) & 0XFF);
16 | b[3] = (byte) (this.outer & 0XFF);
17 | b[4] = (byte) ((this.name >>> 8) & 0XFF);
18 | b[5] = (byte) (this.name & 0XFF);
19 | b[6] = (byte) ((this.access >>> 8) & 0XFF);
20 | b[7] = (byte) (this.access & 0XFF);
21 | return b;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/line/LineNumber.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.line;
2 |
3 | public class LineNumber
4 | {
5 | public int start;
6 | public int line;
7 |
8 | public byte[] toByteArray()
9 | {
10 | byte[] b = new byte[4];
11 | b[0] = (byte) ((this.start >>> 8) & 0XFF);
12 | b[1] = (byte) (this.start & 0XFF);
13 | b[2] = (byte) ((this.line >>> 8) & 0XFF);
14 | b[3] = (byte) (this.line & 0XFF);
15 | return b;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/local/LocalVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.local;
2 |
3 | public class LocalVariable
4 | {
5 | public int start;
6 | public int length;
7 | public int name;
8 | public int type;
9 | public int slot;
10 |
11 | public byte[] toByteArray()
12 | {
13 | byte[] b = new byte[10];
14 | b[0] = (byte) ((this.start >>> 8) & 0XFF);
15 | b[1] = (byte) (this.start & 0XFF);
16 | b[2] = (byte) ((this.length >>> 8) & 0XFF);
17 | b[3] = (byte) (this.length & 0XFF);
18 | b[4] = (byte) ((this.name >>> 8) & 0XFF);
19 | b[5] = (byte) (this.name & 0XFF);
20 | b[6] = (byte) ((this.type >>> 8) & 0XFF);
21 | b[7] = (byte) (this.type & 0XFF);
22 | b[8] = (byte) ((this.slot >>> 8) & 0XFF);
23 | b[9] = (byte) (this.slot & 0XFF);
24 | return b;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/local/LocalVariableType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.local;
2 |
3 | public class LocalVariableType
4 | {
5 | public int start;
6 | public int length;
7 | public int name;
8 | public int type;
9 | public int slot;
10 |
11 | public byte[] toByteArray()
12 | {
13 | byte[] b = new byte[10];
14 | b[0] = (byte) ((this.start >>> 8) & 0XFF);
15 | b[1] = (byte) (this.start & 0XFF);
16 | b[2] = (byte) ((this.length >>> 8) & 0XFF);
17 | b[3] = (byte) (this.length & 0XFF);
18 | b[4] = (byte) ((this.name >>> 8) & 0XFF);
19 | b[5] = (byte) (this.name & 0XFF);
20 | b[6] = (byte) ((this.type >>> 8) & 0XFF);
21 | b[7] = (byte) (this.type & 0XFF);
22 | b[8] = (byte) ((this.slot >>> 8) & 0XFF);
23 | b[9] = (byte) (this.slot & 0XFF);
24 | return b;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/method/Argument.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.method;
2 |
3 | public class Argument
4 | {
5 | public int name;
6 | public int access;
7 |
8 | public byte[] toByteArray()
9 | {
10 | byte[] b = new byte[4];
11 | b[0] = (byte) ((this.name >>> 8) & 0XFF);
12 | b[1] = (byte) (this.name & 0XFF);
13 | b[2] = (byte) ((this.access >>> 8) & 0XFF);
14 | b[3] = (byte) (this.access & 0XFF);
15 | return b;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/module/ModuleExport.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.module;
2 |
3 | import java.util.Arrays;
4 |
5 | public class ModuleExport
6 | {
7 | public int export;
8 | public int flag;
9 | public int[] to = new int[0];
10 |
11 | public void to(int cp)
12 | {
13 | this.to = Arrays.copyOf(this.to, this.to.length+1);
14 | this.to[this.to.length-1] = cp;
15 | }
16 |
17 | public int length()
18 | {
19 | return 6 + (2 * this.to.length);
20 | }
21 |
22 | public byte[] toByteArray()
23 | {
24 | int len = this.length();
25 | byte[] b = new byte[len];
26 | b[0] = (byte) ((this.export >>> 8) & 0XFF);
27 | b[1] = (byte) (this.export & 0XFF);
28 | b[2] = (byte) ((this.flag >>> 8) & 0XFF);
29 | b[3] = (byte) (this.flag & 0XFF);
30 | b[4] = (byte) ((this.to.length >>> 8) & 0XFF);
31 | b[5] = (byte) (this.to.length & 0XFF);
32 | int index = 6;
33 | for (int s : this.to)
34 | {
35 | b[index++] = (byte) ((s >>> 8) & 0XFF);
36 | b[index++] = (byte) (s & 0XFF);
37 | }
38 | return b;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/module/ModuleOpen.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.module;
2 |
3 | import java.util.Arrays;
4 |
5 | public class ModuleOpen
6 | {
7 | public int open;
8 | public int flag;
9 | public int[] to = new int[0];
10 |
11 | public void to(int cp)
12 | {
13 | this.to = Arrays.copyOf(this.to, this.to.length+1);
14 | this.to[this.to.length-1] = cp;
15 | }
16 |
17 | public int length()
18 | {
19 | return 6 + (2 * this.to.length);
20 | }
21 |
22 | public byte[] toByteArray()
23 | {
24 | int len = this.length();
25 | int index = 0;
26 | byte[] b = new byte[len];
27 | b[index++] = (byte) ((this.open >>> 8) & 0XFF);
28 | b[index++] = (byte) (this.open & 0XFF);
29 | b[index++] = (byte) ((this.flag >>> 8) & 0XFF);
30 | b[index++] = (byte) (this.flag & 0XFF);
31 | b[index++] = (byte) ((this.to.length >>> 8) & 0XFF);
32 | b[index++] = (byte) (this.to.length & 0XFF);
33 | for (int s : this.to)
34 | {
35 | b[index++] = (byte) ((s >>> 8) & 0XFF);
36 | b[index++] = (byte) (s & 0XFF);
37 | }
38 | return b;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/module/ModuleProvide.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.module;
2 |
3 | import java.util.Arrays;
4 |
5 | public class ModuleProvide
6 | {
7 | public int provide;
8 | public int[] whit = new int[0];
9 |
10 | public void with(int cp)
11 | {
12 | this.whit = Arrays.copyOf(this.whit, this.whit.length+1);
13 | this.whit[this.whit.length-1] = cp;
14 | }
15 |
16 | public int length()
17 | {
18 | return 4 + (2 * this.whit.length);
19 | }
20 |
21 | public byte[] toByteArray()
22 | {
23 | int len = this.length();
24 | int index = 0;
25 | byte[] b = new byte[len];
26 | b[index++] = (byte) ((this.provide >>> 8) & 0XFF);
27 | b[index++] = (byte) (this.provide & 0XFF);
28 | b[index++] = (byte) ((this.whit.length >>> 8) & 0XFF);
29 | b[index++] = (byte) (this.whit.length & 0XFF);
30 | for (int s : this.whit)
31 | {
32 | b[index++] = (byte) ((s >>> 8) & 0XFF);
33 | b[index++] = (byte) (s & 0XFF);
34 | }
35 | return b;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/module/ModuleRequire.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.module;
2 |
3 | public class ModuleRequire
4 | {
5 | public int require;
6 | public int flag;
7 | public int version;
8 |
9 | public byte[] toByteArray()
10 | {
11 | byte[] b = new byte[6];
12 | b[0] = (byte) ((this.require >>> 8) & 0XFF);
13 | b[1] = (byte) (this.require & 0XFF);
14 | b[2] = (byte) ((this.flag >>> 8) & 0XFF);
15 | b[3] = (byte) (this.flag & 0XFF);
16 | b[4] = (byte) ((this.version >>> 8) & 0XFF);
17 | b[5] = (byte) (this.version & 0XFF);
18 | return b;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapAppendFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | import org.mve.asm.file.attribute.stack.verification.Verification;
4 |
5 | public class StackMapAppendFrame extends StackMapFrame
6 | {
7 | public int offset;
8 | /**
9 | * verification.length = frame_type - 251
10 | */
11 | public Verification[] verification;
12 |
13 | @Override
14 | public StackMapFrameType type()
15 | {
16 | return StackMapFrameType.STACK_MAP_APPEND_FRAME;
17 | }
18 |
19 | @Override
20 | public int length()
21 | {
22 | int len = 3;
23 | for (Verification verification : verification) len += verification.type().length();
24 | return len;
25 | }
26 |
27 | @Override
28 | public byte[] toByteArray()
29 | {
30 | int len = this.length();
31 | byte[] b = new byte[len];
32 | int index = 0;
33 | b[index++] = (byte) this.type;
34 | b[index++] = (byte) ((this.offset >>> 8) & 0XFF);
35 | b[index++] = (byte) (this.offset & 0XFF);
36 | for (Verification v : this.verification)
37 | {
38 | int l = v.type().length();
39 | System.arraycopy(v.toByteArray(), 0, b, index, l);
40 | index+=l;
41 | }
42 | return b;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapChopFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | public class StackMapChopFrame extends StackMapFrame
4 | {
5 | public int offset;
6 |
7 | @Override
8 | public StackMapFrameType type()
9 | {
10 | return StackMapFrameType.STACK_MAP_CHOP_FRAME;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 3;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | return new byte[]{(byte) this.type, (byte) ((this.offset >>> 8) & 0XFF), (byte) (this.offset & 0XFF)};
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapFrameType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | public enum StackMapFrameType
4 | {
5 | STACK_MAP_SAME_FRAME((byte)0, (byte)63),
6 | STACK_MAP_SAME_LOCALS_1_ITEM_FRAME((byte)64, (byte)127),
7 | STACK_MAP_SAME_LOCALS_1_ITEM_FRAME_EXTENDED((byte)247),
8 | STACK_MAP_CHOP_FRAME((byte)248, (byte)250),
9 | STACK_MAP_SAME_FRAME_EXTENDED((byte)251),
10 | STACK_MAP_APPEND_FRAME((byte)252, (byte)254),
11 | STACK_MAP_FULL_FRAME((byte)255);
12 |
13 | private final byte low;
14 | private final byte high;
15 |
16 | private StackMapFrameType(byte low, byte high)
17 | {
18 | this.low = low;
19 | this.high = high;
20 | }
21 |
22 | private StackMapFrameType(byte type)
23 | {
24 | this(type, type);
25 | }
26 |
27 | public byte low()
28 | {
29 | return low;
30 | }
31 |
32 | public byte high()
33 | {
34 | return high;
35 | }
36 |
37 | public static StackMapFrameType getType(int type)
38 | {
39 | if (type >=0 && type <= 63) return STACK_MAP_SAME_FRAME;
40 | else if (type >= 64 && type <= 127) return STACK_MAP_SAME_LOCALS_1_ITEM_FRAME;
41 | else if (type == 247) return STACK_MAP_SAME_LOCALS_1_ITEM_FRAME_EXTENDED;
42 | else if (type >= 248 && type <= 250) return STACK_MAP_CHOP_FRAME;
43 | else if (type == 251) return STACK_MAP_SAME_FRAME_EXTENDED;
44 | else if (type >= 252 && type <= 254) return STACK_MAP_APPEND_FRAME;
45 | else if (type == 255) return STACK_MAP_FULL_FRAME;
46 | else return null;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapSameFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | public class StackMapSameFrame extends StackMapFrame
4 | {
5 | @Override
6 | public StackMapFrameType type()
7 | {
8 | return StackMapFrameType.STACK_MAP_SAME_FRAME;
9 | }
10 |
11 | @Override
12 | public int length()
13 | {
14 | return 1;
15 | }
16 |
17 | @Override
18 | public byte[] toByteArray()
19 | {
20 | return new byte[]{(byte) this.type};
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapSameFrameExtended.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | public class StackMapSameFrameExtended extends StackMapFrame
4 | {
5 | public int offset;
6 |
7 | @Override
8 | public StackMapFrameType type()
9 | {
10 | return StackMapFrameType.STACK_MAP_SAME_FRAME_EXTENDED;
11 | }
12 |
13 | @Override
14 | public int length()
15 | {
16 | return 3;
17 | }
18 |
19 | @Override
20 | public byte[] toByteArray()
21 | {
22 | return new byte[]{(byte) this.type, (byte) ((this.offset >>> 8) & 0XFF), (byte) (this.offset & 0XFF)};
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapSameLocals1StackItemFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | import org.mve.asm.file.attribute.stack.verification.Verification;
4 |
5 | public class StackMapSameLocals1StackItemFrame extends StackMapFrame
6 | {
7 | public Verification verification;
8 |
9 | @Override
10 | public StackMapFrameType type()
11 | {
12 | return StackMapFrameType.STACK_MAP_SAME_LOCALS_1_ITEM_FRAME;
13 | }
14 |
15 | @Override
16 | public int length()
17 | {
18 | return 1 + verification.type().length();
19 | }
20 |
21 | @Override
22 | public byte[] toByteArray()
23 | {
24 | byte[] b = new byte[this.length()];
25 | b[0] = (byte) this.type;
26 | System.arraycopy(this.verification.toByteArray(), 0, b, 1, this.verification.type().length());
27 | return b;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/StackMapSameLocals1StackItemFrameExtended.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack;
2 |
3 | import org.mve.asm.file.attribute.stack.verification.Verification;
4 |
5 | public class StackMapSameLocals1StackItemFrameExtended extends StackMapFrame
6 | {
7 | public int offset;
8 | public Verification verification;
9 |
10 | @Override
11 | public StackMapFrameType type()
12 | {
13 | return StackMapFrameType.STACK_MAP_SAME_LOCALS_1_ITEM_FRAME_EXTENDED;
14 | }
15 |
16 | @Override
17 | public int length()
18 | {
19 | return 3 + this.verification.type().length();
20 | }
21 |
22 | @Override
23 | public byte[] toByteArray()
24 | {
25 | byte[] b = new byte[this.length()];
26 | b[0] = (byte) this.type;
27 | b[1] = (byte) ((this.offset >>> 8) & 0XFF);
28 | b[2] = (byte) (this.offset & 0XFF);
29 | System.arraycopy(this.verification.toByteArray(), 0, b, 3, this.verification.type().length());
30 | return b;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationDoubleVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationDoubleVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_DOUBLE;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{3};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationFloatVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationFloatVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_FLOAT;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{2};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationIntegerVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationIntegerVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_INTEGER;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{1};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationLongVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationLongVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_LONG;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{4};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationNullVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationNullVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_NULL;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{5};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationObjectVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationObjectVariable extends Verification
4 | {
5 | public int type;
6 |
7 | @Override
8 | public VerificationType type()
9 | {
10 | return VerificationType.ITEM_OBJECT;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{7, (byte) ((this.type >>> 8) & 0XFF), (byte) (this.type & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationTopVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationTopVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_TOP;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{0};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public enum VerificationType
4 | {
5 | ITEM_TOP((byte)0, 1),
6 | ITEM_INTEGER((byte)1, 1),
7 | ITEM_FLOAT((byte)2, 1),
8 | ITEM_DOUBLE((byte)3, 1),
9 | ITEM_LONG((byte)4, 1),
10 | ITEM_NULL((byte)5, 1),
11 | ITEM_UNINITIALIZED_THIS((byte)6, 1),
12 | ITEM_OBJECT((byte)7, 3),
13 | ITEM_UNINITIALIZED((byte)8, 3);
14 |
15 | private final byte type;
16 | private final int length;
17 |
18 | private VerificationType(byte type, int length)
19 | {
20 | this.type = type;
21 | this.length = length;
22 | }
23 |
24 | public byte type()
25 | {
26 | return type;
27 | }
28 |
29 | public int length()
30 | {
31 | return length;
32 | }
33 |
34 | public static VerificationType getType(int type)
35 | {
36 | switch (type)
37 | {
38 | case 0: return ITEM_TOP;
39 | case 1: return ITEM_INTEGER;
40 | case 2: return ITEM_FLOAT;
41 | case 3: return ITEM_DOUBLE;
42 | case 4: return ITEM_LONG;
43 | case 5: return ITEM_NULL;
44 | case 6: return ITEM_UNINITIALIZED_THIS;
45 | case 7: return ITEM_OBJECT;
46 | case 8: return ITEM_UNINITIALIZED;
47 | default: return null;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationUninitializedThisVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationUninitializedThisVariable extends Verification
4 | {
5 | @Override
6 | public VerificationType type()
7 | {
8 | return VerificationType.ITEM_UNINITIALIZED_THIS;
9 | }
10 |
11 | @Override
12 | public byte[] toByteArray()
13 | {
14 | return new byte[]{6};
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/attribute/stack/verification/VerificationUninitializedVariable.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.attribute.stack.verification;
2 |
3 | public class VerificationUninitializedVariable extends Verification
4 | {
5 | public int offset;
6 |
7 | @Override
8 | public VerificationType type()
9 | {
10 | return VerificationType.ITEM_UNINITIALIZED;
11 | }
12 |
13 | @Override
14 | public byte[] toByteArray()
15 | {
16 | return new byte[]{8, (byte) ((this.offset >>> 8) & 0XFF), (byte) (this.offset & 0XFF)};
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/Constant.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public abstract class Constant
4 | {
5 | public abstract ConstantType type();
6 |
7 | public abstract byte[] toByteArray();
8 |
9 | public abstract int length();
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantArray.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | import java.util.Arrays;
4 | import java.util.Objects;
5 |
6 | public class ConstantArray
7 | {
8 | public Constant[] element = new Constant[1];
9 |
10 | public ConstantArray()
11 | {
12 | element[0] = new ConstantNull();
13 | }
14 |
15 | public void add(Constant element)
16 | {
17 | this.element = Arrays.copyOf(this.element, this.element.length+1);
18 | this.element[this.element.length-1] = element;
19 | }
20 |
21 | public void remove(int i)
22 | {
23 | element[i] = null;
24 | this.element = Arrays.stream(this.element).filter(Objects::nonNull).toArray(Constant[]::new);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantClass.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantClass extends Constant
4 | {
5 | public int name;
6 |
7 | public ConstantClass(int name)
8 | {
9 | this.name = name;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_CLASS;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[3];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.name >>> 8) & 0XFF);
24 | b[2] = (byte) (this.name & 0XFF);
25 | return b;
26 | }
27 |
28 | @Override
29 | public int length()
30 | {
31 | return 3;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantDouble.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantDouble extends Constant
4 | {
5 | public double value;
6 |
7 | public ConstantDouble(double value)
8 | {
9 | this.value = value;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_DOUBLE;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[9];
22 | long l = Double.doubleToLongBits(this.value);
23 | b[0] = this.type().code();
24 | b[1] = (byte) ((l >>> 56) & 0XFF);
25 | b[2] = (byte) ((l >>> 48) & 0XFF);
26 | b[3] = (byte) ((l >>> 40) & 0XFF);
27 | b[4] = (byte) ((l >>> 32) & 0XFF);
28 | b[5] = (byte) ((l >>> 24) & 0XFF);
29 | b[6] = (byte) ((l >>> 16) & 0XFF);
30 | b[7] = (byte) ((l >>> 8) & 0XFF);
31 | b[8] = (byte) (l & 0XFF);
32 | return b;
33 | }
34 |
35 | @Override
36 | public int length()
37 | {
38 | return 9;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantDynamic.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantDynamic extends Constant
4 | {
5 | public int bootstrap;
6 | public int nameAndType;
7 |
8 | public ConstantDynamic(int bootstrap, int nameAndType)
9 | {
10 | this.bootstrap = bootstrap;
11 | this.nameAndType = nameAndType;
12 | }
13 |
14 | @Override
15 | public ConstantType type()
16 | {
17 | return ConstantType.CONSTANT_DYNAMIC;
18 | }
19 |
20 | @Override
21 | public byte[] toByteArray()
22 | {
23 | byte[] b = new byte[5];
24 | b[0] = this.type().code();
25 | b[1] = (byte) ((this.bootstrap >>> 8) & 0XFF);
26 | b[2] = (byte) (this.bootstrap & 0XFF);
27 | b[3] = (byte) ((this.nameAndType >>> 8) & 0XFF);
28 | b[4] = (byte) (this.nameAndType & 0XFF);
29 | return b;
30 | }
31 |
32 | @Override
33 | public int length()
34 | {
35 | return 5;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantFieldReference.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantFieldReference extends Constant
4 | {
5 | public int clazz;
6 | public int nameAndType;
7 |
8 | public ConstantFieldReference(int clazz, int nameAndType)
9 | {
10 | this.clazz = clazz;
11 | this.nameAndType = nameAndType;
12 | }
13 |
14 | @Override
15 | public ConstantType type()
16 | {
17 | return ConstantType.CONSTANT_FIELD_REFERENCE;
18 | }
19 |
20 | @Override
21 | public int length()
22 | {
23 | return 5;
24 | }
25 |
26 | @Override
27 | public byte[] toByteArray()
28 | {
29 | byte[] b = new byte[5];
30 | b[0] = this.type().code();
31 | b[1] = (byte) ((this.clazz >>> 8) & 0XFF);
32 | b[2] = (byte) (this.clazz & 0XFF);
33 | b[3] = (byte) ((this.nameAndType >>> 8) & 0XFF);
34 | b[4] = (byte) (this.nameAndType & 0XFF);
35 | return b;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantFloat.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantFloat extends Constant
4 | {
5 | public float value;
6 |
7 | public ConstantFloat(float value)
8 | {
9 | this.value = value;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_FLOAT;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[5];
22 | int i = Float.floatToIntBits(this.value);
23 | b[0] = this.type().code();
24 | b[1] = (byte) ((i >>> 24) & 0XFF);
25 | b[2] = (byte) ((i >>> 16) & 0XFF);
26 | b[3] = (byte) ((i >>> 8) & 0XFF);
27 | b[4] = (byte) (i & 0XFF);
28 | return b;
29 | }
30 |
31 | @Override
32 | public int length()
33 | {
34 | return 5;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantInteger.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantInteger extends Constant
4 | {
5 | public int value;
6 |
7 | public ConstantInteger(int value)
8 | {
9 | this.value = value;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_INTEGER;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[5];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.value >>> 24) & 0XFF);
24 | b[2] = (byte) ((this.value >>> 16) & 0XFF);
25 | b[3] = (byte) ((this.value >>> 8) & 0XFF);
26 | b[4] = (byte) (this.value & 0XFF);
27 | return b;
28 | }
29 |
30 | @Override
31 | public int length()
32 | {
33 | return 5;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantInterfaceMethodReference.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantInterfaceMethodReference extends ConstantMethodReference
4 | {
5 | public ConstantInterfaceMethodReference(int classIndex, int nameAndTypeIndex)
6 | {
7 | super(classIndex, nameAndTypeIndex);
8 | }
9 |
10 | @Override
11 | public ConstantType type()
12 | {
13 | return ConstantType.CONSTANT_INTERFACE_METHOD_REFERENCE;
14 | }
15 |
16 | @Override
17 | public byte[] toByteArray()
18 | {
19 | byte[] b = super.toByteArray();
20 | b[0] = this.type().code();
21 | return b;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantInvokeDynamic.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantInvokeDynamic extends ConstantDynamic
4 | {
5 | public ConstantInvokeDynamic(int bootstrap, int nameAndType)
6 | {
7 | super(bootstrap, nameAndType);
8 | }
9 |
10 | @Override
11 | public ConstantType type()
12 | {
13 | return ConstantType.CONSTANT_INVOKE_DYNAMIC;
14 | }
15 |
16 | @Override
17 | public byte[] toByteArray()
18 | {
19 | byte[] b = super.toByteArray();
20 | b[0] = this.type().code();
21 | return b;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantLong.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantLong extends Constant
4 | {
5 | public long value;
6 |
7 | public ConstantLong(long value)
8 | {
9 | this.value = value;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_LONG;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[9];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.value >>> 56) & 0XFF);
24 | b[2] = (byte) ((this.value >>> 48) & 0XFF);
25 | b[3] = (byte) ((this.value >>> 40) & 0XFF);
26 | b[4] = (byte) ((this.value >>> 32) & 0XFF);
27 | b[5] = (byte) ((this.value >>> 24) & 0XFF);
28 | b[6] = (byte) ((this.value >>> 16) & 0XFF);
29 | b[7] = (byte) ((this.value >>> 8) & 0XFF);
30 | b[8] = (byte) (this.value & 0XFF);
31 | return b;
32 | }
33 |
34 | @Override
35 | public int length()
36 | {
37 | return 9;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantMethodHandle.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantMethodHandle extends Constant
4 | {
5 | public int kind;
6 | public int reference;
7 |
8 | public ConstantMethodHandle(int kind, int reference)
9 | {
10 | this.kind = kind;
11 | this.reference = reference;
12 | }
13 |
14 | @Override
15 | public ConstantType type()
16 | {
17 | return ConstantType.CONSTANT_METHOD_HANDLE;
18 | }
19 |
20 | @Override
21 | public byte[] toByteArray()
22 | {
23 | byte[] b = new byte[4];
24 | b[0] = this.type().code();
25 | b[1] = (byte) this.kind;
26 | b[2] = (byte) ((this.reference >>> 8) & 0XFF);
27 | b[3] = (byte) (this.reference & 0XFF);
28 | return b;
29 | }
30 |
31 | @Override
32 | public int length()
33 | {
34 | return 4;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantMethodReference.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantMethodReference extends Constant
4 | {
5 | public int clazz;
6 | public int nameAndType;
7 |
8 | public ConstantMethodReference(int clazz, int nameAndType)
9 | {
10 | this.clazz = clazz;
11 | this.nameAndType = nameAndType;
12 | }
13 |
14 | @Override
15 | public ConstantType type()
16 | {
17 | return ConstantType.CONSTANT_METHOD_REFERENCE;
18 | }
19 |
20 | @Override
21 | public byte[] toByteArray()
22 | {
23 | byte[] b = new byte[5];
24 | b[0] = this.type().code();
25 | b[1] = (byte) ((this.clazz >>> 8) & 0XFF);
26 | b[2] = (byte) (this.clazz & 0XFF);
27 | b[3] = (byte) ((this.nameAndType >>> 8) & 0XFF);
28 | b[4] = (byte) (this.nameAndType & 0XFF);
29 | return b;
30 | }
31 |
32 | @Override
33 | public int length()
34 | {
35 | return 5;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantMethodType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantMethodType extends Constant
4 | {
5 | public int type;
6 |
7 | public ConstantMethodType(int type)
8 | {
9 | this.type = type;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_METHOD_TYPE;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[3];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.type >>> 8) & 0XFF);
24 | b[2] = (byte) (this.type & 0XFF);
25 | return b;
26 | }
27 |
28 | @Override
29 | public int length()
30 | {
31 | return 3;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantModule.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantModule extends Constant
4 | {
5 | public int name;
6 |
7 | public ConstantModule(int name)
8 | {
9 | this.name = name;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_MODULE;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[3];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.name >>> 8) & 0XFF);
24 | b[2] = (byte) (this.name & 0XFF);
25 | return b;
26 | }
27 |
28 | @Override
29 | public int length()
30 | {
31 | return 3;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantNameAndType.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantNameAndType extends Constant
4 | {
5 | public int name;
6 | public int type;
7 |
8 | public ConstantNameAndType(int name, int type)
9 | {
10 | this.name = name;
11 | this.type = type;
12 | }
13 |
14 | @Override
15 | public ConstantType type()
16 | {
17 | return ConstantType.CONSTANT_NAME_AND_TYPE;
18 | }
19 |
20 | @Override
21 | public byte[] toByteArray()
22 | {
23 | byte[] b = new byte[5];
24 | b[0] = this.type().code();
25 | b[1] = (byte) ((this.name >>> 8) & 0XFF);
26 | b[2] = (byte) (this.name & 0XFF);
27 | b[3] = (byte) ((this.type >>> 8) & 0XFF);
28 | b[4] = (byte) (this.type & 0XFF);
29 | return b;
30 | }
31 |
32 | @Override
33 | public int length()
34 | {
35 | return 5;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantNull.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantNull extends Constant
4 | {
5 | @Override
6 | public ConstantType type()
7 | {
8 | return ConstantType.CONSTANT_NULL;
9 | }
10 |
11 | @Override
12 | public int length()
13 | {
14 | return 0;
15 | }
16 |
17 | @Override
18 | public byte[] toByteArray()
19 | {
20 | return new byte[0];
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantPackage.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantPackage extends Constant
4 | {
5 | public int name;
6 |
7 | public ConstantPackage(int name)
8 | {
9 | this.name = name;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_PACKAGE;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[3];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.name >>> 8) & 0XFF);
24 | b[2] = (byte) (this.name & 0XFF);
25 | return b;
26 | }
27 |
28 | @Override
29 | public int length()
30 | {
31 | return 3;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantString.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantString extends Constant
4 | {
5 | public int value;
6 |
7 | public ConstantString(int value)
8 | {
9 | this.value = value;
10 | }
11 |
12 | @Override
13 | public ConstantType type()
14 | {
15 | return ConstantType.CONSTANT_STRING;
16 | }
17 |
18 | @Override
19 | public byte[] toByteArray()
20 | {
21 | byte[] b = new byte[3];
22 | b[0] = this.type().code();
23 | b[1] = (byte) ((this.value >>> 8) & 0XFF);
24 | b[2] = (byte) (this.value & 0XFF);
25 | return b;
26 | }
27 |
28 | @Override
29 | public int length()
30 | {
31 | return 3;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/asm/file/constant/ConstantUTF8.java:
--------------------------------------------------------------------------------
1 | package org.mve.asm.file.constant;
2 |
3 | public class ConstantUTF8 extends Constant
4 | {
5 | public byte[] value;
6 |
7 | public ConstantUTF8(byte[] value)
8 | {
9 | this.value = value;
10 | }
11 |
12 | @Override
13 | public int length()
14 | {
15 | return this.value.length + 3;
16 | }
17 |
18 | @Override
19 | public ConstantType type()
20 | {
21 | return ConstantType.CONSTANT_UTF8;
22 | }
23 |
24 | @Override
25 | public byte[] toByteArray()
26 | {
27 | int len = this.value.length + 3;
28 | byte[] b = new byte[len];
29 | b[0] = this.type().code();
30 | b[1] = (byte) ((this.value.length >>> 8) & 0XFF);
31 | b[2] = (byte) (this.value.length & 0XFF);
32 | System.arraycopy(this.value, 0, b, 3, this.value.length);
33 | return b;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/ConstructorAccessor.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import java.lang.reflect.Constructor;
4 |
5 | public interface ConstructorAccessor extends ReflectionAccessor
6 | {
7 | public static final String CONSTRUCTOR = "constructor";
8 |
9 | Constructor constructor();
10 |
11 | ConstructorAccessor with(Object... argument);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/EnumHelper.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | public interface EnumHelper
4 | {
5 | T construct(String name);
6 |
7 | T construct(String name, int ordinal);
8 |
9 | T[] values();
10 |
11 | void values(T[] values);
12 |
13 | void add(T value);
14 |
15 | void remove(int index);
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/FieldAccessor.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | public interface FieldAccessor extends ReflectionAccessor
6 | {
7 | public static final String FIELD = "field";
8 | public static final String GET = "get";
9 | public static final String SET = "set";
10 |
11 | Field field();
12 |
13 | T get();
14 |
15 | T get(Object o);
16 |
17 | void set(Object vo);
18 |
19 | void set(Object o, Object v);
20 |
21 | FieldAccessor with(Object... argument);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/MagicAccess.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.METHOD})
10 | public @interface MagicAccess
11 | {
12 | int METHOD = 0;
13 | int FIELD = 1;
14 | int CONSTRUCT = 2;
15 | int INSTANTIATE = 3;
16 |
17 | int access();
18 |
19 | Class> objective();
20 |
21 | String name() default "";
22 |
23 | Class>[] type() default {};
24 |
25 | Class> value() default void.class;
26 |
27 | int kind() default 0;
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/MethodAccessor.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | public interface MethodAccessor extends ReflectionAccessor
6 | {
7 | public static final String METHOD = "method";
8 |
9 | Method method();
10 |
11 | MethodAccessor with(Object... argument);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/MethodKind.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import org.mve.invoke.common.JavaVM;
4 |
5 | import java.lang.invoke.MethodType;
6 | import java.lang.reflect.Method;
7 |
8 | public class MethodKind
9 | {
10 | private final Class> clazz;
11 | private final String name;
12 | private final MethodType type;
13 |
14 | public MethodKind(String name, Class> returnType, Class>... params)
15 | {
16 | this(name, MethodType.methodType(returnType, params));
17 | }
18 |
19 | public MethodKind(String name, MethodType type)
20 | {
21 | this(null, name, type);
22 | }
23 |
24 | public MethodKind(Method method)
25 | {
26 | this(method.getDeclaringClass(), method.getName(), method.getReturnType(), method.getParameterTypes());
27 | }
28 |
29 | public MethodKind(Class> clazz, String name, Class> returnType, Class>... params)
30 | {
31 | this(clazz, name, MethodType.methodType(returnType, params));
32 | }
33 |
34 | public MethodKind(Class> clazz, String name, MethodType type)
35 | {
36 | this.clazz = clazz;
37 | this.name = name;
38 | this.type = type;
39 | }
40 |
41 | public Class> clazz() { return this.clazz; }
42 | public String name() { return this.name; }
43 | public MethodType type() { return this.type; }
44 |
45 | public static MethodKind getMethod(MethodKind[] pattern)
46 | {
47 | try
48 | {
49 | return new MethodKind(JavaVM.getMethod(pattern));
50 | }
51 | catch (Throwable ignored)
52 | {
53 | }
54 | return new MethodKind(null, void.class);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/ReflectionAccessor.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.lang.reflect.Field;
5 | import java.lang.reflect.Method;
6 |
7 | public interface ReflectionAccessor
8 | {
9 | public static final String INVOKE = "invoke";
10 | public static final String OBJECTIVE = "objective";
11 | public static final String ARGUMENT = "argument";
12 | public static final String WITH = "with";
13 |
14 | /**
15 | * Method name of regenerate accessoro with arguments
16 | *
17 | * @see org.mve.invoke.common.Generator#generate(Method, int, Object[])
18 | * @see org.mve.invoke.common.Generator#generate(Field, Object[])
19 | * @see org.mve.invoke.common.Generator#generate(Constructor, Object[])
20 | */
21 | public static final String METHOD_GENERATE = "generate";
22 |
23 | /**
24 | * offset of string in constant array
25 | *
26 | * @see org.mve.invoke.common.JavaVM#CONSTANT
27 | */
28 | public static final int FIELD_CLASS = 4;
29 | public static final int FIELD_OBJECTIVE = 5;
30 | public static final int FIELD_WITH = 6;
31 |
32 | T invoke(Object... args);
33 |
34 | T invoke();
35 |
36 | Class> objective();
37 |
38 | Object[] argument();
39 |
40 | ReflectionAccessor with(Object... argument);
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/StackFrame.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke;
2 |
3 | import java.lang.invoke.MethodType;
4 |
5 | public class StackFrame
6 | {
7 | public final Class> clazz;
8 | public final String name;
9 | public final MethodType type;
10 | public final int offset;
11 | public final int line;
12 | public final String file;
13 | public final boolean natives;
14 |
15 | public StackFrame(Class> clazz, String name, MethodType type, int offset, int line, String file, boolean natives)
16 | {
17 | this.clazz = clazz;
18 | this.name = name;
19 | this.type = type;
20 | this.offset = offset;
21 | this.line = line;
22 | this.file = file;
23 | this.natives = natives;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/MagicPolymorphismInstantiationGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.asm.AccessFlag;
4 | import org.mve.asm.ClassWriter;
5 | import org.mve.asm.MethodWriter;
6 | import org.mve.asm.Opcodes;
7 | import org.mve.asm.attribute.CodeWriter;
8 | import org.mve.invoke.MethodKind;
9 | import org.mve.invoke.common.Generator;
10 |
11 | public class MagicPolymorphismInstantiationGenerator extends PolymorphismInstantiationGenerator
12 | {
13 | public MagicPolymorphismInstantiationGenerator(Class> target, MethodKind implementation)
14 | {
15 | super(target, implementation);
16 | }
17 |
18 | @Override
19 | public void generate(ClassWriter bytecode)
20 | {
21 | MethodWriter mw = new MethodWriter()
22 | .set(AccessFlag.PUBLIC, implementation().name(), implementation().type().toMethodDescriptorString())
23 | .attribute(new CodeWriter()
24 | .type(Opcodes.NEW, Generator.type(getTarget()))
25 | .instruction(Opcodes.ARETURN)
26 | .max(1, 1 + Generator.parameterSize(implementation().type().parameterArray()))
27 | );
28 | bytecode.method(mw);
29 | Generator.inline(mw);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/NativePolymorphismFieldGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.asm.AccessFlag;
4 | import org.mve.asm.ClassWriter;
5 | import org.mve.asm.MethodWriter;
6 | import org.mve.invoke.MagicAccessor;
7 | import org.mve.invoke.MethodKind;
8 | import org.mve.invoke.ReflectionFactory;
9 | import org.mve.invoke.common.Generator;
10 | import org.mve.invoke.common.standard.UnsafeFieldGetterGenerator;
11 | import org.mve.invoke.common.standard.UnsafeFieldSetterGenerator;
12 |
13 | import java.lang.reflect.Field;
14 |
15 | public class NativePolymorphismFieldGenerator extends PolymorphismFieldGenerator
16 | {
17 | public NativePolymorphismFieldGenerator(Class> target, MethodKind implementation, String operation, int kind)
18 | {
19 | super(target, implementation, operation, kind);
20 | }
21 |
22 | @Override
23 | public void generate(ClassWriter bytecode)
24 | {
25 | Field field = MagicAccessor.accessor.getField(this.getTarget(), this.operation());
26 | MethodWriter mw = new MethodWriter().set(AccessFlag.PUBLIC, implementation().name(), implementation().type().toMethodDescriptorString());
27 | bytecode.method(mw);
28 | Generator.inline(mw);
29 | if (this.kind() == ReflectionFactory.KIND_PUT)
30 | {
31 | new UnsafeFieldSetterGenerator(field).generate(mw, bytecode);
32 | }
33 | else if (this.kind() == ReflectionFactory.KIND_GET)
34 | {
35 | new UnsafeFieldGetterGenerator(field).generate(mw, bytecode);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/NativePolymorphismInstantiationGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.asm.AccessFlag;
4 | import org.mve.asm.ClassWriter;
5 | import org.mve.asm.MethodWriter;
6 | import org.mve.asm.Opcodes;
7 | import org.mve.asm.attribute.CodeWriter;
8 | import org.mve.invoke.MethodKind;
9 | import org.mve.invoke.Unsafe;
10 | import org.mve.invoke.common.Generator;
11 |
12 | import java.lang.invoke.MethodType;
13 |
14 | public class NativePolymorphismInstantiationGenerator extends PolymorphismInstantiationGenerator
15 | {
16 | public NativePolymorphismInstantiationGenerator(Class> target, MethodKind implementation)
17 | {
18 | super(target, implementation);
19 | }
20 |
21 | @Override
22 | public void generate(ClassWriter bytecode)
23 | {
24 | MethodWriter mw = new MethodWriter()
25 | .set(AccessFlag.PUBLIC, implementation().name(), implementation().type().toMethodDescriptorString())
26 | .attribute(new CodeWriter()
27 | .field(Opcodes.GETSTATIC, Generator.type(Unsafe.class), "unsafe", Generator.signature(Unsafe.class))
28 | .field(Opcodes.GETSTATIC, bytecode.name, "0", Generator.signature(Class.class))
29 | .method(Opcodes.INVOKEVIRTUAL, Generator.type(Unsafe.class), "allocateInstance", MethodType.methodType(Object.class, Class.class).toMethodDescriptorString(), false)
30 | .instruction(Opcodes.ARETURN)
31 | .max(3, 1 + Generator.parameterSize(implementation().type().parameterArray()))
32 | );
33 | Generator.inline(mw);
34 | bytecode.method(mw);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/PolymorphismConstructGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.invoke.MethodKind;
4 |
5 | public abstract class PolymorphismConstructGenerator extends PolymorphismGenerator
6 | {
7 | private final MethodKind implementation;
8 | private final MethodKind invocation;
9 |
10 | public PolymorphismConstructGenerator(Class> target, MethodKind implementation, MethodKind invocation)
11 | {
12 | super(target);
13 | this.implementation = implementation;
14 | this.invocation = invocation;
15 | }
16 |
17 | public MethodKind implementation()
18 | {
19 | return implementation;
20 | }
21 |
22 | public MethodKind invocation()
23 | {
24 | return invocation;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/PolymorphismFieldGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.invoke.MethodKind;
4 |
5 | public abstract class PolymorphismFieldGenerator extends PolymorphismGenerator
6 | {
7 | private final MethodKind implementation;
8 | private final String operation;
9 | private final int kind;
10 |
11 | public PolymorphismFieldGenerator(Class> target, MethodKind implementation, String operation, int kind)
12 | {
13 | super(target);
14 | this.implementation = implementation;
15 | this.operation = operation;
16 | this.kind = kind;
17 | }
18 |
19 | public MethodKind implementation()
20 | {
21 | return implementation;
22 | }
23 |
24 | public String operation()
25 | {
26 | return operation;
27 | }
28 |
29 | public int kind()
30 | {
31 | return kind;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/PolymorphismGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.asm.ClassWriter;
4 | import org.mve.invoke.common.Generator;
5 |
6 | public abstract class PolymorphismGenerator extends Generator
7 | {
8 | private final Class> target;
9 |
10 | public PolymorphismGenerator(Class> target)
11 | {
12 | this.target = target;
13 | }
14 |
15 | public Class> getTarget()
16 | {
17 | return target;
18 | }
19 |
20 | public abstract void generate(ClassWriter bytecode);
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/PolymorphismInstantiationGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.invoke.MethodKind;
4 |
5 | public abstract class PolymorphismInstantiationGenerator extends PolymorphismGenerator
6 | {
7 | private final MethodKind implementation;
8 |
9 | public PolymorphismInstantiationGenerator(Class> target, MethodKind implementation)
10 | {
11 | super(target);
12 | this.implementation = implementation;
13 | }
14 |
15 | public MethodKind implementation()
16 | {
17 | return implementation;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/polymorphism/PolymorphismMethodGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.polymorphism;
2 |
3 | import org.mve.invoke.MethodKind;
4 |
5 | public abstract class PolymorphismMethodGenerator extends PolymorphismGenerator
6 | {
7 | private final MethodKind implementation;
8 | private final MethodKind invocation;
9 | private final int kind;
10 |
11 | public PolymorphismMethodGenerator(Class> target, MethodKind implementation, MethodKind invocation, int kind)
12 | {
13 | super(target);
14 | this.implementation = implementation;
15 | this.invocation = invocation;
16 | this.kind = kind;
17 | }
18 |
19 | public MethodKind implementation()
20 | {
21 | return implementation;
22 | }
23 |
24 | public MethodKind invocation()
25 | {
26 | return invocation;
27 | }
28 |
29 | public int kind()
30 | {
31 | return kind;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/AccessibleObjectAccessorGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import org.mve.asm.AccessFlag;
4 | import org.mve.asm.ClassWriter;
5 | import org.mve.asm.FieldWriter;
6 | import org.mve.invoke.MagicAccessor;
7 | import org.mve.invoke.ReflectionAccessor;
8 | import org.mve.invoke.Unsafe;
9 | import org.mve.invoke.common.Generator;
10 | import org.mve.invoke.common.JavaVM;
11 |
12 | import java.lang.reflect.AccessibleObject;
13 |
14 | public abstract class AccessibleObjectAccessorGenerator extends AccessorGenerator
15 | {
16 | private final AccessibleObject accessibleObject;
17 |
18 | public AccessibleObjectAccessorGenerator(AccessibleObject accessibleObject, Class> target, Object[] argument)
19 | {
20 | super(target, argument);
21 | this.accessibleObject = accessibleObject;
22 | }
23 |
24 | public void pregenerate(ClassWriter bytecode)
25 | {
26 | super.pregenerate(bytecode);
27 | bytecode.field(new FieldWriter()
28 | .set(AccessFlag.PUBLIC | AccessFlag.STATIC | AccessFlag.FINAL, JavaVM.CONSTANT[ReflectionAccessor.FIELD_OBJECTIVE], Generator.signature(AccessibleObject.class))
29 | );
30 | }
31 |
32 | public void postgenerate(Class> generated)
33 | {
34 | super.postgenerate(generated);
35 | Unsafe.unsafe.putObject(generated, Unsafe.unsafe.staticFieldOffset(MagicAccessor.accessor.getField(generated, JavaVM.CONSTANT[ReflectionAccessor.FIELD_OBJECTIVE])), this.accessibleObject);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/AllocatorGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import org.mve.asm.AccessFlag;
4 | import org.mve.asm.MethodWriter;
5 | import org.mve.asm.Opcodes;
6 | import org.mve.asm.attribute.CodeWriter;
7 | import org.mve.invoke.ReflectionAccessor;
8 | import org.mve.invoke.common.Generator;
9 |
10 | import java.lang.invoke.MethodType;
11 |
12 | public abstract class AllocatorGenerator extends AccessorGenerator
13 | {
14 | public AllocatorGenerator(Class> target, Object[] argument)
15 | {
16 | super(target, argument);
17 | this.bytecode().interfaces = new String[]{Generator.type(ReflectionAccessor.class)};
18 | }
19 |
20 | @Override
21 | public void generate()
22 | {
23 | this.bytecode().method(new MethodWriter()
24 | .set(AccessFlag.PUBLIC, ReflectionAccessor.WITH, MethodType.methodType(ReflectionAccessor.class, Object[].class).toMethodDescriptorString())
25 | .attribute(new CodeWriter()
26 | .instruction(Opcodes.ALOAD_0)
27 | .instruction(Opcodes.ARETURN)
28 | .max(1, 2)
29 | )
30 | );
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/FieldGetterGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | public abstract class FieldGetterGenerator extends FieldModifierGenerator
6 | {
7 | public FieldGetterGenerator(Field field)
8 | {
9 | super(field);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/FieldModifierGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import org.mve.asm.ClassWriter;
4 | import org.mve.asm.MethodWriter;
5 | import org.mve.invoke.common.Generator;
6 |
7 | import java.lang.reflect.Field;
8 |
9 | public abstract class FieldModifierGenerator extends Generator
10 | {
11 | private final Field field;
12 |
13 | public FieldModifierGenerator(Field field)
14 | {
15 | this.field = field;
16 | }
17 |
18 | public abstract void generate(MethodWriter method, ClassWriter classWriter);
19 |
20 | public Field getField()
21 | {
22 | return field;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/FieldSetterGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | public abstract class FieldSetterGenerator extends FieldModifierGenerator
6 | {
7 | public FieldSetterGenerator(Field field)
8 | {
9 | super(field);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/MagicAllocatorGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import org.mve.asm.AccessFlag;
4 | import org.mve.asm.ClassWriter;
5 | import org.mve.asm.MethodWriter;
6 | import org.mve.asm.Opcodes;
7 | import org.mve.asm.attribute.CodeWriter;
8 | import org.mve.invoke.ReflectionAccessor;
9 | import org.mve.invoke.common.Generator;
10 |
11 | import java.lang.invoke.MethodType;
12 |
13 | public class MagicAllocatorGenerator extends AllocatorGenerator
14 | {
15 | private final ClassWriter bytecode = this.bytecode();
16 | private final Class> target;
17 |
18 | public MagicAllocatorGenerator(Class> target, Object[] argument)
19 | {
20 | super(target, argument);
21 | this.target = target;
22 | }
23 |
24 | @Override
25 | public void generate()
26 | {
27 | super.generate();
28 | MethodWriter mw = new MethodWriter()
29 | .set(AccessFlag.PUBLIC, ReflectionAccessor.INVOKE, MethodType.methodType(Object.class, Object[].class).toMethodDescriptorString())
30 | .attribute(new CodeWriter()
31 | .type(Opcodes.NEW, Generator.type(this.target))
32 | .instruction(Opcodes.ARETURN)
33 | .max(1, 2)
34 | );
35 | Generator.inline(mw);
36 | this.bytecode.method(mw);
37 |
38 | mw = new MethodWriter()
39 | .set(AccessFlag.PUBLIC, ReflectionAccessor.INVOKE, MethodType.methodType(Object.class).toMethodDescriptorString())
40 | .attribute(new CodeWriter()
41 | .type(Opcodes.NEW, Generator.type(this.target))
42 | .instruction(Opcodes.ARETURN)
43 | .max(1, 1)
44 | );
45 | Generator.inline(mw);
46 | this.bytecode.method(mw);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/MagicFieldGetterGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import org.mve.asm.ClassWriter;
4 | import org.mve.asm.MethodWriter;
5 | import org.mve.asm.Opcodes;
6 | import org.mve.asm.attribute.CodeWriter;
7 | import org.mve.invoke.MagicAccessor;
8 | import org.mve.invoke.common.Generator;
9 |
10 | import java.lang.reflect.Field;
11 | import java.lang.reflect.Modifier;
12 |
13 | public class MagicFieldGetterGenerator extends FieldGetterGenerator
14 | {
15 | public MagicFieldGetterGenerator(Field field)
16 | {
17 | super(field);
18 | }
19 |
20 | @Override
21 | public void generate(MethodWriter method, ClassWriter classWriter)
22 | {
23 | Field field = this.getField();
24 | int modifiers = field.getModifiers();
25 | boolean statics = Modifier.isStatic(modifiers);
26 | CodeWriter code = new CodeWriter();
27 | method.attribute(code);
28 | if (statics)
29 | {
30 | code.field(Opcodes.GETSTATIC, Generator.type(field.getDeclaringClass()), MagicAccessor.accessor.getName(field), Generator.signature(field.getType()))
31 | .max(Generator.typeSize(field.getType()), 1);
32 | }
33 | else
34 | {
35 | code.instruction(Opcodes.ALOAD_1)
36 | .field(Opcodes.GETFIELD, Generator.type(field.getDeclaringClass()), MagicAccessor.accessor.getName(field), Generator.signature(field.getType()))
37 | .max(Generator.typeSize(field.getType()), 2);
38 | }
39 | Generator.returner(field.getType(), code);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/invoke/common/standard/UnsafeFieldGetterGenerator.java:
--------------------------------------------------------------------------------
1 | package org.mve.invoke.common.standard;
2 |
3 | import org.mve.asm.ClassWriter;
4 | import org.mve.asm.MethodWriter;
5 | import org.mve.asm.Opcodes;
6 | import org.mve.asm.attribute.CodeWriter;
7 | import org.mve.invoke.ReflectionAccessor;
8 | import org.mve.invoke.Unsafe;
9 | import org.mve.invoke.common.Generator;
10 | import org.mve.invoke.common.JavaVM;
11 |
12 | import java.lang.reflect.Field;
13 | import java.lang.reflect.Modifier;
14 |
15 | public class UnsafeFieldGetterGenerator extends FieldGetterGenerator
16 | {
17 | public UnsafeFieldGetterGenerator(Field field)
18 | {
19 | super(field);
20 | }
21 |
22 | @Override
23 | public void generate(MethodWriter method, ClassWriter classWriter)
24 | {
25 | Field field = this.getField();
26 | int modifiers = field.getModifiers();
27 | boolean statics = Modifier.isStatic(modifiers);
28 | long off = statics ? Unsafe.unsafe.staticFieldOffset(field) : Unsafe.unsafe.objectFieldOffset(field);
29 | CodeWriter code = new CodeWriter();
30 | method.attribute(code);
31 | code.field(Opcodes.GETSTATIC, Generator.type(Unsafe.class), "unsafe", Generator.signature(Unsafe.class));
32 | if (statics)
33 | {
34 | code.field(Opcodes.GETSTATIC, classWriter.name, JavaVM.CONSTANT[ReflectionAccessor.FIELD_CLASS], Generator.signature(Class.class));
35 | }
36 | else
37 | {
38 | code.instruction(Opcodes.ALOAD_1);
39 | }
40 | code.constant(off);
41 | Generator.unsafeget(field.getType(), code);
42 | Generator.returner(field.getType(), code);
43 | code.max(4, statics ? 1 : 2);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/mve/io/ByteArrayAccessor.java:
--------------------------------------------------------------------------------
1 | package org.mve.io;
2 |
3 | public interface ByteArrayAccessor
4 | {
5 | void seek(int n);
6 |
7 | int skip(int n);
8 |
9 | void write(int i);
10 |
11 | void write(byte[] b);
12 |
13 | void write(byte[] b, int off, int len);
14 |
15 | int read();
16 |
17 | int read(byte[] b);
18 |
19 | int read(byte[] b, int off, int len);
20 |
21 | void insert(int i);
22 |
23 | void insert(byte[] b);
24 |
25 | void insert(byte[] b, int off, int len);
26 |
27 | void insertByte(int b);
28 |
29 | void insertShort(int s);
30 |
31 | void insertInt(int i);
32 |
33 | void insertLong(long l);
34 |
35 | void insertFloat(float f);
36 |
37 | void insertDouble(double d);
38 |
39 | void insertBoolean(boolean b);
40 |
41 | void insertChar(char c);
42 |
43 | void insertUTF(String str);
44 |
45 | int delete();
46 |
47 | int delete(byte[] b);
48 |
49 | int delete(byte[] b, int off, int len);
50 |
51 | int available();
52 |
53 | int length();
54 |
55 | int position();
56 |
57 | byte[] toByteArray();
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/resources/module-info.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MeiVinEight/ReflectionFX/ca16f7a3841ec75d2ebd8a2db863efde1112ea0f/src/main/resources/module-info.class
--------------------------------------------------------------------------------
/src/test/java/org/mve/Main.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | import org.mve.invoke.MagicAccessor;
4 |
5 | public class Main
6 | {
7 | public static void main(String[] args) throws Throwable
8 | {
9 | // MagicAccessor accessor = MagicAccessor.accessor;
10 | // Unsafe unsafe = Unsafe.unsafe;
11 | // long method = unsafe.objectFieldOffset(accessor.getField(Method.class, "name"));
12 | // long field = unsafe.objectFieldOffset(accessor.getField(Field.class, "name"));
13 | // System.out.println(unsafe.getObject(Main.class.getMethod("main", String[].class), method));
14 | // System.out.println(unsafe.getObject(String.class.getDeclaredField("value"), field));
15 | System.out.println(MagicAccessor.accessor.getName(Main.class.getMethod("main", String[].class)));
16 | System.out.println(MagicAccessor.accessor.getName(String.class.getDeclaredField("value")));
17 | System.out.println(MagicAccessor.accessor.getPID());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/org/mve/Main1.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | import org.mve.invoke.MethodAccessor;
4 | import org.mve.invoke.ReflectionFactory;
5 |
6 | import java.lang.invoke.MethodType;
7 |
8 | public class Main1
9 | {
10 | public static void main(String[] args) throws Throwable
11 | {
12 | MethodAccessor invoke1 = ReflectionFactory.access(
13 | Test.class, "staticPrint",
14 | MethodType.methodType(void.class, String.class),
15 | ReflectionFactory.KIND_INVOKE_STATIC
16 | );
17 | invoke1.invoke("Text");
18 |
19 | MethodAccessor invoke2 = ReflectionFactory.access(
20 | Test.class, "print",
21 | MethodType.methodType(void.class, String.class),
22 | ReflectionFactory.KIND_INVOKE_VIRTUAL
23 | );
24 | invoke2.invoke(Test.INSTANCE, "Text");
25 |
26 | MethodAccessor invoke3 = ReflectionFactory.access(Test.class.getDeclaredMethod("staticPrint", String.class), ReflectionFactory.KIND_INVOKE_STATIC);
27 | invoke3.invoke("Text");
28 |
29 | MethodAccessor invoke4 = ReflectionFactory.access(Test.class.getDeclaredMethod("print", String.class), ReflectionFactory.KIND_INVOKE_VIRTUAL);
30 | invoke4.invoke(Test.INSTANCE, "Text");
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/java/org/mve/Main2.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | import org.mve.invoke.FieldAccessor;
4 | import org.mve.invoke.ReflectionFactory;
5 |
6 | public class Main2
7 | {
8 | public static void main(String[] args) throws Throwable
9 | {
10 | Test test = new Test();
11 |
12 | FieldAccessor accessor1 = ReflectionFactory.access(Test.class, "INSTANCE");
13 | accessor1.invoke(test);
14 | System.out.println(accessor1.invoke());
15 |
16 | FieldAccessor accessor2 = ReflectionFactory.access(Test.class, "staticPrefix");
17 | accessor2.invoke("Test");
18 | System.out.println(accessor2.invoke());
19 |
20 | FieldAccessor accessor3 = ReflectionFactory.access(Test.class.getDeclaredField("defaultPrefix"));
21 | accessor3.invoke(test, "TestDefaultPrefix");
22 | System.out.println(accessor3.invoke(test));
23 |
24 | FieldAccessor accessor4 = ReflectionFactory.access(Test.class.getDeclaredField("prefix"));
25 | accessor4.invoke(test, "TestPrefix");
26 | System.out.println(accessor4.invoke(test));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/org/mve/Main3.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | import org.mve.invoke.ReflectionAccessor;
4 | import org.mve.invoke.ReflectionFactory;
5 |
6 | public class Main3
7 | {
8 | public static void main(String[] args)
9 | {
10 | ReflectionAccessor accessor1 = ReflectionFactory.access(Test.class);
11 | System.out.println(accessor1.invoke());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/org/mve/Main4.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | import org.mve.invoke.ConstructorAccessor;
4 | import org.mve.invoke.ReflectionFactory;
5 |
6 | import java.lang.invoke.MethodType;
7 |
8 | public class Main4
9 | {
10 | public static void main(String[] args) throws Throwable
11 | {
12 | ConstructorAccessor accessor1 = ReflectionFactory.access(Test.class, MethodType.methodType(void.class));
13 | System.out.println(accessor1.invoke());
14 |
15 | ConstructorAccessor accessor2 = ReflectionFactory.access(Test.class, MethodType.methodType(void.class, String.class));
16 | System.out.println(accessor2.invoke("TestPrefix"));
17 |
18 | ConstructorAccessor accessor3 = ReflectionFactory.access(Test.class.getDeclaredConstructor(String.class));
19 | System.out.println(accessor3.invoke("TestPrefix"));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/java/org/mve/Main5.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | import org.mve.invoke.EnumHelper;
4 | import org.mve.invoke.ReflectionFactory;
5 |
6 | import java.util.Arrays;
7 |
8 | public class Main5
9 | {
10 | public static void main(String[] args)
11 | {
12 | EnumHelper helper = ReflectionFactory.enumHelper(Test.TestEnum.class);
13 | Test.TestEnum value = helper.construct("D", 3);
14 | System.out.println(Arrays.toString(helper.values()));
15 | helper.add(value);
16 | System.out.println(Arrays.toString(helper.values()));
17 | helper.remove(2);
18 | System.out.println(Arrays.toString(helper.values()));
19 | Test.TestEnum a = helper.values()[0];
20 | helper.values()[0] = null;
21 | System.out.println(Arrays.toString(Test.TestEnum.values()));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/java/org/mve/Test.java:
--------------------------------------------------------------------------------
1 | package org.mve;
2 |
3 | public class Test
4 | {
5 | public static final Test INSTANCE = new Test();
6 | private static String staticPrefix = "StaticPrefix";
7 | private final String defaultPrefix;
8 | private String prefix;
9 |
10 | public Test(String prefix)
11 | {
12 | this.defaultPrefix = "Default"+prefix;
13 | this.prefix = prefix;
14 | }
15 |
16 | public Test() { this("Prefix"); }
17 |
18 | private static void staticPrint(String text) { System.out.println(staticPrefix + " - " + text); }
19 |
20 | private void print(String text) { System.out.println(prefix + " - " + text); }
21 |
22 | public String getPrefix() { return this.prefix; }
23 |
24 | public String getDefaultPrefix() { return this.defaultPrefix; }
25 |
26 | public static String getStaticPrefix() { return staticPrefix; }
27 |
28 | public static enum TestEnum
29 | {
30 | A, B, C;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------