├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
└── java
└── me
└── coley
└── bmf
├── ClassNode.java
├── ClassReader.java
├── ClassWriter.java
├── FieldNode.java
├── JarReader.java
├── Main.java
├── MemberNode.java
├── MethodNode.java
├── attribute
├── Attribute.java
├── AttributeDeprecated.java
├── AttributeOwner.java
├── AttributeSignature.java
├── AttributeSynthetic.java
├── AttributeType.java
├── annotation
│ ├── Annotation.java
│ ├── AttributeAnnotationDefault.java
│ ├── AttributeAnnotations.java
│ ├── AttributeParameterAnnotations.java
│ ├── ParameterAnnotations.java
│ └── element
│ │ ├── ElementValue.java
│ │ ├── ElementValueAnnotationValue.java
│ │ ├── ElementValueArrayValue.java
│ │ ├── ElementValueClassInfoIndex.java
│ │ ├── ElementValueConstValueIndex.java
│ │ ├── ElementValueEnumConstValue.java
│ │ ├── ElementValuePair.java
│ │ └── ElementValueType.java
├── clazz
│ ├── AttributeBootstrapMethods.java
│ ├── AttributeEnclosingMethod.java
│ ├── AttributeInnerClasses.java
│ ├── AttributeSourceDebugExtension.java
│ ├── AttributeSourceFile.java
│ ├── BootstrapMethod.java
│ └── InnerClass.java
├── field
│ └── AttributeConstantValue.java
└── method
│ ├── AttributeCode.java
│ ├── AttributeExceptions.java
│ ├── AttributeLineNumberTable.java
│ ├── AttributeLocalVariableTable.java
│ ├── AttributeLocalVariableTypeTable.java
│ ├── AttributeStackMapTable.java
│ ├── LineNumberTable.java
│ ├── Local.java
│ ├── LocalVariableTable.java
│ ├── LocalVariableType.java
│ ├── MethodCode.java
│ └── MethodException.java
├── consts
├── AbstractMemberConstant.java
├── ConstClass.java
├── ConstDouble.java
├── ConstDynamic.java
├── ConstField.java
├── ConstFloat.java
├── ConstInt.java
├── ConstInterfaceMethod.java
├── ConstInvokeDynamic.java
├── ConstLong.java
├── ConstMethod.java
├── ConstMethodHandle.java
├── ConstMethodType.java
├── ConstModule.java
├── ConstNameType.java
├── ConstPackage.java
├── ConstString.java
├── ConstUTF8.java
├── Constant.java
├── ConstantType.java
└── mapping
│ ├── ConstMemberDesc.java
│ ├── ConstName.java
│ └── ConstSignature.java
├── exception
└── InvalidClassException.java
├── insn
├── AbstractClassPointer.java
├── AbstractFieldInstruction.java
├── AbstractJump.java
├── AbstractLDC.java
├── AbstractLOAD.java
├── AbstractMethodInstruction.java
├── AbstractRETURN.java
├── AbstractSTORE.java
├── InsnInstances.java
├── Instruction.java
├── OpType.java
├── SingleValueInstruction.java
└── impl
│ ├── AALOAD.java
│ ├── AASTORE.java
│ ├── ACONST_NULL.java
│ ├── ALOAD.java
│ ├── ANEWARRAY.java
│ ├── ARETURN.java
│ ├── ARRAYLENGTH.java
│ ├── ASTORE.java
│ ├── ATHROW.java
│ ├── BALOAD.java
│ ├── BASTORE.java
│ ├── BIPUSH.java
│ ├── BREAKPOINT.java
│ ├── CALOAD.java
│ ├── CASTORE.java
│ ├── CHECKCAST.java
│ ├── D2F.java
│ ├── D2I.java
│ ├── D2L.java
│ ├── DADD.java
│ ├── DALOAD.java
│ ├── DASTORE.java
│ ├── DCMPG.java
│ ├── DCMPL.java
│ ├── DCONST.java
│ ├── DDIV.java
│ ├── DLOAD.java
│ ├── DMUL.java
│ ├── DNEG.java
│ ├── DREM.java
│ ├── DRETURN.java
│ ├── DSTORE.java
│ ├── DSUB.java
│ ├── DUP.java
│ ├── DUP2.java
│ ├── DUP2_X1.java
│ ├── DUP2_X2.java
│ ├── DUP_X1.java
│ ├── DUP_X2.java
│ ├── F2D.java
│ ├── F2I.java
│ ├── F2L.java
│ ├── FADD.java
│ ├── FALOAD.java
│ ├── FASTORE.java
│ ├── FCMPG.java
│ ├── FCMPL.java
│ ├── FCONST.java
│ ├── FDIV.java
│ ├── FLOAD.java
│ ├── FMUL.java
│ ├── FNEG.java
│ ├── FREM.java
│ ├── FRETURN.java
│ ├── FSTORE.java
│ ├── FSUB.java
│ ├── GETFIELD.java
│ ├── GETSTATIC.java
│ ├── GOTO.java
│ ├── I2B.java
│ ├── I2C.java
│ ├── I2D.java
│ ├── I2F.java
│ ├── I2L.java
│ ├── I2S.java
│ ├── IADD.java
│ ├── IALOAD.java
│ ├── IAND.java
│ ├── IASTORE.java
│ ├── ICONST.java
│ ├── IDIV.java
│ ├── IFEQ.java
│ ├── IFGE.java
│ ├── IFGT.java
│ ├── IFLE.java
│ ├── IFLT.java
│ ├── IFNE.java
│ ├── IFNONNULL.java
│ ├── IFNULL.java
│ ├── IF_ACMPEQ.java
│ ├── IF_ACMPNE.java
│ ├── IF_ICMPEQ.java
│ ├── IF_ICMPGE.java
│ ├── IF_ICMPGT.java
│ ├── IF_ICMPLE.java
│ ├── IF_ICMPLT.java
│ ├── IF_ICMPNE.java
│ ├── IINC.java
│ ├── ILOAD.java
│ ├── IMPDEP1.java
│ ├── IMPDEP2.java
│ ├── IMUL.java
│ ├── INEG.java
│ ├── INSTANCEOF.java
│ ├── INVOKEDYNAMIC.java
│ ├── INVOKEINTERFACE.java
│ ├── INVOKESPECIAL.java
│ ├── INVOKESTATIC.java
│ ├── INVOKEVIRTUAL.java
│ ├── IOR.java
│ ├── IREM.java
│ ├── IRETURN.java
│ ├── ISHL.java
│ ├── ISHR.java
│ ├── ISTORE.java
│ ├── ISUB.java
│ ├── IUSHR.java
│ ├── IXOR.java
│ ├── L2D.java
│ ├── L2F.java
│ ├── L2I.java
│ ├── LADD.java
│ ├── LALOAD.java
│ ├── LAND.java
│ ├── LASTORE.java
│ ├── LCMP.java
│ ├── LCONST.java
│ ├── LDC.java
│ ├── LDC2_W.java
│ ├── LDC_W.java
│ ├── LDIV.java
│ ├── LLOAD.java
│ ├── LMUL.java
│ ├── LNEG.java
│ ├── LOOKUPSWITCH.java
│ ├── LOR.java
│ ├── LREM.java
│ ├── LRETURN.java
│ ├── LSHL.java
│ ├── LSHR.java
│ ├── LSTORE.java
│ ├── LSUB.java
│ ├── LUSHR.java
│ ├── LXOR.java
│ ├── MONITORENTER.java
│ ├── MONITOREXIT.java
│ ├── MULTIANEWARRAY.java
│ ├── NEW.java
│ ├── NEWARRAY.java
│ ├── NOP.java
│ ├── POP.java
│ ├── POP2.java
│ ├── PUTFIELD.java
│ ├── PUTSTATIC.java
│ ├── RETURN.java
│ ├── SALOAD.java
│ ├── SASTORE.java
│ ├── SIPUSH.java
│ ├── SWAP.java
│ ├── TABLESWITCH.java
│ └── WIDE.java
├── mapping
├── AbstractMapping.java
├── ClassMapping.java
├── InnerClassMapping.java
├── Mapping.java
├── MemberMapping.java
└── MethodMapping.java
├── signature
├── MethodSignature.java
├── SigArg.java
├── SigArgArray.java
├── SigArgClass.java
├── SigArgClassWithInner.java
├── SigArgGeneric.java
├── SigArgPrimitive.java
├── SigArgWild.java
├── Signature.java
├── TypeArgHelper.java
└── TypeSignature.java
├── type
├── ArrayType.java
├── ClassType.java
├── PrimitiveType.java
├── Sort.java
├── Type.java
└── descriptors
│ ├── MemberDescriptor.java
│ ├── MethodDescriptor.java
│ └── VariableDescriptor.java
└── util
├── Access.java
├── Box.java
├── ClassLoadStatus.java
├── ConstUtil.java
├── ImmutableBox.java
├── IndexableDataStream.java
├── JavaNameSorter.java
├── Measurable.java
├── MeasurableUtils.java
├── StreamUtil.java
└── io
├── JarUtil.java
└── NameFilter.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata/**
2 | .recommenders/**
3 | .settings/**
4 | bin/**
5 | temp/**
6 | target/**
7 |
8 | .classpath
9 | .project
10 |
11 | # IntelliJ IDEA Project stuff
12 | .idea/
13 | out/
14 | *.iws
15 | *.iml
16 |
17 | src/test
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Matthew Coley, Matthew Dupraz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bytecode Modification Framework
2 |
3 | BMF is an alternative JVM bytecode modification framework that *(if desired)* will hide nothing about the class structure behind abstraction *(But in the future abstraction will certainly be an option)*.
4 |
5 | ### Notable Features
6 |
7 | * Simplified renaming of classes, fields, and methods
8 | * Direct access to the constant pool.
9 |
10 |
11 | ### Example: Renaming classes and members
12 |
13 | Renaming classes and their members is designed currently to function given a jar file.
14 |
15 | Here is an example for renaming a single class and one of its methods.
16 | ```java
17 | JarReader read = new JarReader(new File(IN_FILE), true, true);
18 | read.getMapping().getMapping("com/example/game/Edible").name.setValue("com/example/game/Consumable");
19 | read.getMapping().getMapping("com/example/game/Edible").getMemberMapping("isRotten", "()Z").name.setValue("hasDecayed");
20 | read.saveTo(new File(OUT_FILE));
21 | ```
22 | To rename each item takes only a single line of code. The affects of this change are instantaneous across the program since all class names link to a single instance.
23 |
24 | ### What needs finishing
25 |
26 | This library is still a heavy WIP and the main focus is remapping classes, so some basic functionality not-pertaining to remapping still needs to be completed. For example there is no way to edit instructions in a method.
27 |
28 | ### Credits
29 |
30 | **[Matthew Dupraz](https://github.com/MatthewDupraz)**
31 | * Wrote the original Readme
32 | * Box class + beginnings of the remapping system
33 | * Large portion of the `Type` classes
34 | * Squashing several bugs
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | me.coley
4 | reader
5 | 2.0.0
6 |
7 | UTF-8
8 | 5.6.2
9 |
10 |
11 |
12 |
13 |
14 | org.junit.jupiter
15 | junit-jupiter-api
16 | ${junit.version}
17 | test
18 |
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter-engine
23 | ${junit.version}
24 | test
25 |
26 |
27 |
28 | org.junit.jupiter
29 | junit-jupiter-params
30 | ${junit.version}
31 | test
32 |
33 |
34 |
35 |
36 |
37 |
38 | maven-compiler-plugin
39 | 3.8.0
40 |
41 | 8
42 | 8
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/FieldNode.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.attribute.Attribute;
7 | import me.coley.bmf.attribute.field.AttributeConstantValue;
8 |
9 | /**
10 | * A field.
11 | *
12 | * @author Matt
13 | */
14 | public class FieldNode extends MemberNode {
15 | /**
16 | * Attribute: Finalized value of the field (Will be null if field is not
17 | * final, or the value is not constant)
18 | */
19 | public AttributeConstantValue value;
20 |
21 | public FieldNode(ClassNode owner) {
22 | super(owner);
23 | }
24 |
25 | @Override
26 | public void addAttribute(Attribute attribute) {
27 | switch (attribute.type) {
28 | case CONSTANT_VALUE:
29 | value = (AttributeConstantValue) attribute;
30 | break;
31 | default:
32 | super.addAttribute(attribute);
33 | }
34 | }
35 |
36 | @Override
37 | public List getAttributes() {
38 | List attributes = new ArrayList<>();
39 | if (value != null)
40 | attributes.add(value);
41 | if (signature != null)
42 | attributes.add(signature);
43 | if (runtimeInvisibleAnnotations != null)
44 | attributes.add(runtimeInvisibleAnnotations);
45 | if (runtimeVisibleAnnotations != null)
46 | attributes.add(runtimeVisibleAnnotations);
47 | if (runtimeVisibleParamAnnotations != null)
48 | attributes.add(runtimeVisibleParamAnnotations);
49 | if (runtimeInvisibleParamAnnotations != null)
50 | attributes.add(runtimeInvisibleParamAnnotations);
51 | if (deprecated != null)
52 | attributes.add(deprecated);
53 | if (synthetic != null)
54 | attributes.add(synthetic);
55 | return attributes;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/Main.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 |
6 | import me.coley.bmf.consts.Constant;
7 | import me.coley.bmf.consts.mapping.ConstName;
8 | import me.coley.bmf.mapping.ClassMapping;
9 | import me.coley.bmf.mapping.InnerClassMapping;
10 | import me.coley.bmf.mapping.MemberMapping;
11 | import me.coley.bmf.util.ConstUtil;
12 | import me.coley.bmf.util.ImmutableBox;
13 | import me.coley.bmf.util.io.JarUtil;
14 |
15 | @SuppressWarnings("unused")
16 | public class Main {
17 | private static final String IN_FILE = "tests/Test.jar", OUT_FILE = "tests/OUT.jar";
18 |
19 | public static void main(String[] args) {
20 | long l = System.currentTimeMillis();
21 | all(IN_FILE);
22 | System.out.println("Time Elapsed: " + (System.currentTimeMillis() - l));
23 | }
24 |
25 | private static void all(String file) {
26 | try {
27 | JarReader read = new JarReader(new File(file), true, true);
28 | // read.getMapping().getClassName("com/example/test/Edible").setValue("dank/memes/WeedJokeHere");
29 | // read.getMapping().getClassName("com/example/test/Apple").setValue("keep/the/doctors/Away");
30 | // read.getMapping().getClassName("com/example/test/Fruit").setValue("not/a/Vegetable");
31 | int classIndex = 1;
32 | for (String name : read.getClassEntries().keySet()) {
33 | ClassMapping cm = read.getMapping().getMapping(name);
34 | String obName = getCapName(classIndex);
35 | if (!(cm instanceof InnerClassMapping)){
36 | obName = "AAA/" + obName;
37 | }
38 | cm.name.setValue(obName);
39 | System.out.println(name + " -> " + cm.name.getValue());
40 | int memberIndex = 1;
41 | for (MemberMapping mm : cm.getMembers()) {
42 | if (mm.name.getValue().equals(mm.name.original) && !mm.name.original.equals("main") && !mm.name.original.contains("<")) {
43 | mm.name.setValue(getLowName(memberIndex));
44 | memberIndex++;
45 | }
46 | }
47 | classIndex++;
48 | }
49 | read.saveJarTo(new File(OUT_FILE));
50 | } catch (Exception e) {
51 | e.printStackTrace();
52 | }
53 | }
54 |
55 | public static String getLowName(int i) {
56 | return getString("abcdefghijklmnopqrstuvwxyz", i, 24);
57 | }
58 |
59 | public static String getCapName(int i) {
60 | return getString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", i, 24);
61 | }
62 |
63 | public static String getString(String alpha, int i, int n) {
64 | char[] charz = alpha.toCharArray();
65 | if (n < 2) {
66 | n = 2;
67 | } else if (n > alpha.length()) {
68 | n = alpha.length();
69 | }
70 | final char[] array = new char[33];
71 | final boolean b = i < 0;
72 | int n2 = 32;
73 | if (!b) {
74 | i = -i;
75 | }
76 | while (i <= -n) {
77 | array[n2--] = charz[-(i % n)];
78 | i /= n;
79 | }
80 | array[n2] = charz[-i];
81 | if (b) {
82 | array[--n2] = '_';
83 | }
84 | return new String(array, n2, 33 - n2);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/MemberNode.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf;
2 |
3 | import me.coley.bmf.attribute.*;
4 | import me.coley.bmf.attribute.annotation.*;
5 | import me.coley.bmf.util.ConstUtil;
6 |
7 | /**
8 | * A member. Implementation is either a field or method.
9 | *
10 | * @author Matt
11 | */
12 | public abstract class MemberNode implements AttributeOwner {
13 | /**
14 | * The class the member belongs to.
15 | */
16 | public final ClassNode owner;
17 | /**
18 | * Access. May be multiple combined.
19 | */
20 | public int access;
21 | /**
22 | * Index in the constant pool pointing to the member's name.
23 | */
24 | public int name;
25 | /**
26 | * Index in the constant pool pointing to the member's desc.
27 | */
28 | public int desc;
29 | /**
30 | * Attribute: If not-null, the member is deprecated.
31 | */
32 | public AttributeDeprecated deprecated;
33 | /**
34 | * Attribute: If not-null, the member is synthetic.
35 | */
36 | public AttributeSynthetic synthetic;
37 | /**
38 | * Attribute: Signature for generic information.
39 | */
40 | public AttributeSignature signature;
41 | /**
42 | * Attribute: Annotations
43 | */
44 | public AttributeAnnotations runtimeInvisibleAnnotations;
45 | /**
46 | * Attribute: Annotations
47 | */
48 | public AttributeAnnotations runtimeVisibleAnnotations;
49 | /**
50 | * Attribute: Annotations
51 | */
52 | public AttributeParameterAnnotations runtimeInvisibleParamAnnotations;
53 | /**
54 | * Attribute: Annotations
55 | */
56 | public AttributeParameterAnnotations runtimeVisibleParamAnnotations;
57 |
58 | /**
59 | * Creates the node and sets its owner.
60 | *
61 | * @param owner
62 | */
63 | public MemberNode(ClassNode owner) {
64 | this.owner = owner;
65 | }
66 |
67 | /**
68 | * Finds the member's name by accessing the owner-class's constant pool.
69 | *
70 | * @return The member's name.
71 | */
72 | public String getName() {
73 | return ConstUtil.getUTF8(owner, name);
74 | }
75 |
76 | /**
77 | * Finds the member's descriptor by accessing the owner-class's constant
78 | * pool.
79 | *
80 | * @return The member's descriptor.
81 | */
82 | public String getDesc() {
83 | return ConstUtil.getUTF8(owner, desc);
84 | }
85 |
86 | /**
87 | * Finds the member's signature by accessing the owner-class's constant
88 | * pool.
89 | *
90 | * @return The member's signature. Null if none exists.
91 | */
92 | public String getSignature() {
93 | if (signature == null) {
94 | return null;
95 | }
96 | return ConstUtil.getUTF8(owner, signature.signature);
97 | }
98 |
99 | @Override
100 | public void addAttribute(Attribute attribute) {
101 | switch (attribute.type) {
102 | case SYNTHETIC:
103 | synthetic = (AttributeSynthetic) attribute;
104 | break;
105 | case SIGNATURE:
106 | signature = (AttributeSignature) attribute;
107 | break;
108 | case DEPRECATED:
109 | deprecated = (AttributeDeprecated) attribute;
110 | break;
111 | case RUNTIME_VISIBLE_ANNOTATIONS:
112 | runtimeVisibleAnnotations = (AttributeAnnotations) attribute;
113 | break;
114 | case RUNTIME_INVISIBLE_ANNOTATIONS:
115 | runtimeInvisibleAnnotations = (AttributeAnnotations) attribute;
116 | break;
117 | case RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
118 | runtimeVisibleParamAnnotations = (AttributeParameterAnnotations) attribute;
119 | break;
120 | case RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS:
121 | runtimeInvisibleParamAnnotations = (AttributeParameterAnnotations) attribute;
122 | break;
123 | default:
124 | break;
125 | }
126 | }
127 |
128 | @Override
129 | public String toString() {
130 | return this.getClass().getSimpleName().replace("Node", "") + ":" + access + ", "
131 | + owner.getConst(name).toString() + ", " + owner.getConst(desc);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/MethodNode.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.attribute.Attribute;
7 | import me.coley.bmf.attribute.annotation.AttributeAnnotationDefault;
8 | import me.coley.bmf.attribute.method.AttributeCode;
9 |
10 | /**
11 | * A method.
12 | *
13 | * @author Matt
14 | */
15 | public class MethodNode extends MemberNode {
16 | /**
17 | * Attribute: Method code properties.
18 | */
19 | public AttributeCode code;
20 | /**
21 | * Attribute: Annotations
22 | */
23 | public AttributeAnnotationDefault annotationDefault;
24 |
25 | public MethodNode(ClassNode owner) {
26 | super(owner);
27 | }
28 |
29 | @Override
30 | public void addAttribute(Attribute attribute) {
31 | switch (attribute.type) {
32 | case CODE:
33 | code = (AttributeCode) attribute;
34 | break;
35 | case ANNOTATION_DEFAULT:
36 | annotationDefault = (AttributeAnnotationDefault) attribute;
37 | break;
38 | default:
39 | super.addAttribute(attribute);
40 | }
41 | }
42 |
43 | @Override
44 | public List getAttributes() {
45 | List attributes = new ArrayList<>();
46 | if (code != null) {
47 | attributes.add(code);
48 | }
49 | if (annotationDefault != null) {
50 | attributes.add(annotationDefault);
51 | }
52 | if (signature != null) {
53 | attributes.add(signature);
54 | }
55 | if (runtimeInvisibleAnnotations != null) {
56 | attributes.add(runtimeInvisibleAnnotations);
57 | }
58 | if (runtimeVisibleAnnotations != null) {
59 | attributes.add(runtimeVisibleAnnotations);
60 | }
61 | if (runtimeVisibleParamAnnotations != null) {
62 | attributes.add(runtimeVisibleParamAnnotations);
63 | }
64 | if (runtimeInvisibleParamAnnotations != null) {
65 | attributes.add(runtimeInvisibleParamAnnotations);
66 | }
67 | if (deprecated != null) {
68 | attributes.add(deprecated);
69 | }
70 | if (synthetic != null) {
71 | attributes.add(synthetic);
72 | }
73 | return attributes;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/Attribute.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | /**
6 | * Generic Attribute.
7 | *
8 | * @author Matt
9 | */
10 | public abstract class Attribute implements Measurable {
11 | /**
12 | * An attribute's {@link me.coley.bmf.attribute.AttributeType type}.
13 | */
14 | public final AttributeType type;
15 | /**
16 | * Index of the attribute's name in the constant pool.
17 | */
18 | public int name;
19 |
20 | public Attribute(int name, AttributeType type) {
21 | this.type = type;
22 | this.name = name;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/AttributeDeprecated.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute;
2 |
3 | public class AttributeDeprecated extends Attribute {
4 |
5 | public AttributeDeprecated(int name) {
6 | super(name, AttributeType.DEPRECATED);
7 | }
8 |
9 | @Override
10 | public int getLength() {
11 | return 0;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/AttributeOwner.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute;
2 |
3 | import java.util.List;
4 |
5 | public interface AttributeOwner {
6 | /**
7 | * Adds an attribute to the owner.
8 | *
9 | * @param attribute
10 | */
11 | void addAttribute(Attribute attribute);
12 |
13 | /**
14 | * Collects and returns the attributes into a list.
15 | */
16 | List getAttributes();
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/AttributeSignature.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute;
2 |
3 | public class AttributeSignature extends Attribute {
4 | public int signature;
5 |
6 | public AttributeSignature(int name, int signature) {
7 | super(name, AttributeType.SIGNATURE);
8 | this.signature = signature;
9 | }
10 |
11 | @Override
12 | public int getLength() {
13 | // u2: signature_index
14 | return 2;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/AttributeSynthetic.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute;
2 |
3 | public class AttributeSynthetic extends Attribute {
4 |
5 | public AttributeSynthetic(int name) {
6 | super(name, AttributeType.SYNTHETIC);
7 | }
8 |
9 | @Override
10 | public int getLength() {
11 | return 0;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/AttributeType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Enumeration for handling attributes.
8 | *
9 | * @author Matt
10 | */
11 | public enum AttributeType {
12 | //@formatter:off
13 | CONSTANT_VALUE("ConstantValue"),
14 | CODE("Code"),
15 | // Something really odd is occurring
16 | // Some classes call it a StackMap
17 | // Others call it a StackMapTable
18 | //
19 | //STACK_MAP_TABLE("StackMap"),
20 | STACK_MAP_TABLE("StackMapTable"),
21 | EXCEPTIONS("Exceptions"),
22 | INNER_CLASSES("InnerClasses"),
23 | ENCLOSING_METHOD("EnclosingMethod"),
24 | SYNTHETIC("Synthetic"),
25 | SIGNATURE("Signature"),
26 | SOURCE_FILE("SourceFile"),
27 | SOURCE_DEBUG_EXTENSION("SourceDebugExtension"),
28 | LINE_NUMBER_TABLE("LineNumberTable"),
29 | LOCAL_VARIABLE_TABLE("LocalVariableTable"),
30 | LOCAL_VARIABLE_TYPE_TABLE("LocalVariableTypeTable"),
31 | DEPRECATED("Deprecated"),
32 | RUNTIME_VISIBLE_ANNOTATIONS("RuntimeVisibleAnnotations"),
33 | RUNTIME_INVISIBLE_ANNOTATIONS("RuntimeInvisibleAnnotations"),
34 | RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS("RuntimeVisibleParameterAnnotations"),
35 | RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS("RuntimeInvisibleParameterAnnotations"),
36 | ANNOTATION_DEFAULT("AnnotationDefault"),
37 | BOOTSTRAP_METHODS("BootstrapMethods");
38 | //@formatter:ON
39 | private static Map nameMap;
40 | private final String name;
41 |
42 | AttributeType(String name) {
43 | this.name = name;
44 | register(this);
45 | }
46 |
47 | /**
48 | * Retrieves an Attribute instance by a given name.
49 | *
50 | * @param name
51 | * @return
52 | */
53 | public static AttributeType fromName(String name) {
54 | return nameMap.get(name);
55 | }
56 |
57 | /**
58 | * Registers the Attribute's name to an instance.
59 | *
60 | * @param attribute
61 | */
62 | private void register(AttributeType attribute) {
63 | if (nameMap == null) {
64 | nameMap = new HashMap<>();
65 | }
66 | nameMap.put(name, attribute);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/Annotation.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.annotation.element.ElementValuePair;
6 | import me.coley.bmf.util.Measurable;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | public class Annotation implements Measurable {
10 | /**
11 | * Index in classpool that indicated the annotation's type.
12 | */
13 | public int type;
14 |
15 | /**
16 | * List of describing values.
17 | */
18 | public List elementValuePairs;
19 |
20 | public Annotation(int type, List elementValuePairs) {
21 | this.type = type;
22 | this.elementValuePairs = elementValuePairs;
23 | }
24 |
25 | @Override
26 | public int getLength() {
27 | // u2: type_index
28 | // u2: num_element_value_pairs
29 | // ??: element_value_pairs[num_element_value_pairs]
30 | return 4 + MeasurableUtils.getLength(elementValuePairs);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/AttributeAnnotationDefault.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation;
2 |
3 | import me.coley.bmf.attribute.Attribute;
4 | import me.coley.bmf.attribute.AttributeType;
5 | import me.coley.bmf.attribute.annotation.element.ElementValue;
6 |
7 | public class AttributeAnnotationDefault extends Attribute {
8 | public ElementValue value;
9 |
10 | public AttributeAnnotationDefault(int name, ElementValue value) {
11 | super(name, AttributeType.ANNOTATION_DEFAULT);
12 | this.value = value;
13 | }
14 |
15 | @Override
16 | public int getLength() {
17 | // element_value: value
18 | return value.getLength();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/AttributeAnnotations.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | public class AttributeAnnotations extends Attribute {
10 | public List annotations;
11 |
12 | public AttributeAnnotations(int name, boolean invisible, List annotations) {
13 | super(name,
14 | invisible ? AttributeType.RUNTIME_INVISIBLE_ANNOTATIONS : AttributeType.RUNTIME_VISIBLE_ANNOTATIONS);
15 | this.annotations = annotations;
16 | }
17 |
18 | @Override
19 | public int getLength() {
20 | // u2: num_annotations
21 | // ??: annotations
22 | return 2 + MeasurableUtils.getLength(annotations);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/AttributeParameterAnnotations.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | public class AttributeParameterAnnotations extends Attribute {
10 | /**
11 | * Each entry represents the annotation on a parameter. The indices in the
12 | * list match up to indices of parameters in the method.
13 | */
14 | public List parametersAnnotations;
15 |
16 | public AttributeParameterAnnotations(int name, boolean invisible, List parameterAnnotations) {
17 | super(name, invisible ? AttributeType.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS
18 | : AttributeType.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS);
19 | this.parametersAnnotations = parameterAnnotations;
20 | }
21 |
22 | @Override
23 | public int getLength() {
24 | // u1: num_parameters
25 | // ??: parameter_annotations
26 | return 1 + MeasurableUtils.getLength(parametersAnnotations);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/ParameterAnnotations.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.util.Measurable;
6 | import me.coley.bmf.util.MeasurableUtils;
7 |
8 | public class ParameterAnnotations implements Measurable {
9 | /**
10 | * List of annotations belonging to the parameter.
11 | */
12 | public List annotations;
13 |
14 | public ParameterAnnotations(List annotations) {
15 | this.annotations = annotations;
16 | }
17 |
18 | @Override
19 | public int getLength() {
20 | // u2: num_annotations
21 | // ??: annotations
22 | return 2 + MeasurableUtils.getLength(annotations);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValue.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | /**
6 | * A structure used by annotations that represent different values depending on
7 | * its type.
8 | *
9 | * @author Matt
10 | */
11 | public abstract class ElementValue implements Measurable {
12 | /**
13 | *
14 | * u1: tag
15 | *
16 | */
17 | protected final static int BASE_LEN = 1;
18 | public ElementValueType type;
19 |
20 | public ElementValue(ElementValueType type) {
21 | this.type = type;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValueAnnotationValue.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | import me.coley.bmf.attribute.annotation.Annotation;
4 |
5 | public class ElementValueAnnotationValue extends ElementValue {
6 | /**
7 | * Nested annotation structure.
8 | */
9 | public Annotation annotation;
10 |
11 | public ElementValueAnnotationValue(Annotation annotation) {
12 | super(ElementValueType.ANNOTATION_VALUE);
13 | this.annotation = annotation;
14 | }
15 |
16 | @Override
17 | public int getLength() {
18 | return BASE_LEN + annotation.getLength();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValueArrayValue.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.util.MeasurableUtils;
6 |
7 | public class ElementValueArrayValue extends ElementValue {
8 | /**
9 | * Nested list of element values.
10 | */
11 | public List values;
12 |
13 | public ElementValueArrayValue(List values) {
14 | super(ElementValueType.ARRAY_VALUE);
15 | this.values = values;
16 | }
17 |
18 | @Override
19 | public int getLength() {
20 | // u2: num_values
21 | // ??: element_value values[num_values]
22 | return BASE_LEN + 2 + MeasurableUtils.getLength(values);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValueClassInfoIndex.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | public class ElementValueClassInfoIndex extends ElementValue {
4 | /**
5 | * Points to a UTF constant pool entry indicating the return descriptor of
6 | * the class.
7 | * Example:
8 | *
9 | * - v = Void.class
10 | *
- Ljava/lang/Object; = Object.class
11 | *
12 | */
13 | public int classInfoIndex;
14 |
15 | public ElementValueClassInfoIndex(int classInfoIndex) {
16 | super(ElementValueType.CLASS_INFO_INDEX);
17 | this.classInfoIndex = classInfoIndex;
18 | }
19 |
20 | @Override
21 | public int getLength() {
22 | // u2: class_info_index
23 | return BASE_LEN + 2;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValueConstValueIndex.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | public class ElementValueConstValueIndex extends ElementValue {
4 | /**
5 | * Points to a primitive constant value in the constant pool.
6 | */
7 | public int constValueIndex;
8 |
9 | public ElementValueConstValueIndex(ElementValueType type, int constValueIndex) {
10 | super(type);
11 | this.constValueIndex = constValueIndex;
12 | }
13 |
14 | @Override
15 | public int getLength() {
16 | // u2: const_value_index
17 | return BASE_LEN + 2;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValueEnumConstValue.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | public class ElementValueEnumConstValue extends ElementValue {
4 | /**
5 | * Points to a UTF8 constant pool value indicating a field descriptor.
6 | */
7 | public int type;
8 | /**
9 | * Points to a UTF constant pool value indicating the name of the enum
10 | * constant.
11 | */
12 | public int name;
13 |
14 | public ElementValueEnumConstValue(int type, int name) {
15 | super(ElementValueType.ENUM_CONST_VALUE);
16 | this.type = type;
17 | this.name = name;
18 | }
19 |
20 | @Override
21 | public int getLength() {
22 | // u2: type_name_index
23 | // u2: const_name_index
24 | return BASE_LEN + 4;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValuePair.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | public class ElementValuePair implements Measurable {
6 | /**
7 | * Index in constant pool that indicated the pair's name.
8 | */
9 | public int name;
10 | /**
11 | * The value of the pair.
12 | */
13 | public ElementValue value;
14 |
15 | public ElementValuePair(int name, ElementValue value) {
16 | this.name = name;
17 | this.value = value;
18 | }
19 |
20 | @Override
21 | public int getLength() {
22 | // u2: element_name_index
23 | // element_value: value
24 | return 2 + value.getLength();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/annotation/element/ElementValueType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.annotation.element;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public enum ElementValueType {
7 | //@formatter:off
8 | CONST_VALUE_INDEX_BYTE('B'),
9 | CONST_VALUE_INDEX_C('C'),
10 | CONST_VALUE_INDEX_DOUBLE('D'),
11 | CONST_VALUE_INDEX_FLOAT('F'),
12 | CONST_VALUE_INDEX_INT('I'),
13 | CONST_VALUE_INDEX_LONG('J'),
14 | CONST_VALUE_INDEX_SHORT('S'),
15 | CONST_VALUE_INDEX_BOOLEAN('Z'),
16 | CONST_VALUE_INDEX_s('s'),
17 | ENUM_CONST_VALUE('e'),
18 | CLASS_INFO_INDEX('c'),
19 | ANNOTATION_VALUE('@'),
20 | ARRAY_VALUE('[');
21 | //@formatter:on
22 |
23 | private static Map typeMap;
24 | public final char key;
25 |
26 | ElementValueType(char key) {
27 | this.key = key;
28 | register(this);
29 | }
30 |
31 | /**
32 | * Retrieves an ElementValueType by a given name.
33 | *
34 | * @param tag
35 | * @return
36 | */
37 | public static ElementValueType fromType(char tag) {
38 | return typeMap.get(tag);
39 | }
40 |
41 | /**
42 | * Registers the ElementValueType's associated types to an instance.
43 | *
44 | * @param valueType
45 | */
46 | private void register(ElementValueType type) {
47 | if (typeMap == null) {
48 | typeMap = new HashMap<>();
49 | }
50 | typeMap.put(key, type);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/AttributeBootstrapMethods.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | public class AttributeBootstrapMethods extends Attribute {
10 | public List methods;
11 |
12 | public AttributeBootstrapMethods(int name, List methods) {
13 | super(name, AttributeType.BOOTSTRAP_METHODS);
14 | this.methods = methods;
15 | }
16 |
17 | @Override
18 | public int getLength() {
19 | // u2: num_methods
20 | // ??:
21 | return 2 + MeasurableUtils.getLength(methods);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/AttributeEnclosingMethod.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import me.coley.bmf.attribute.Attribute;
4 | import me.coley.bmf.attribute.AttributeType;
5 |
6 | public class AttributeEnclosingMethod extends Attribute {
7 | public int classIndex;
8 | public int methodIndex;
9 |
10 | public AttributeEnclosingMethod(int name, int classIndex, int methodIndex) {
11 | super(name, AttributeType.ENCLOSING_METHOD);
12 | this.classIndex = classIndex;
13 | this.methodIndex = methodIndex;
14 | }
15 |
16 | @Override
17 | public int getLength() {
18 | // u2: class_index
19 | // u2: method_index
20 | return 4;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/AttributeInnerClasses.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | public class AttributeInnerClasses extends Attribute {
10 | public List classes;
11 |
12 | public AttributeInnerClasses(int name, List classes) {
13 | super(name, AttributeType.INNER_CLASSES);
14 | this.classes = classes;
15 | }
16 |
17 | @Override
18 | public int getLength() {
19 | // u2: num_classes
20 | // ?: classes
21 | return 2 + MeasurableUtils.getLength(classes);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/AttributeSourceDebugExtension.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 |
8 | public class AttributeSourceDebugExtension extends Attribute {
9 | /**
10 | * Holds extended debugging information which has no semantic effect on the
11 | * Java Virtual Machine. The information is represented using a modified
12 | * UTF-8 string with no terminating zero byte.
13 | */
14 | public List data;
15 |
16 | public AttributeSourceDebugExtension(int name, List data) {
17 | super(name, AttributeType.SOURCE_DEBUG_EXTENSION);
18 | this.data = data;
19 | }
20 |
21 | @Override
22 | public int getLength() {
23 | // u1[]: debug_extension[attribute_length]
24 | // TODO Verify that this is correct
25 | return data.size();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/AttributeSourceFile.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import me.coley.bmf.attribute.Attribute;
4 | import me.coley.bmf.attribute.AttributeType;
5 |
6 | public class AttributeSourceFile extends Attribute {
7 | public int sourceFile;
8 |
9 | public AttributeSourceFile(int name, int sourceFile) {
10 | super(name, AttributeType.SOURCE_FILE);
11 | this.sourceFile = sourceFile;
12 | }
13 |
14 | @Override
15 | public int getLength() {
16 | // u2: source_index
17 | return 2;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/BootstrapMethod.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.util.Measurable;
7 |
8 | public class BootstrapMethod implements Measurable {
9 | public int methodReference;
10 | public List arguments;
11 |
12 | public BootstrapMethod(int methodReference, int argCount) {
13 | this.methodReference = methodReference;
14 | this.arguments = new ArrayList(argCount);
15 | }
16 |
17 | public void addArgument(int arg) {
18 | arguments.add(arg);
19 | }
20 |
21 | @Override
22 | public int getLength() {
23 | // u2: method_ref
24 | // u2: num_args
25 | // u2[]: args
26 | return 4 + (2 * arguments.size());
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/clazz/InnerClass.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.clazz;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | public class InnerClass implements Measurable {
6 | /**
7 | * Constant pool index of ConstClass of the inner class.
8 | */
9 | public int innerClassIndex;
10 | /**
11 | * Constant pool index of ConstClass of the outer class.
12 | */
13 | public int outerClassIndex;
14 | /**
15 | * Constant pool index of the UTF8 of the inner class's name.
16 | */
17 | public int innerName;
18 | /**
19 | * Constant pool index of the
20 | */
21 | public int innerAccess;
22 |
23 | public InnerClass(int innerIndex, int outerIndex, int cInnerName, int innerAccess) {
24 | this.innerClassIndex = innerIndex;
25 | this.outerClassIndex = outerIndex;
26 | this.innerName = cInnerName;
27 | this.innerAccess = innerAccess;
28 | }
29 |
30 | @Override
31 | public int getLength() {
32 | // u2: inner_class_index
33 | // u2: outer_class_index
34 | // u2: inner_name
35 | // u2: inner_access
36 | return 8;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/field/AttributeConstantValue.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.field;
2 |
3 | import me.coley.bmf.attribute.Attribute;
4 | import me.coley.bmf.attribute.AttributeType;
5 |
6 | public class AttributeConstantValue extends Attribute {
7 | public int constantIndex;
8 |
9 | public AttributeConstantValue(int name, int constantIndex) {
10 | super(name, AttributeType.CONSTANT_VALUE);
11 | this.constantIndex = constantIndex;
12 | }
13 |
14 | @Override
15 | public int getLength() {
16 | // u2: constantIndex
17 | return 2;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/AttributeCode.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | /**
10 | * The Code of a method. Contains sub-attributes:
11 | *
12 | * - {@link #lines LineNumberTable} - May be null
13 | *
- {@link #variables LocalVariableTable} - May be null
14 | *
- {@link #variableTypes LocalVariableTypeTable}
15 | *
- {@link #stackMap StackMapTable}
16 | *
17 | * May contain others, but those four are standard.
18 | *
19 | * @author Matt
20 | */
21 | public class AttributeCode extends Attribute {
22 | /**
23 | * Max number of values allowed on the stack.
24 | */
25 | public int maxStack;
26 | /**
27 | * Max number of variables allowed in the method.
28 | */
29 | public int maxLocals;
30 |
31 | /**
32 | * A list of {@link me.coley.bmf.attribute.method.MethodException
33 | * exceptions}.
34 | */
35 | public List exceptions;
36 |
37 | /**
38 | * A {@link me.coley.bmf.attribute.method.AttributeLineNumberTable table}
39 | * that correlates opcode indices and line numbers (Debugging).
40 | * May be null.
41 | */
42 | public AttributeLineNumberTable lines;
43 | /**
44 | * A {@link me.coley.bmf.attribute.method.AttributeLocalVariableTable
45 | * table} containing local variables.
46 | */
47 | public AttributeLocalVariableTable variables;
48 | /**
49 | * A {@link me.coley.bmf.attribute.method.AttributeLocalVariableTypeTable
50 | * table} containing types of local variables.
51 | * May be null
52 | */
53 | public AttributeLocalVariableTypeTable variableTypes;
54 | /**
55 | * A {@link me.coley.bmf.attribute.method.AttributeStackMapTable table}
56 | * that supplies information about the stack and stored locals at given
57 | * bytecode offsets.
58 | */
59 | public AttributeStackMapTable stackMap;
60 |
61 | /**
62 | * A {@link me.coley.bmf.attribute.method.MethodException structure}
63 | * containing the opcodes.
64 | */
65 | public MethodCode instructions;
66 |
67 | public AttributeCode(int name, int stack, int locals, List exceptions, MethodCode instructions,
68 | List attributes) {
69 | super(name, AttributeType.CODE);
70 | this.maxStack = stack;
71 | this.maxLocals = locals;
72 | this.exceptions = exceptions;
73 | this.instructions = instructions;
74 | for (Attribute attribute : attributes) {
75 | switch (attribute.type) {
76 | case LINE_NUMBER_TABLE:
77 | lines = (AttributeLineNumberTable) attribute;
78 | break;
79 | case LOCAL_VARIABLE_TABLE:
80 | variables = (AttributeLocalVariableTable) attribute;
81 | break;
82 | case LOCAL_VARIABLE_TYPE_TABLE:
83 | variableTypes = (AttributeLocalVariableTypeTable) attribute;
84 | break;
85 | case STACK_MAP_TABLE:
86 | stackMap = (AttributeStackMapTable) attribute;
87 | break;
88 | default:
89 | System.err.println("UNHANDLED CODE ATTRIB: " + attribute.type.name());
90 | break;
91 | }
92 | }
93 | }
94 |
95 | @Override
96 | public int getLength() {
97 | // Common to all attributes, only needed in length calculation for
98 | // embedded attributes.
99 | // u2: name_index
100 | // u4: attribute_length
101 | int baseLen = 6;
102 | // u2: max_stack
103 | // u2: max_locals
104 | int len = 4;
105 | // u4: code_length
106 | // ??: CODE
107 | len += 4;
108 | if (instructions != null) {
109 | len += instructions.getLength();
110 | }
111 | // u2: exception_table_length
112 | // ??: EXCEPTIONS
113 | len += 2;
114 | if (exceptions.size() > 0) {
115 | len += MeasurableUtils.getLength(exceptions);
116 | }
117 | // u2: attributes_count
118 | // ??: ATTRIBS
119 | len += 2;
120 | if (lines != null) {
121 | len += baseLen + lines.getLength();
122 | }
123 | if (variables != null) {
124 | len += baseLen + variables.getLength();
125 | }
126 | if (variableTypes != null) {
127 | len += baseLen + variableTypes.getLength();
128 | }
129 | if (stackMap != null) {
130 | len += baseLen + stackMap.getLength();
131 | }
132 | return len;
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/AttributeExceptions.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 |
8 | public class AttributeExceptions extends Attribute {
9 | public List exceptionIndicies;
10 |
11 | public AttributeExceptions(int name, List exceptionIndicies) {
12 | super(name, AttributeType.EXCEPTIONS);
13 | this.exceptionIndicies = exceptionIndicies;
14 | }
15 |
16 | @Override
17 | public int getLength() {
18 | // u2: num_exceptions
19 | // u2[]: exceptions
20 | return 2 + (2 * exceptionIndicies.size());
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/AttributeLineNumberTable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import me.coley.bmf.attribute.Attribute;
4 | import me.coley.bmf.attribute.AttributeType;
5 |
6 | /**
7 | * An attribute belonging to the
8 | * "{@link me.coley.bmf.attribute.method.AttributeCode Code}" attribute of a
9 | * method. The table correlates instruction indices with java line numbers (For
10 | * debugging).
11 | */
12 | public class AttributeLineNumberTable extends Attribute {
13 | /**
14 | * The {@link me.coley.bmf.attribute.method.LineNumberTable table}.
15 | */
16 | public LineNumberTable lines;
17 |
18 | public AttributeLineNumberTable(int name, LineNumberTable lines) {
19 | super(name, AttributeType.LINE_NUMBER_TABLE);
20 | this.lines = lines;
21 | }
22 |
23 | @Override
24 | public int getLength() {
25 | // ??: linetable
26 | return lines.getLength();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/AttributeLocalVariableTable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import me.coley.bmf.attribute.Attribute;
4 | import me.coley.bmf.attribute.AttributeType;
5 |
6 | /**
7 | * An attribute belonging to the
8 | * "{@link me.coley.bmf.attribute.method.AttributeCode Code}" attribute of a
9 | * method. Contains information about local variables.
10 | *
11 | * @author Matt
12 | */
13 | public class AttributeLocalVariableTable extends Attribute {
14 | /**
15 | * The {@link me.coley.bmf.attribute.method.LocalVariableTable table}.
16 | */
17 | public LocalVariableTable variableTable;
18 |
19 | public AttributeLocalVariableTable(int name, LocalVariableTable variableTable) {
20 | super(name, AttributeType.LOCAL_VARIABLE_TABLE);
21 | this.variableTable = variableTable;
22 | }
23 |
24 | @Override
25 | public int getLength() {
26 | return variableTable.getLength();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/AttributeLocalVariableTypeTable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | public class AttributeLocalVariableTypeTable extends Attribute {
10 | public List localTypes;
11 |
12 | public AttributeLocalVariableTypeTable(int name, List localTypes) {
13 | super(name, AttributeType.LOCAL_VARIABLE_TYPE_TABLE);
14 | this.localTypes = localTypes;
15 | }
16 |
17 | @Override
18 | public int getLength() {
19 | // u2: num_variables
20 | // ??: variable_table
21 | return 2 + MeasurableUtils.getLength(localTypes);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/AttributeStackMapTable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.attribute.Attribute;
6 | import me.coley.bmf.attribute.AttributeType;
7 | import me.coley.bmf.util.Measurable;
8 | import me.coley.bmf.util.MeasurableUtils;
9 |
10 | public class AttributeStackMapTable extends Attribute {
11 | public List frames;
12 |
13 | public AttributeStackMapTable(int name, List frames) {
14 | super(name, AttributeType.STACK_MAP_TABLE);
15 | this.frames = frames;
16 | }
17 |
18 | @Override
19 | public int getLength() {
20 | // u2: number_of_entries
21 | return 2 + MeasurableUtils.getLength(frames);
22 | }
23 |
24 | public static class VerificationType implements Measurable {
25 | public int tag;
26 |
27 | public VerificationType(int tag) {
28 | this.tag = tag;
29 | }
30 |
31 | @Override
32 | public int getLength() {
33 | // u1: tag
34 | return 1;
35 | }
36 |
37 | public static class ObjectVariable extends VerificationType {
38 | public int poolIndex;
39 |
40 | public ObjectVariable(int poolIndex) {
41 | super(7);
42 | this.poolIndex = poolIndex;
43 | }
44 |
45 | @Override
46 | public int getLength() {
47 | // u1: tag
48 | // u2: cpool_index
49 | return 3;
50 | }
51 | }
52 |
53 | public static class UninitializedVariable extends VerificationType {
54 | public int offset;
55 |
56 | public UninitializedVariable(int offset) {
57 | super(8);
58 | this.offset = offset;
59 | }
60 |
61 | @Override
62 | public int getLength() {
63 | // u1: tag
64 | // u2: cpool_index
65 | return 3;
66 | }
67 | }
68 |
69 | }
70 |
71 | public abstract static class Frame implements Measurable {
72 | protected int type;
73 |
74 | public Frame(int type) {
75 | this.type = type;
76 | }
77 |
78 | public int getType() {
79 | return type;
80 | }
81 |
82 | public static class Same extends Frame {
83 | public Same(int type) {
84 | super(type);
85 | }
86 |
87 | @Override
88 | public int getLength() {
89 | // u1: frame_type
90 | return 1;
91 | }
92 | }
93 |
94 | public static class SameExtended extends Same {
95 | public int offsetDelta;
96 |
97 | public SameExtended(int offsetDelta) {
98 | super(251);
99 | this.offsetDelta = offsetDelta;
100 | }
101 |
102 | @Override
103 | public int getLength() {
104 | // u1: frame_type
105 | // u2: offset_delta
106 | return 3;
107 | }
108 | }
109 |
110 | public static class SameLocals1StackItem extends Frame {
111 | public VerificationType stack;
112 | public int offsetDelta;
113 |
114 | public SameLocals1StackItem(int type, VerificationType stack) {
115 | super(type);
116 | offsetDelta = type - 64;
117 | this.stack = stack;
118 | }
119 |
120 | @Override
121 | public int getLength() {
122 | // u1: frame_type
123 | return 1 + stack.getLength();
124 | }
125 | }
126 |
127 | public static class SameLocals1StackItemExtended extends SameLocals1StackItem {
128 | public SameLocals1StackItemExtended(int offsetDelta, VerificationType stack) {
129 | super(247, stack);
130 | this.offsetDelta = offsetDelta;
131 | }
132 |
133 | @Override
134 | public int getLength() {
135 | // u1: frame_type
136 | // u2: offset_delta
137 | return 3 + stack.getLength();
138 | }
139 | }
140 |
141 | public static class Chop extends Frame {
142 | public int offsetDelta;
143 |
144 | public Chop(int type, int offsetDelta) {
145 | super(type);
146 | this.offsetDelta = offsetDelta;
147 | // offsetDelta = 251 - type;
148 | }
149 |
150 | @Override
151 | public int getLength() {
152 | // u1: frame_type
153 | // u2: offset_delta
154 | return 3;
155 | }
156 | }
157 |
158 | public static class Append extends Frame {
159 | public List locals;
160 | public int offsetDelta;
161 |
162 | public Append(int type, int offsetDelta, List locals) {
163 | super(type);
164 | this.offsetDelta = offsetDelta;
165 | this.locals = locals;
166 | }
167 |
168 | @Override
169 | public int getLength() {
170 | // u1: frame_type
171 | // u2: offset_delta
172 | return 3 + MeasurableUtils.getLength(locals);
173 | }
174 | }
175 |
176 | public static class Full extends Frame {
177 | public int offsetDelta;
178 | public List locals, stack;
179 |
180 | public Full(int offsetDelta, List locals, List stack) {
181 | super(255);
182 | this.offsetDelta = offsetDelta;
183 | this.locals = locals;
184 | this.stack = stack;
185 | }
186 |
187 | @Override
188 | public int getLength() {
189 | // u1: frame_type
190 | // u2: offset_delta
191 | // u2: number_of_locals
192 | // u2: number_of_stack_items
193 | return 7 + MeasurableUtils.getLength(locals) + MeasurableUtils.getLength(stack);
194 | }
195 | }
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/LineNumberTable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import me.coley.bmf.util.Measurable;
7 |
8 | public class LineNumberTable implements Measurable {
9 | public Map indexToLine = new HashMap<>();
10 |
11 | public void add(int startPC, int lineNumber) {
12 | indexToLine.put(startPC, lineNumber);
13 | }
14 |
15 | @Override
16 | public int getLength() {
17 | // u2: num_lines
18 | // [u2: start_pc, u2: line_number]
19 | return 2 + (4 * indexToLine.size());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/Local.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | /**
6 | * Local variable entry for the
7 | * {@link me.coley.bmf.attribute.method.LocalVariableTable}.
8 | *
9 | * - {@link #start}
10 | *
- {@link #length}
11 | *
- {@link #name}
12 | *
- {@link #desc}
13 | *
- {@link #index}
14 | *
15 | *
16 | * @author Matt
17 | */
18 | public class Local implements Measurable {
19 |
20 | /**
21 | * Start index in the instructions
22 | */
23 | public int start;
24 | /**
25 | * Length from start local lasts in the instructions
26 | */
27 | public int length;
28 | /**
29 | * Constant pool pointers
30 | */
31 | public int name;
32 | public int desc;
33 | /**
34 | * Stack frame index. Doubles/Longs take two indices.
35 | */
36 | public int index;
37 |
38 | /**
39 | * Creates and assigned values to the local variable entry.
40 | *
41 | * @param start
42 | * {@link #start}
43 | * @param length
44 | * {@link #length}
45 | * @param name
46 | * {@link #name}
47 | * @param desc
48 | * {@link #desc}
49 | * @param index
50 | * {@link #index}
51 | */
52 | public Local(int start, int length, int name, int desc, int index) {
53 | this.start = start;
54 | this.length = length;
55 | this.name = name;
56 | this.desc = desc;
57 | this.index = index;
58 | }
59 |
60 | @Override
61 | public int getLength() {
62 | // u2: start_pc
63 | // u2: length
64 | // u2: name_index
65 | // u2: descriptor_index
66 | // u2: index
67 | return 10;
68 | }
69 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/LocalVariableTable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.util.Measurable;
7 | import me.coley.bmf.util.MeasurableUtils;
8 |
9 | /**
10 | * Local variable table attribute belonging to a {@link me.coley.bmf.MethodNode
11 | * method's} "{@link me.coley.bmf.attribute.method.AttributeCode Code}"
12 | * attribute.
13 | *
14 | * @author Matt
15 | */
16 | public class LocalVariableTable implements Measurable {
17 | public List locals;
18 |
19 | public LocalVariableTable(int size) {
20 | locals = new ArrayList(size);
21 | }
22 |
23 | /**
24 | * Creates and adds a local variable to the table. See the documentation of
25 | * {@link me.coley.bmf.attribute.method.Local Local} for more information.
26 | *
27 | * @param start
28 | * Start index in the instructions
29 | * @param len
30 | * Length from start local lasts in the instructions
31 | * @param name
32 | * Constant pool pointers
33 | * @param desc
34 | * Constant pool pointers
35 | * @param index
36 | * Stack frame index.
37 | */
38 | public void add(int start, int len, int name, int desc, int index) {
39 | locals.add(new Local(start, len, name, desc, index));
40 | }
41 |
42 | @Override
43 | public int getLength() {
44 | // u2: num_locals
45 | // ??: locals
46 | return 2 + MeasurableUtils.getLength(locals);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/LocalVariableType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | public class LocalVariableType implements Measurable {
6 | public int start;
7 | public int length;
8 | public int name;
9 | public int signature;
10 | public int index;
11 |
12 | public LocalVariableType(int start, int len, int name, int signature, int index) {
13 | this.start = start;
14 | this.length = len;
15 | this.name = name;
16 | this.signature = signature;
17 | this.index = index;
18 | }
19 |
20 | @Override
21 | public int getLength() {
22 | // u2: start_pc
23 | // u2: length
24 | // u2: name_index
25 | // u2: signature_index
26 | // u2: index
27 | return 10;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/MethodCode.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.insn.Instruction;
6 | import me.coley.bmf.util.Measurable;
7 |
8 | /**
9 | * TODO refactor this to be more useful.
10 | *
11 | * @author Matt
12 | */
13 | public class MethodCode implements Measurable {
14 | public final byte[] original;
15 | public List instructions;
16 |
17 | public MethodCode(byte[] original) {
18 | this.original = original;
19 | }
20 |
21 | @Override
22 | public int getLength() {
23 | // TODO: What opcode is the wrong length?
24 | /*
25 | if (opcodes != null) {
26 | return MeasurableUtils.getLength(opcodes);
27 | }*/
28 | return original.length;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/attribute/method/MethodException.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.attribute.method;
2 |
3 | import me.coley.bmf.util.Measurable;
4 |
5 | public class MethodException implements Measurable {
6 | /**
7 | * Instruction indices in the method.
8 | */
9 | public int start, end, handler;
10 | /**
11 | * Index in the constant pool of the type of exeption handled.
12 | */
13 | public int type;
14 |
15 | @Override
16 | public int getLength() {
17 | // u2: start_pc
18 | // u2: end_pc
19 | // u2: handler_pc
20 | // u2: catch_type
21 | return 8;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/AbstractMemberConstant.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class AbstractMemberConstant extends Constant {
4 | private int nameType;
5 |
6 | public AbstractMemberConstant(ConstantType type, int clazz, int nameType) {
7 | super(type, clazz);
8 | this.nameType = nameType;
9 | }
10 |
11 | public int getClassIndex() {
12 | return super.getValue();
13 | }
14 |
15 | public int getNameTypeIndex() {
16 | return nameType;
17 | }
18 |
19 | public void setClassIndex(int index) {
20 | this.setValue(index);
21 | }
22 |
23 | public void setNameTypeIndex(int index) {
24 | this.nameType = index;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstClass.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstClass extends Constant {
4 |
5 | public ConstClass(int name) {
6 | super(ConstantType.CLASS, name);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstDouble.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstDouble extends Constant {
4 | public ConstDouble(double value) {
5 | super(ConstantType.DOUBLE, value);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstDynamic.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstDynamic extends Constant {
4 | private int nameType;
5 |
6 | public ConstDynamic(int attribute, int nameType) {
7 | super(ConstantType.DYNAMIC, attribute);
8 | this.nameType = nameType;
9 | }
10 |
11 | public int getBootstrapAttribute() {
12 | return this.getValue();
13 | }
14 |
15 | public int getNameTypeIndex() {
16 | return nameType;
17 | }
18 |
19 | public void setBootstrapAttribute(int index) {
20 | this.setValue(index);
21 | }
22 |
23 | public void setNameTypeIndex(int index) {
24 | this.nameType = index;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstField.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstField extends AbstractMemberConstant {
4 | public ConstField(int clazz, int nameType) {
5 | super(ConstantType.FIELD, clazz, nameType);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstFloat.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstFloat extends Constant {
4 | public ConstFloat(float value) {
5 | super(ConstantType.FLOAT, value);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstInt.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstInt extends Constant {
4 | public ConstInt(int value) {
5 | super(ConstantType.INT, value);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstInterfaceMethod.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstInterfaceMethod extends AbstractMemberConstant {
4 | public ConstInterfaceMethod(int clazz, int nameType) {
5 | super(ConstantType.INTERFACE_METHOD, clazz, nameType);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstInvokeDynamic.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstInvokeDynamic extends Constant {
4 | private int nameType;
5 |
6 | public ConstInvokeDynamic(int attribute, int nameType) {
7 | super(ConstantType.INVOKEDYNAMIC, attribute);
8 | this.nameType = nameType;
9 | }
10 |
11 | public int getBootstrapAttribute() {
12 | return this.getValue();
13 | }
14 |
15 | public int getNameTypeIndex() {
16 | return nameType;
17 | }
18 |
19 | public void setBootstrapAttribute(int index) {
20 | this.setValue(index);
21 | }
22 |
23 | public void setNameTypeIndex(int index) {
24 | this.nameType = index;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstLong.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstLong extends Constant {
4 | public ConstLong(long value) {
5 | super(ConstantType.LONG, value);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstMethod.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstMethod extends AbstractMemberConstant {
4 | public ConstMethod(int clazz, int nameType) {
5 | super(ConstantType.METHOD, clazz, nameType);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstMethodHandle.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstMethodHandle extends Constant {
4 | private int kind;
5 |
6 | public ConstMethodHandle(int kind, int index) {
7 | super(ConstantType.METHOD_HANDLE, index);
8 | this.kind = kind;
9 | }
10 |
11 | public int getKind() {
12 | return kind;
13 | }
14 |
15 | public void setKind(int kind) {
16 | this.kind = kind;
17 | }
18 |
19 | public int getIndex() {
20 | return getValue();
21 | }
22 |
23 | public void setIndex(int index) {
24 | this.setValue(index);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstMethodType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstMethodType extends Constant {
4 | public ConstMethodType(int index) {
5 | super(ConstantType.METHOD_TYPE, index);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstModule.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstModule extends Constant {
4 | public ConstModule(int name) {
5 | super(ConstantType.MODULE, name);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstNameType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstNameType extends Constant {
4 | private int descIndex;
5 |
6 | public ConstNameType(int nameIndex, int descIndex) {
7 | super(ConstantType.NAME_TYPE, nameIndex);
8 | this.descIndex = descIndex;
9 | }
10 |
11 | public int getNameIndex() {
12 | return this.getValue();
13 | }
14 |
15 | public void setNameIndex(int nameIndex) {
16 | this.setValue(nameIndex);
17 | }
18 |
19 | public int getDescIndex() {
20 | return descIndex;
21 | }
22 |
23 | public void setDescIndex(int index) {
24 | this.descIndex = index;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstPackage.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstPackage extends Constant {
4 | public ConstPackage(int name) {
5 | super(ConstantType.PACKAGE, name);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstString.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstString extends Constant {
4 |
5 | public ConstString(int index) {
6 | super(ConstantType.STRING, index);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstUTF8.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | public class ConstUTF8 extends Constant {
4 | public ConstUTF8() {
5 | this(null);
6 | }
7 |
8 | public ConstUTF8(String data) {
9 | super(ConstantType.UTF8, data);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/Constant.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | import java.util.Objects;
4 |
5 | /**
6 | * A generic constant class. An entry in a class's constant pool.
7 | *
8 | * @param
9 | * @author Matt
10 | */
11 | public abstract class Constant {
12 | /**
13 | * Constant type.
14 | */
15 | public final ConstantType type;
16 | /**
17 | * Constant's value.
18 | */
19 | private T value;
20 |
21 | public Constant(ConstantType type) {
22 | this(type, null);
23 | }
24 |
25 | public Constant(ConstantType type, T value) {
26 | this.type = Objects.requireNonNull(type);
27 | this.value = value;
28 | }
29 |
30 | public T getValue() {
31 | return value;
32 | }
33 |
34 | public void setValue(T value) {
35 | this.value = value;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return type.toString() + ":" + getValue();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/ConstantType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Enumeration for handling constant pool entry types.
8 | *
9 | * @author Matt
10 | */
11 | public enum ConstantType {
12 | UTF8(1),
13 | INT(3),
14 | FLOAT(4),
15 | LONG(5),
16 | DOUBLE(6),
17 | CLASS(7),
18 | STRING(8),
19 | FIELD(9),
20 | METHOD(10),
21 | INTERFACE_METHOD(11),
22 | NAME_TYPE(12),
23 | METHOD_HANDLE(15),
24 | METHOD_TYPE(16),
25 | DYNAMIC(17),
26 | INVOKEDYNAMIC(18),
27 | MODULE(19),
28 | PACKAGE(20);
29 |
30 | /**
31 | * The tag of the Constant type.
32 | */
33 | private static Map typeMap;
34 | private final int tag;
35 |
36 | ConstantType(int tag) {
37 | this.tag = tag;
38 | register(this);
39 | }
40 |
41 | /**
42 | * Retrieves a ConstantType instance from a given tag.
43 | *
44 | * @param tag
45 | * @return
46 | */
47 | public static ConstantType fromTag(int tag) {
48 | return typeMap.get(tag);
49 | }
50 |
51 | /**
52 | * Checks if given tag matches a const type.
53 | *
54 | * @param tag
55 | * @param type
56 | * @return
57 | */
58 | public static boolean matches(int tag, ConstantType type) {
59 | return (tag & type.tag) != 0;
60 | }
61 |
62 | /**
63 | * Registers the ConstantType's tag to an instance.
64 | *
65 | * @param type
66 | */
67 | private void register(ConstantType type) {
68 | if (typeMap == null) {
69 | typeMap = new HashMap<>();
70 | }
71 | typeMap.put(tag, type);
72 | }
73 |
74 | public int getTag() {
75 | return tag;
76 | }
77 |
78 | @Override
79 | public String toString() {
80 | return name().replace("_", " ").toLowerCase();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/mapping/ConstMemberDesc.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts.mapping;
2 |
3 | import me.coley.bmf.consts.ConstUTF8;
4 | import me.coley.bmf.type.descriptors.MemberDescriptor;
5 |
6 | public class ConstMemberDesc extends ConstUTF8 {
7 | public final MemberDescriptor desc;
8 |
9 | public ConstMemberDesc(MemberDescriptor desc) {
10 | super();
11 | // For testing.
12 | // TODO: Decide if this practice should be applied globally
13 | if (desc == null)
14 | throw new RuntimeException("Cannot have a null value for ConstMemberDesc!");
15 | this.desc = desc;
16 | }
17 |
18 | @Override
19 | public String getValue() {
20 | return desc.toDesc();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/mapping/ConstName.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts.mapping;
2 |
3 | import me.coley.bmf.consts.ConstUTF8;
4 | import me.coley.bmf.util.Box;
5 |
6 | public class ConstName extends ConstUTF8 {
7 | private Box name;
8 |
9 | public ConstName(String name) {
10 | this(new Box(name));
11 | }
12 |
13 | public ConstName(Box name) {
14 | super();
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | public String getValue() {
20 | return name.getValue();
21 | }
22 |
23 | @Override
24 | public void setValue(String value) {
25 | name.setValue(value);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/consts/mapping/ConstSignature.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.consts.mapping;
2 |
3 | import me.coley.bmf.consts.ConstUTF8;
4 | import me.coley.bmf.signature.Signature;
5 |
6 | public class ConstSignature extends ConstUTF8 {
7 | public Signature sig;
8 |
9 | public ConstSignature(Signature sig) {
10 | this.sig = sig;
11 | }
12 |
13 | @Override
14 | public String getValue() {
15 | return sig.toSignature();
16 | }
17 |
18 | @Override
19 | public void setValue(String value) {
20 | throw new RuntimeException("TODO: What should be done here?");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/exception/InvalidClassException.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.exception;
2 |
3 | public class InvalidClassException extends Exception {
4 | public InvalidClassException(String string) {
5 | super(string);
6 | }
7 |
8 | private static final long serialVersionUID = 11241L;
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractClassPointer.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | /**
4 | * Opcode that points to a class index. This should be named better eventually.
5 | *
6 | * @author Matt
7 | */
8 | public class AbstractClassPointer extends Instruction {
9 | public int classIndex;
10 |
11 | public AbstractClassPointer(OpType type, int opcode, int length, int classIndex) {
12 | super(type, opcode, 1);
13 | this.classIndex = classIndex;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractFieldInstruction.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public class AbstractFieldInstruction extends Instruction {
4 | public int fieldIndex;
5 |
6 | public AbstractFieldInstruction(int opcode, int fieldIndex) {
7 | super(OpType.STACK, opcode, 3);
8 | this.fieldIndex = fieldIndex;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractJump.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public class AbstractJump extends Instruction {
4 | // TODO: Figure out a clean way to automate updating this whenever somebody
5 | // messes with the instructions of the method.
6 | public int jumpIndex;
7 |
8 | public AbstractJump(OpType optype, int opcode, int jumpIndex) {
9 | super(optype, opcode, 1);
10 | this.jumpIndex = jumpIndex;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractLDC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | import me.coley.bmf.ClassNode;
4 | import me.coley.bmf.consts.ConstString;
5 | import me.coley.bmf.consts.ConstUTF8;
6 | import me.coley.bmf.consts.ConstantType;
7 |
8 | public abstract class AbstractLDC extends SingleValueInstruction {
9 | public AbstractLDC(int opcode, int size, int index) {
10 | super(OpType.CONST_POOL, opcode, size, index);
11 | }
12 |
13 | /**
14 | * Get the type of constant the LDC refers to in the given ClassNode's
15 | * constant-pool.
16 | *
17 | * @param node
18 | * @return Type of constant
19 | */
20 | public ConstantType getValueType(ClassNode node) {
21 | return node.getConst(value).type;
22 | }
23 |
24 | /**
25 | * Get the referenced value.
26 | *
27 | * @param node
28 | * @return Referenced value
29 | */
30 | public Object getValue(ClassNode node) {
31 | return node.getConst(value).getValue();
32 | }
33 |
34 | /**
35 | * Used if opcode is LDC or LDC_W
36 | *
37 | * @param node
38 | * @return Referenced value as int
39 | */
40 | public int getInt(ClassNode node) {
41 | return (int) getValue(node);
42 | }
43 |
44 | /**
45 | * Used if opcode is LDC or LDC_W
46 | *
47 | * @param node
48 | * @return Referenced value as float
49 | */
50 | public float getFloat(ClassNode node) {
51 | return (float) getValue(node);
52 | }
53 |
54 | /**
55 | * Used if opcode is LDC or LDC_W
56 | *
57 | * @param node
58 | * @return Referenced value as String
59 | */
60 | public String getString(ClassNode node) {
61 | ConstString cs = (ConstString) node.getConst(value);
62 | ConstUTF8 utf = (ConstUTF8) node.getConst(cs.getValue());
63 | return utf.getValue();
64 | }
65 |
66 | /**
67 | * Used only if opcode is LDC2_W
68 | *
69 | * @param node
70 | * @return Referenced value as double
71 | */
72 | public double getDouble(ClassNode node) {
73 | return (double) getValue(node);
74 | }
75 |
76 | /**
77 | * Used only if opcode is LDC2_W
78 | *
79 | * @param node
80 | * @return Referenced value as long
81 | */
82 | public long getLong(ClassNode node) {
83 | return (long) getValue(node);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractLOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public class AbstractLOAD extends SingleValueInstruction {
4 | public AbstractLOAD(int opcode, int index) {
5 | super(OpType.VARIABLE, opcode, 2, index);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractMethodInstruction.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public class AbstractMethodInstruction extends Instruction {
4 | public int methodIndex;
5 |
6 | public AbstractMethodInstruction(int opcode, int size, int methodIndex) {
7 | super(OpType.STACK, opcode, size);
8 | this.methodIndex = methodIndex;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractRETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | import me.coley.bmf.type.Type;
4 |
5 | public class AbstractRETURN extends Instruction {
6 | public final Type returnType;
7 |
8 | public AbstractRETURN(OpType optype, int opcode, Type returnType) {
9 | super(optype, opcode, 1);
10 | this.returnType = returnType;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/AbstractSTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public class AbstractSTORE extends SingleValueInstruction {
4 | public AbstractSTORE(int opcode, int index) {
5 | super(OpType.VARIABLE, opcode, 2, index);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/OpType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public enum OpType {
4 | ALLOCATION,
5 | ARRAY,
6 | CONST_POOL,
7 | CONST_VALUE,
8 | TYPE_CONVERSION,
9 | FLOW_CONTROL,
10 | MATH,
11 | RETURN,
12 | STACK,
13 | VARIABLE,
14 | OTHER
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/SingleValueInstruction.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn;
2 |
3 | public class SingleValueInstruction extends Instruction {
4 | public T value;
5 |
6 | public SingleValueInstruction(OpType type, int opcode, int length) {
7 | this(type, opcode, length, null);
8 | }
9 |
10 | public SingleValueInstruction(OpType type, int opcode, int length, T value) {
11 | super(type, opcode, length);
12 | this.value = value;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/AALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class AALOAD extends Instruction {
7 | public AALOAD() {
8 | super(OpType.ARRAY, Instruction.AALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/AASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class AASTORE extends Instruction {
7 | public AASTORE() {
8 | super(OpType.ARRAY, Instruction.AASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ACONST_NULL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class ACONST_NULL extends Instruction {
7 | public ACONST_NULL() {
8 | super(OpType.CONST_VALUE, Instruction.ACONST_NULL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLOAD;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class ALOAD extends AbstractLOAD {
7 | public ALOAD(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.ALOAD_0;
14 | else if (index == 1)
15 | return Instruction.ALOAD_1;
16 | else if (index == 2)
17 | return Instruction.ALOAD_2;
18 | else if (index == 3)
19 | return Instruction.ALOAD_3;
20 | else return Instruction.ALOAD;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ANEWARRAY.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractClassPointer;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class ANEWARRAY extends AbstractClassPointer {
8 |
9 | public ANEWARRAY(int classIndex) {
10 | super(OpType.ARRAY, Instruction.ANEWARRAY, 3, classIndex);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ARETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractRETURN;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 | import me.coley.bmf.type.Type;
7 |
8 | public class ARETURN extends AbstractRETURN {
9 | public ARETURN() {
10 | super(OpType.RETURN, Instruction.DRETURN, Type.OBJECT);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ARRAYLENGTH.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class ARRAYLENGTH extends Instruction {
7 | public ARRAYLENGTH() {
8 | super(OpType.ARRAY, Instruction.ARRAYLENGTH, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractSTORE;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class ASTORE extends AbstractSTORE {
7 | public ASTORE(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.ASTORE_0;
14 | else if (index == 1)
15 | return Instruction.ASTORE_1;
16 | else if (index == 2)
17 | return Instruction.ASTORE_2;
18 | else if (index == 3)
19 | return Instruction.ASTORE_3;
20 | else return Instruction.ASTORE;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ATHROW.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class ATHROW extends Instruction {
7 | public ATHROW() {
8 | super(OpType.ARRAY, Instruction.ATHROW, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/BALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class BALOAD extends Instruction {
7 | public BALOAD() {
8 | super(OpType.ARRAY, Instruction.BALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/BASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class BASTORE extends Instruction {
7 | public BASTORE() {
8 | super(OpType.ARRAY, Instruction.BASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/BIPUSH.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 | import me.coley.bmf.insn.SingleValueInstruction;
6 |
7 | public class BIPUSH extends SingleValueInstruction {
8 | public BIPUSH(int value) {
9 | super(OpType.STACK, Instruction.BIPUSH, 2, value);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/BREAKPOINT.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class BREAKPOINT extends Instruction {
7 | public BREAKPOINT() {
8 | super(OpType.OTHER, Instruction.BREAKPOINT, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/CALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class CALOAD extends Instruction {
7 | public CALOAD() {
8 | super(OpType.ARRAY, Instruction.CALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/CASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class CASTORE extends Instruction {
7 | public CASTORE() {
8 | super(OpType.ARRAY, Instruction.CASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/CHECKCAST.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractClassPointer;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class CHECKCAST extends AbstractClassPointer {
8 |
9 | public CHECKCAST(int classIndex) {
10 | super(OpType.TYPE_CONVERSION, Instruction.CHECKCAST, 3, classIndex);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/D2F.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class D2F extends Instruction {
7 | public D2F() {
8 | super(OpType.TYPE_CONVERSION, Instruction.D2F, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/D2I.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class D2I extends Instruction {
7 | public D2I() {
8 | super(OpType.TYPE_CONVERSION, Instruction.D2I, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/D2L.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class D2L extends Instruction {
7 | public D2L() {
8 | super(OpType.TYPE_CONVERSION, Instruction.D2L, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DADD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DADD extends Instruction {
7 | public DADD() {
8 | super(OpType.MATH, Instruction.DADD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DALOAD extends Instruction {
7 | public DALOAD() {
8 | super(OpType.ARRAY, Instruction.DALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DASTORE extends Instruction {
7 | public DASTORE() {
8 | super(OpType.ARRAY, Instruction.DASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DCMPG.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DCMPG extends Instruction {
7 | public DCMPG() {
8 | super(OpType.STACK, Instruction.DCMPG, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DCMPL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DCMPL extends Instruction {
7 | public DCMPL() {
8 | super(OpType.STACK, Instruction.DCMPL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DCONST.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 | import me.coley.bmf.insn.SingleValueInstruction;
6 |
7 | public class DCONST extends SingleValueInstruction {
8 | public DCONST(double value) {
9 | super(OpType.CONST_VALUE, opFromValue((int) Math.round(value)), 1, value);
10 | }
11 |
12 | private static int opFromValue(int value) {
13 | if (value == 0)
14 | return Instruction.DCONST_0;
15 | else return Instruction.DCONST_1;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DDIV.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DDIV extends Instruction {
7 | public DDIV() {
8 | super(OpType.MATH, Instruction.DDIV, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DLOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLOAD;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class DLOAD extends AbstractLOAD {
7 | public DLOAD(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.DLOAD_0;
14 | else if (index == 1)
15 | return Instruction.DLOAD_1;
16 | else if (index == 2)
17 | return Instruction.DLOAD_2;
18 | else if (index == 3)
19 | return Instruction.DLOAD_3;
20 | else return Instruction.DLOAD;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DMUL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DMUL extends Instruction {
7 | public DMUL() {
8 | super(OpType.MATH, Instruction.DMUL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DNEG.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DNEG extends Instruction {
7 | public DNEG() {
8 | super(OpType.MATH, Instruction.DNEG, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DREM.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DREM extends Instruction {
7 | public DREM() {
8 | super(OpType.MATH, Instruction.DREM, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DRETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractRETURN;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 | import me.coley.bmf.type.Type;
7 |
8 | public class DRETURN extends AbstractRETURN {
9 | public DRETURN() {
10 | super(OpType.RETURN, Instruction.DRETURN, Type.DOUBLE);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DSTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractSTORE;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class DSTORE extends AbstractSTORE {
7 | public DSTORE(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.DSTORE_0;
14 | else if (index == 1)
15 | return Instruction.DSTORE_1;
16 | else if (index == 2)
17 | return Instruction.DSTORE_2;
18 | else if (index == 3)
19 | return Instruction.DSTORE_3;
20 | else return Instruction.DSTORE;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DSUB.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DSUB extends Instruction {
7 | public DSUB() {
8 | super(OpType.MATH, Instruction.DSUB, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DUP.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DUP extends Instruction {
7 | public DUP() {
8 | super(OpType.STACK, Instruction.DUP, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DUP2.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DUP2 extends Instruction {
7 | public DUP2() {
8 | super(OpType.STACK, Instruction.DUP2, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DUP2_X1.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DUP2_X1 extends Instruction {
7 | public DUP2_X1() {
8 | super(OpType.STACK, Instruction.DUP2_X1, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DUP2_X2.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DUP2_X2 extends Instruction {
7 | public DUP2_X2() {
8 | super(OpType.STACK, Instruction.DUP2_X2, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DUP_X1.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DUP_X1 extends Instruction {
7 | public DUP_X1() {
8 | super(OpType.STACK, Instruction.DUP_X1, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/DUP_X2.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class DUP_X2 extends Instruction {
7 | public DUP_X2() {
8 | super(OpType.STACK, Instruction.DUP_X2, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/F2D.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class F2D extends Instruction {
7 | public F2D() {
8 | super(OpType.TYPE_CONVERSION, Instruction.F2D, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/F2I.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class F2I extends Instruction {
7 | public F2I() {
8 | super(OpType.TYPE_CONVERSION, Instruction.F2I, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/F2L.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class F2L extends Instruction {
7 | public F2L() {
8 | super(OpType.TYPE_CONVERSION, Instruction.F2L, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FADD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FADD extends Instruction {
7 | public FADD() {
8 | super(OpType.MATH, Instruction.FADD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FALOAD extends Instruction {
7 | public FALOAD() {
8 | super(OpType.ARRAY, Instruction.FALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FASTORE extends Instruction {
7 | public FASTORE() {
8 | super(OpType.ARRAY, Instruction.FASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FCMPG.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FCMPG extends Instruction {
7 | public FCMPG() {
8 | super(OpType.STACK, Instruction.FCMPG, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FCMPL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FCMPL extends Instruction {
7 | public FCMPL() {
8 | super(OpType.STACK, Instruction.FCMPL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FCONST.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 | import me.coley.bmf.insn.SingleValueInstruction;
6 |
7 | public class FCONST extends SingleValueInstruction {
8 | public FCONST(float value) {
9 | super(OpType.CONST_VALUE, opFromValue((int) Math.round(value)), 1, value);
10 | }
11 |
12 | private static int opFromValue(int value) {
13 | if (value == 0)
14 | return Instruction.FCONST_0;
15 | if (value == 1)
16 | return Instruction.FCONST_1;
17 | else return Instruction.FCONST_2;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FDIV.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FDIV extends Instruction {
7 | public FDIV() {
8 | super(OpType.MATH, Instruction.FDIV, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FLOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLOAD;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class FLOAD extends AbstractLOAD {
7 | public FLOAD(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.FLOAD_0;
14 | else if (index == 1)
15 | return Instruction.FLOAD_1;
16 | else if (index == 2)
17 | return Instruction.FLOAD_2;
18 | else if (index == 3)
19 | return Instruction.FLOAD_3;
20 | else return Instruction.FLOAD;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FMUL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FMUL extends Instruction {
7 | public FMUL() {
8 | super(OpType.MATH, Instruction.FMUL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FNEG.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FNEG extends Instruction {
7 | public FNEG() {
8 | super(OpType.MATH, Instruction.FNEG, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FREM.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FREM extends Instruction {
7 | public FREM() {
8 | super(OpType.MATH, Instruction.FREM, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FRETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractRETURN;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 | import me.coley.bmf.type.Type;
7 |
8 | public class FRETURN extends AbstractRETURN {
9 | public FRETURN() {
10 | super(OpType.RETURN, Instruction.FRETURN, Type.FLOAT);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FSTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractSTORE;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class FSTORE extends AbstractSTORE {
7 | public FSTORE(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.FSTORE_0;
14 | else if (index == 1)
15 | return Instruction.FSTORE_1;
16 | else if (index == 2)
17 | return Instruction.FSTORE_2;
18 | else if (index == 3)
19 | return Instruction.FSTORE_3;
20 | else return Instruction.FSTORE;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/FSUB.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class FSUB extends Instruction {
7 | public FSUB() {
8 | super(OpType.MATH, Instruction.FSUB, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/GETFIELD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractFieldInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class GETFIELD extends AbstractFieldInstruction {
7 | public GETFIELD( int fieldIndex) {
8 | super(Instruction.GETFIELD, fieldIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/GETSTATIC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractFieldInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class GETSTATIC extends AbstractFieldInstruction {
7 | public GETSTATIC( int fieldIndex) {
8 | super(Instruction.GETSTATIC, fieldIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/GOTO.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class GOTO extends AbstractJump {
8 | public GOTO(int jumpIndex) {
9 | super(OpType.FLOW_CONTROL, jumpIndex > Short.MAX_VALUE ? Instruction.GOTO_W : Instruction.GOTO, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/I2B.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class I2B extends Instruction {
7 | public I2B() {
8 | super(OpType.TYPE_CONVERSION, Instruction.I2B, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/I2C.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class I2C extends Instruction {
7 | public I2C() {
8 | super(OpType.TYPE_CONVERSION, Instruction.I2C, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/I2D.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class I2D extends Instruction {
7 | public I2D() {
8 | super(OpType.TYPE_CONVERSION, Instruction.I2D, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/I2F.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class I2F extends Instruction {
7 | public I2F() {
8 | super(OpType.TYPE_CONVERSION, Instruction.I2F, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/I2L.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class I2L extends Instruction {
7 | public I2L() {
8 | super(OpType.TYPE_CONVERSION, Instruction.I2L, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/I2S.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class I2S extends Instruction {
7 | public I2S() {
8 | super(OpType.TYPE_CONVERSION, Instruction.I2S, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IADD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IADD extends Instruction {
7 | public IADD() {
8 | super(OpType.MATH, Instruction.IADD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IALOAD extends Instruction {
7 | public IALOAD() {
8 | super(OpType.ARRAY, Instruction.IALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IAND.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IAND extends Instruction {
7 | public IAND() {
8 | super(OpType.MATH, Instruction.IAND, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IASTORE extends Instruction {
7 | public IASTORE() {
8 | super(OpType.ARRAY, Instruction.IASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ICONST.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 | import me.coley.bmf.insn.SingleValueInstruction;
6 |
7 | public class ICONST extends SingleValueInstruction {
8 | public ICONST(int value) {
9 | super(OpType.CONST_VALUE, opFromValue(value), 1, value);
10 | }
11 |
12 | private static int opFromValue(int value) {
13 | if (value == 0)
14 | return Instruction.ICONST_0;
15 | else if (value == 1)
16 | return Instruction.ICONST_1;
17 | else if (value == 2)
18 | return Instruction.ICONST_2;
19 | else if (value == 3)
20 | return Instruction.ICONST_3;
21 | else if (value == 4)
22 | return Instruction.ICONST_4;
23 | else return Instruction.ICONST_5;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IDIV.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IDIV extends Instruction {
7 | public IDIV() {
8 | super(OpType.MATH, Instruction.IDIV, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFEQ.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFEQ extends AbstractJump {
8 | public IFEQ(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFEQ, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFGE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFGE extends AbstractJump {
8 | public IFGE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFGE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFGT.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFGT extends AbstractJump {
8 | public IFGT(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFGT, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFLE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFLE extends AbstractJump {
8 | public IFLE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFLE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFLT.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFLT extends AbstractJump {
8 | public IFLT(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFLT, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFNE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFNE extends AbstractJump {
8 | public IFNE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFNE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFNONNULL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFNONNULL extends AbstractJump {
8 | public IFNONNULL(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFNONNULL, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IFNULL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IFNULL extends AbstractJump {
8 | public IFNULL(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IFNULL, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ACMPEQ.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ACMPEQ extends AbstractJump {
8 | public IF_ACMPEQ(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ACMPEQ, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ACMPNE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ACMPNE extends AbstractJump {
8 | public IF_ACMPNE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ACMPNE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ICMPEQ.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ICMPEQ extends AbstractJump {
8 | public IF_ICMPEQ(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ICMPEQ, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ICMPGE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ICMPGE extends AbstractJump {
8 | public IF_ICMPGE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ICMPGE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ICMPGT.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ICMPGT extends AbstractJump {
8 | public IF_ICMPGT(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ICMPGT, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ICMPLE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ICMPLE extends AbstractJump {
8 | public IF_ICMPLE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ICMPLE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ICMPLT.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ICMPLT extends AbstractJump {
8 | public IF_ICMPLT(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ICMPLT, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IF_ICMPNE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractJump;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class IF_ICMPNE extends AbstractJump {
8 | public IF_ICMPNE(int jumpIndex) {
9 | super(OpType.ARRAY, Instruction.IF_ICMPNE, jumpIndex);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IINC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IINC extends Instruction {
7 | public int index, increment;
8 |
9 | public IINC(int index, int increment) {
10 | super(OpType.VARIABLE, Instruction.IINC, 3);
11 | this.index = index;
12 | this.increment = increment;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ILOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLOAD;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class ILOAD extends AbstractLOAD {
7 | public ILOAD(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.ILOAD_0;
14 | else if (index == 1)
15 | return Instruction.ILOAD_1;
16 | else if (index == 2)
17 | return Instruction.ILOAD_2;
18 | else if (index == 3)
19 | return Instruction.ILOAD_3;
20 | else return Instruction.ILOAD;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IMPDEP1.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IMPDEP1 extends Instruction {
7 | public IMPDEP1() {
8 | super(OpType.OTHER, Instruction.IMPDEP1, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IMPDEP2.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IMPDEP2 extends Instruction {
7 | public IMPDEP2() {
8 | super(OpType.OTHER, Instruction.IMPDEP2, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IMUL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IMUL extends Instruction {
7 | public IMUL() {
8 | super(OpType.MATH, Instruction.IMUL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INEG.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class INEG extends Instruction {
7 | public INEG() {
8 | super(OpType.MATH, Instruction.INEG, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INSTANCEOF.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractClassPointer;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class INSTANCEOF extends AbstractClassPointer {
8 |
9 | public INSTANCEOF(int classIndex) {
10 | super(OpType.TYPE_CONVERSION, Instruction.INSTANCEOF, 3,classIndex);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INVOKEDYNAMIC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class INVOKEDYNAMIC extends Instruction {
7 | public int declaringClass;
8 | public int indyIndex;
9 |
10 | public INVOKEDYNAMIC(int declaringClass) {
11 | super(OpType.STACK, Instruction.INVOKEDYNAMIC, 5);
12 | this.declaringClass = declaringClass;
13 | }
14 |
15 | // For writing:
16 | // byte - opcode
17 | // short - declaringClass
18 | // byte - 0
19 | // byte - 0
20 |
21 | // From javap, pretty sure InvokeDynamic index is based off their place in
22 | // the class file.
23 | // First instance = first Indy
24 | // Last instance = last Indy
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INVOKEINTERFACE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractMethodInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class INVOKEINTERFACE extends AbstractMethodInstruction {
7 | public int argWords;
8 |
9 | public INVOKEINTERFACE(int methodIndex, int argWords, int zero) {
10 | super(Instruction.INVOKEINTERFACE, 7, methodIndex);
11 | this.argWords = argWords;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INVOKESPECIAL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractMethodInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class INVOKESPECIAL extends AbstractMethodInstruction {
7 | public INVOKESPECIAL(int methodIndex) {
8 | super(Instruction.INVOKESPECIAL, 5, methodIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INVOKESTATIC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractMethodInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class INVOKESTATIC extends AbstractMethodInstruction {
7 | public INVOKESTATIC(int methodIndex) {
8 | super(Instruction.INVOKESTATIC, 5, methodIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/INVOKEVIRTUAL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractMethodInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class INVOKEVIRTUAL extends AbstractMethodInstruction {
7 | public INVOKEVIRTUAL(int methodIndex) {
8 | super(Instruction.INVOKEVIRTUAL, 5, methodIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IOR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IOR extends Instruction {
7 | public IOR() {
8 | super(OpType.MATH, Instruction.IOR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IREM.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IREM extends Instruction {
7 | public IREM() {
8 | super(OpType.MATH, Instruction.IREM, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IRETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractRETURN;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 | import me.coley.bmf.type.Type;
7 |
8 | public class IRETURN extends AbstractRETURN {
9 | public IRETURN() {
10 | super(OpType.RETURN, Instruction.IRETURN, Type.INT);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ISHL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class ISHL extends Instruction {
7 | public ISHL() {
8 | super(OpType.MATH, Instruction.ISHL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ISHR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class ISHR extends Instruction {
7 | public ISHR() {
8 | super(OpType.MATH, Instruction.ISHR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ISTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractSTORE;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class ISTORE extends AbstractSTORE {
7 | public ISTORE(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.ISTORE_0;
14 | else if (index == 1)
15 | return Instruction.ISTORE_1;
16 | else if (index == 2)
17 | return Instruction.ISTORE_2;
18 | else if (index == 3)
19 | return Instruction.ISTORE_3;
20 | else return Instruction.ISTORE;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/ISUB.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class ISUB extends Instruction {
7 | public ISUB() {
8 | super(OpType.MATH, Instruction.ISUB, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IUSHR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IUSHR extends Instruction {
7 | public IUSHR() {
8 | super(OpType.MATH, Instruction.IUSHR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/IXOR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class IXOR extends Instruction {
7 | public IXOR() {
8 | super(OpType.MATH, Instruction.IXOR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/L2D.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class L2D extends Instruction {
7 | public L2D() {
8 | super(OpType.TYPE_CONVERSION, Instruction.L2D, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/L2F.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class L2F extends Instruction {
7 | public L2F() {
8 | super(OpType.TYPE_CONVERSION, Instruction.L2F, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/L2I.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class L2I extends Instruction {
7 | public L2I() {
8 | super(OpType.TYPE_CONVERSION, Instruction.L2I, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LADD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LADD extends Instruction {
7 | public LADD() {
8 | super(OpType.MATH, Instruction.LADD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LALOAD extends Instruction {
7 | public LALOAD() {
8 | super(OpType.ARRAY, Instruction.LALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LAND.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LAND extends Instruction {
7 | public LAND() {
8 | super(OpType.MATH, Instruction.LAND, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LASTORE extends Instruction {
7 | public LASTORE() {
8 | super(OpType.ARRAY, Instruction.LASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LCMP.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LCMP extends Instruction {
7 | public LCMP() {
8 | super(OpType.STACK, Instruction.LCMP, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LCONST.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 | import me.coley.bmf.insn.SingleValueInstruction;
6 |
7 | public class LCONST extends SingleValueInstruction {
8 | public LCONST(long value) {
9 | super(OpType.CONST_VALUE, opFromValue((int) value), 1, value);
10 | }
11 |
12 | private static int opFromValue(int value) {
13 | if (value == 0)
14 | return Instruction.LCONST_0;
15 | else return Instruction.LCONST_1;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LDC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLDC;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class LDC extends AbstractLDC {
7 | public LDC(int index) {
8 | super(Instruction.LDC, 2, index);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LDC2_W.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLDC;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class LDC2_W extends AbstractLDC {
7 | public LDC2_W(int index) {
8 | // TODO: Check is size 3 is correct
9 | super(Instruction.LDC_W, 3, index);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LDC_W.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLDC;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class LDC_W extends AbstractLDC {
7 | public LDC_W(int index) {
8 | super(Instruction.LDC_W, 3, index);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LDIV.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LDIV extends Instruction {
7 | public LDIV() {
8 | super(OpType.MATH, Instruction.LDIV, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LLOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractLOAD;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class LLOAD extends AbstractLOAD {
7 | public LLOAD(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.LLOAD_0;
14 | else if (index == 1)
15 | return Instruction.LLOAD_1;
16 | else if (index == 2)
17 | return Instruction.LLOAD_2;
18 | else if (index == 3)
19 | return Instruction.LLOAD_3;
20 | else return Instruction.LLOAD;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LMUL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LMUL extends Instruction {
7 | public LMUL() {
8 | super(OpType.MATH, Instruction.LMUL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LNEG.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LNEG extends Instruction {
7 | public LNEG() {
8 | super(OpType.MATH, Instruction.LNEG, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LOOKUPSWITCH.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.insn.Instruction;
6 | import me.coley.bmf.insn.OpType;
7 |
8 | public class LOOKUPSWITCH extends Instruction {
9 | public int default_offset;
10 | public List offsets;
11 |
12 | public LOOKUPSWITCH(int default_offset, List offsets) {
13 | super(OpType.FLOW_CONTROL, Instruction.LOOKUPSWITCH, 9);
14 | this.default_offset = default_offset;
15 | this.offsets = offsets;
16 | }
17 |
18 | @Override
19 | public int getLength() {
20 | // Padding not included.
21 | // opcode + padding? + default_off + n + ... (key, offset: size 4 each)
22 | return 1 + 8 + (8 * offsets.size());
23 | }
24 |
25 | public static class OffsetPair {
26 | public int key;
27 | public int offset;
28 |
29 | public OffsetPair(int key, int offset) {
30 | this.key = key;
31 | this.offset = offset;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LOR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LOR extends Instruction {
7 | public LOR() {
8 | super(OpType.MATH, Instruction.LOR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LREM.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LREM extends Instruction {
7 | public LREM() {
8 | super(OpType.MATH, Instruction.LREM, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LRETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractRETURN;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 | import me.coley.bmf.type.Type;
7 |
8 | public class LRETURN extends AbstractRETURN {
9 | public LRETURN() {
10 | super(OpType.RETURN, Instruction.LRETURN, Type.LONG);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LSHL.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LSHL extends Instruction {
7 | public LSHL() {
8 | super(OpType.MATH, Instruction.LSHL, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LSHR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LSHR extends Instruction {
7 | public LSHR() {
8 | super(OpType.MATH, Instruction.LSHR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LSTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractSTORE;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class LSTORE extends AbstractSTORE {
7 | public LSTORE(int index) {
8 | super(opFromIndex(index), index);
9 | }
10 |
11 | private static int opFromIndex(int index) {
12 | if (index == 0)
13 | return Instruction.LSTORE_0;
14 | else if (index == 1)
15 | return Instruction.LSTORE_1;
16 | else if (index == 2)
17 | return Instruction.LSTORE_2;
18 | else if (index == 3)
19 | return Instruction.LSTORE_3;
20 | else return Instruction.LSTORE;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LSUB.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LSUB extends Instruction {
7 | public LSUB() {
8 | super(OpType.MATH, Instruction.LSUB, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LUSHR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LUSHR extends Instruction {
7 | public LUSHR() {
8 | super(OpType.MATH, Instruction.LUSHR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/LXOR.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class LXOR extends Instruction {
7 | public LXOR() {
8 | super(OpType.MATH, Instruction.LXOR, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/MONITORENTER.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class MONITORENTER extends Instruction {
7 | public MONITORENTER() {
8 | super(OpType.OTHER, Instruction.MONITORENTER, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/MONITOREXIT.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class MONITOREXIT extends Instruction {
7 | public MONITOREXIT() {
8 | super(OpType.OTHER, Instruction.MONITOREXIT, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/MULTIANEWARRAY.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractClassPointer;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class MULTIANEWARRAY extends AbstractClassPointer {
8 | public int dimensions;
9 |
10 | public MULTIANEWARRAY(int classIndex, int dimensions) {
11 | super(OpType.ARRAY, Instruction.ANEWARRAY, 3, classIndex);
12 | this.dimensions = dimensions;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/NEW.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractClassPointer;
4 | import me.coley.bmf.insn.Instruction;
5 | import me.coley.bmf.insn.OpType;
6 |
7 | public class NEW extends AbstractClassPointer {
8 |
9 | public NEW(int classIndex) {
10 | super(OpType.ALLOCATION, Instruction.NEW, 3,classIndex);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/NEWARRAY.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class NEWARRAY extends Instruction {
7 | //@formatter:off
8 | public static final int TYPE_BOOLEAN = 4;
9 | public static final int TYPE_CHAR = 5;
10 | public static final int TYPE_FLOAT = 6;
11 | public static final int TYPE_DOUBLE = 7;
12 | public static final int TYPE_BYTE = 8;
13 | public static final int TYPE_SHORT = 9;
14 | public static final int TYPE_INT = 10;
15 | public static final int TYPE_LONG = 11;
16 | //@formatter:on
17 | public int type;
18 |
19 | public NEWARRAY(int type) {
20 | super(OpType.ARRAY, Instruction.NEWARRAY, 2);
21 | this.type = type;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/NOP.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class NOP extends Instruction {
7 | public NOP() {
8 | super(OpType.OTHER, Instruction.NOP, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/POP.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class POP extends Instruction {
7 | public POP() {
8 | super(OpType.STACK, Instruction.POP, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/POP2.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class POP2 extends Instruction {
7 | public POP2() {
8 | super(OpType.STACK, Instruction.POP2, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/PUTFIELD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractFieldInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class PUTFIELD extends AbstractFieldInstruction {
7 | public PUTFIELD( int fieldIndex) {
8 | super(Instruction.PUTFIELD, fieldIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/PUTSTATIC.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.AbstractFieldInstruction;
4 | import me.coley.bmf.insn.Instruction;
5 |
6 | public class PUTSTATIC extends AbstractFieldInstruction {
7 | public PUTSTATIC( int fieldIndex) {
8 | super(Instruction.PUTSTATIC, fieldIndex);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/RETURN.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class RETURN extends Instruction {
7 | public RETURN() {
8 | super(OpType.RETURN, Instruction.RETURN, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/SALOAD.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class SALOAD extends Instruction {
7 | public SALOAD() {
8 | super(OpType.ARRAY, Instruction.SALOAD, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/SASTORE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class SASTORE extends Instruction {
7 | public SASTORE() {
8 | super(OpType.ARRAY, Instruction.SASTORE, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/SIPUSH.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 | import me.coley.bmf.insn.SingleValueInstruction;
6 |
7 | public class SIPUSH extends SingleValueInstruction {
8 | public SIPUSH(int value) {
9 | super(OpType.STACK, Instruction.SIPUSH, 3, value);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/SWAP.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class SWAP extends Instruction {
7 | public SWAP() {
8 | super(OpType.STACK, Instruction.SWAP, 1);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/TABLESWITCH.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.insn.Instruction;
6 | import me.coley.bmf.insn.OpType;
7 |
8 | public class TABLESWITCH extends Instruction {
9 | public int default_offset;
10 | public int low;
11 | public int high;
12 | public List offsets;
13 |
14 | public TABLESWITCH(int default_offset, int low, int high, List offsets) {
15 | super(OpType.FLOW_CONTROL, Instruction.TABLESWITCH, 1);
16 | this.default_offset = default_offset;
17 | this.low = low;
18 | this.high = high;
19 | this.offsets = offsets;
20 | }
21 |
22 | @Override
23 | public int getLength() {
24 | // Padding not included.
25 | // opcode + padding? + default_off + low + high + ... (offsets size:4)
26 | return 1 + 12 + (4 * (offsets.size()));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/insn/impl/WIDE.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.insn.impl;
2 |
3 | import me.coley.bmf.insn.Instruction;
4 | import me.coley.bmf.insn.OpType;
5 |
6 | public class WIDE extends Instruction {
7 | private final int nextModifier;
8 |
9 | public WIDE(int opcode, int length, int nextModifier) {
10 | super(OpType.OTHER, Instruction.WIDE, nextModifier);
11 | this.nextModifier = nextModifier;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/mapping/AbstractMapping.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.mapping;
2 |
3 | import me.coley.bmf.util.Box;
4 |
5 | public class AbstractMapping {
6 | public final Box name;
7 |
8 | public AbstractMapping(String name) {
9 | this(new Box(name));
10 | }
11 |
12 | public AbstractMapping(Box name) {
13 | this.name = name;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/mapping/ClassMapping.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.mapping;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.util.Box;
7 |
8 | public class ClassMapping extends AbstractMapping {
9 | private final List members = new ArrayList<>();
10 |
11 | public ClassMapping(String name) {
12 | super(name);
13 | }
14 |
15 | public ClassMapping(Box name) {
16 | super(name);
17 | }
18 |
19 | /**
20 | * Gets a member's mapping by the original name and descriptor.
21 | *
22 | * @param name
23 | * @param desc
24 | * @return
25 | */
26 | public MemberMapping getMemberMapping(String name, String desc) {
27 | for (MemberMapping mm : members) {
28 | if (mm.name.original.equals(name) && mm.desc.original.equals(desc)) {
29 | return mm;
30 | }
31 | }
32 | return null;
33 | }
34 |
35 | /**
36 | * Gets a member's mapping by the current name and descriptor.
37 | *
38 | * @param name
39 | * @param desc
40 | * @return
41 | */
42 | public MemberMapping getMemberMappingWithRenaming(String name, String desc) {
43 | for (MemberMapping mm : members) {
44 | if (mm.name.getValue().equals(name) && mm.desc.toDesc().equals(desc))
45 | return mm;
46 | }
47 | return null;
48 | }
49 |
50 | /**
51 | * Gets the list of members in the class.
52 | *
53 | * @return
54 | */
55 | public List getMembers() {
56 | return members;
57 | }
58 |
59 | /**
60 | * Adds a member to the class. The passed member is replaced with another
61 | * Member instance if the name and descriptor match the stored version.
62 | *
63 | * @param mapping
64 | * @param mm
65 | */
66 | public void addMember(Mapping mapping, MemberMapping mm) {
67 | if (mm instanceof MethodMapping) {
68 | mm = mapping.getMemberInstance(this, mm);
69 | }
70 | members.add(mm);
71 | }
72 |
73 | /**
74 | * Returns a list of members matching the given name. Compares to a member's
75 | * original name rather than current name.
76 | *
77 | * @param name
78 | * @return
79 | */
80 | public List getMembersByOriginalName(String name) {
81 | List list = new ArrayList();
82 | for (MemberMapping mm : members) {
83 | if (mm.name.original.equals(name))
84 | list.add(mm);
85 | }
86 | return list;
87 | }
88 |
89 | /**
90 | * Returns a list of members matching the given name.
91 | *
92 | * @param name
93 | * @return
94 | */
95 | public List getMembersByName(String name) {
96 | List list = new ArrayList();
97 | for (MemberMapping mm : members) {
98 | if (mm.name.getValue().equals(name))
99 | list.add(mm);
100 | }
101 | return list;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/mapping/InnerClassMapping.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.mapping;
2 |
3 | import me.coley.bmf.util.Box;
4 |
5 | public class InnerClassMapping extends ClassMapping {
6 | public InnerClassMapping(Box outer, String inner) {
7 | super(createBox(outer, inner));
8 | }
9 |
10 | private static Box createBox(Box outer, String inner) {
11 | return new InnerClassBox(outer, inner);
12 | }
13 |
14 | public String getInnerSection() {
15 | return ((InnerClassBox) name).inner.getValue();
16 | }
17 |
18 | public static class InnerClassBox extends Box {
19 | private final Box outer;
20 | private Box inner;
21 |
22 | public InnerClassBox(Box outer, String inner) {
23 | super(inner);
24 | this.outer = outer;
25 | this.inner = new Box(trim(inner));
26 | }
27 |
28 | public String getInnerSection() {
29 | return inner.getValue();
30 | }
31 |
32 | @Override
33 | public String getValue() {
34 | String nameOuter = outer.getValue();
35 | String nameInner = inner.getValue();
36 | // If the mapping for the inner contains the outer, it likely looks
37 | // is behaving like the following:
38 | // Outer: com.example.MyClass
39 | // Inner: com.example.MyClass$Inner
40 | // Make sure the output doesn't duplicate prefixes.
41 | if (nameInner.startsWith(nameOuter)) {
42 | int index = nameOuter.length();
43 | nameInner = nameInner.substring(index);
44 | if (nameInner.startsWith("$")) {
45 | nameInner = nameInner.substring(1);
46 | }
47 | }
48 | return nameOuter + "$" + nameInner;
49 | }
50 |
51 | @Override
52 | public void setValue(String value) {
53 | this.inner.setValue(trim(value));
54 | }
55 |
56 | private static String trim(String value) {
57 | int index = value.lastIndexOf("$");
58 | if (index > 0) {
59 | value = value.substring(index + 1);
60 | }
61 | return value;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/mapping/MemberMapping.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.mapping;
2 |
3 | import me.coley.bmf.type.descriptors.MemberDescriptor;
4 | import me.coley.bmf.util.Box;
5 |
6 | public class MemberMapping extends AbstractMapping {
7 | public final MemberDescriptor desc;
8 |
9 | public MemberMapping(String name, MemberDescriptor desc) {
10 | this(new Box(name), desc);
11 | }
12 |
13 | public MemberMapping(Box name, MemberDescriptor desc) {
14 | super(name);
15 | this.desc = desc;
16 | }
17 |
18 | @Override
19 | public String toString() {
20 | return name.getValue() + desc.toDesc();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/mapping/MethodMapping.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.mapping;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.type.descriptors.MemberDescriptor;
7 | import me.coley.bmf.util.Box;
8 |
9 | public class MethodMapping extends MemberMapping {
10 | private final List variables = new ArrayList();
11 |
12 | public MethodMapping(Box name, MemberDescriptor desc) {
13 | super(name, desc);
14 | }
15 |
16 | public void addVariable(Mapping mapping, MemberMapping mm) {
17 | variables.add(mm);
18 | }
19 |
20 | public List getVariables() {
21 | return variables;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/MethodSignature.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | import java.util.List;
4 |
5 | public class MethodSignature extends Signature {
6 | private List parameters;
7 |
8 | public MethodSignature(TypeArgHelper helper, List parameters, SigArg retType) {
9 | this.helper = helper;
10 | this.parameters = parameters;
11 | this.type = retType;
12 | }
13 |
14 | public List getMethodParams() {
15 | return parameters;
16 | }
17 |
18 | @Override
19 | public String toSignature() {
20 | // Build type parameters
21 | StringBuilder strVariables = new StringBuilder();
22 | if (helper != null) {
23 | strVariables.append(helper.toGeneric());
24 | }
25 | // List args
26 | StringBuilder strArgs = new StringBuilder();
27 | if (parameters != null && parameters.size() > 0) {
28 | for (SigArg arg : parameters) {
29 | strArgs.append(arg.toArg());
30 | }
31 | }
32 | // Combine
33 | return strVariables.toString() + "(" + strArgs.toString() + ")" + type.toArg();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArg.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | abstract class SigArg {
4 | abstract String toArg();
5 |
6 | int length() {
7 | return toArg().length();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArgArray.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | public class SigArgArray extends SigArg {
4 | private final SigArg inner;
5 |
6 | SigArgArray(SigArg inner) {
7 | this.inner = inner;
8 | }
9 |
10 | @Override
11 | String toArg() {
12 | return "[" + inner.toArg();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArgClass.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.util.Box;
6 |
7 | public class SigArgClass extends SigArg {
8 | /**
9 | * The class's name
10 | */
11 | private final Box className;
12 | /**
13 | * Generic args of classes with generic types.
14 | */
15 | private final List genericArgs;
16 |
17 | SigArgClass(Box className, List genericArgs) {
18 | this.className = className;
19 | this.genericArgs = genericArgs;
20 | }
21 |
22 | @Override
23 | String toArg() {
24 | if (genericArgs == null) {
25 | return className.getValue() + ";";
26 | } else {
27 | StringBuilder args = new StringBuilder();
28 | for (SigArg arg : genericArgs) {
29 | args.append(arg.toArg());
30 | }
31 | return className.getValue() + "<" + args.toString() + ">;";
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArgClassWithInner.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.mapping.InnerClassMapping;
6 | import me.coley.bmf.util.Box;
7 |
8 | public class SigArgClassWithInner extends SigArg {
9 | /**
10 | * The outer class's name
11 | */
12 | private final Box outer;
13 | /**
14 | * The inner class's name
15 | */
16 | private final InnerClassMapping.InnerClassBox inner;
17 | /**
18 | * Generic args of classes with generic types.
19 | */
20 | private final List genericArgs;
21 |
22 | SigArgClassWithInner(Box outer, InnerClassMapping.InnerClassBox inner, List genericArgs) {
23 | this.outer = outer;
24 | this.inner = inner;
25 | this.genericArgs = genericArgs;
26 | }
27 |
28 | @Override
29 | String toArg() {
30 | // Louter_name.inner_name_section;
31 | StringBuilder builder = new StringBuilder();
32 | builder.append("L" + outer.getValue());
33 | if (genericArgs != null) {
34 | StringBuilder args = new StringBuilder();
35 | for (SigArg arg : genericArgs) {
36 | args.append(arg.toArg());
37 | }
38 | builder.append("<" + args.toString() + ">");
39 | }
40 | builder.append("." + inner.getInnerSection() + ";");
41 | return builder.toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArgGeneric.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | public class SigArgGeneric extends SigArg {
4 | /**
5 | * The name of the generic (T, K, V, etc.)
6 | */
7 | private final String varName;
8 |
9 | SigArgGeneric(String varName) {
10 | this.varName = varName;
11 | }
12 |
13 | @Override
14 | String toArg() {
15 | return "T" + varName + ";";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArgPrimitive.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | public class SigArgPrimitive extends SigArg {
4 | /**
5 | * Primitive desc (I, Z, F, etc.)
6 | */
7 | private final String desc;
8 |
9 | SigArgPrimitive(String desc) {
10 | this.desc = desc;
11 | }
12 |
13 | @Override
14 | String toArg() {
15 | return desc;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/SigArgWild.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | public class SigArgWild extends SigArg {
4 | private final SigArg inner;
5 | private final String wild;
6 |
7 | SigArgWild(String wild, SigArg inner) {
8 | this.wild = wild;
9 | this.inner = inner;
10 | }
11 |
12 | @Override
13 | String toArg() {
14 | String s = wild;
15 | if (inner != null) {
16 | s += inner.toArg();
17 | }
18 | return s;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/TypeArgHelper.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashMap;
5 | import java.util.LinkedHashSet;
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.Set;
9 |
10 | class TypeArgHelper {
11 | private Set keys = new LinkedHashSet<>();
12 | private Map typeVars = null;
13 | private Map> interfaces = null;
14 |
15 | void addType(String name, SigArg arg) {
16 | if (typeVars == null) {
17 | typeVars = new LinkedHashMap<>();
18 | }
19 | typeVars.put(name, arg);
20 | keys.add(name);
21 | }
22 |
23 | void addInterface(String name, SigArg arg) {
24 | if (interfaces == null) {
25 | interfaces = new LinkedHashMap<>();
26 | }
27 | if (!interfaces.containsKey(name)) {
28 | interfaces.put(name, new ArrayList<>());
29 | }
30 | interfaces.get(name).add(arg);
31 | keys.add(name);
32 | }
33 |
34 | public String toGeneric() {
35 | StringBuilder strVariables = new StringBuilder();
36 | if (typeVars == null && interfaces == null) {
37 | return "";
38 | }
39 | strVariables.append("<");
40 | for (String key : keys) {
41 | strVariables.append(key + ":");
42 | if (typeVars != null && typeVars.containsKey(key)) {
43 | strVariables.append(typeVars.get(key).toArg());
44 | }
45 | if (interfaces != null && interfaces.containsKey(key)) {
46 | strVariables.append(":");
47 | for (SigArg inter : interfaces.get(key)) {
48 | strVariables.append(inter.toArg());
49 | }
50 | }
51 | }
52 | strVariables.append(">");
53 | return strVariables.toString();
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/signature/TypeSignature.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.signature;
2 |
3 | import java.util.List;
4 |
5 | public class TypeSignature extends Signature {
6 | private final List interfaces;
7 |
8 | public TypeSignature(SigArg type) {
9 | this(type, null, null);
10 | }
11 |
12 | public TypeSignature(SigArg type, TypeArgHelper helper, List interfaces) {
13 | this.helper = helper;
14 | this.interfaces = interfaces;
15 | this.type = type;
16 | }
17 |
18 | @Override
19 | public String toSignature() {
20 | // Build type parameters
21 | StringBuilder strVariables = new StringBuilder();
22 | if (helper != null) {
23 | strVariables.append(helper.toGeneric());
24 | }
25 | // List interfaces
26 | StringBuilder strInterfaces = new StringBuilder();
27 | if (interfaces != null && interfaces.size() > 0) {
28 | for (SigArg arg : interfaces) {
29 | strInterfaces.append(arg.toArg());
30 | }
31 | }
32 | // Combine
33 | return strVariables.toString() + type.toArg() + strInterfaces.toString();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/ArrayType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type;
2 |
3 | public class ArrayType extends Type {
4 | public final Type itemType;
5 |
6 | public ArrayType(Type itemType) {
7 | super(Sort.ARRAY);
8 | this.itemType = itemType;
9 | }
10 |
11 | public int getDepth() {
12 | int i = 1;
13 | Type next = itemType;
14 | while (next.sort == Sort.ARRAY) {
15 | next = ((ArrayType) next).itemType;
16 | i++;
17 | }
18 | return i;
19 | }
20 |
21 | @Override
22 | public String toDesc() {
23 | return "[" + itemType.toDesc();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/ClassType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type;
2 |
3 | import me.coley.bmf.util.Box;
4 |
5 | public class ClassType extends Type {
6 | public final Box className;
7 |
8 | public ClassType(Box className) {
9 | super(Sort.CLASS);
10 | this.className = className;
11 | }
12 |
13 | @Override
14 | public String toDesc() {
15 | return "L" + className.getValue() + ";";
16 | }
17 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/PrimitiveType.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type;
2 |
3 | public class PrimitiveType extends Type {
4 |
5 | public final String desc;
6 |
7 | public PrimitiveType(int type, String desc) {
8 | super(type);
9 | this.desc = desc;
10 | }
11 |
12 | @Override
13 | public String toDesc() {
14 | return desc;
15 | }
16 |
17 | public String toJavaName() {
18 | switch (desc.charAt(0)) {
19 | case 'B':
20 | return "byte";
21 | case 'C':
22 | return "char";
23 | case 'D':
24 | return "double";
25 | case 'F':
26 | return "float";
27 | case 'I':
28 | return "int";
29 | case 'J':
30 | return "long";
31 | case 'S':
32 | return "short";
33 | case 'Z':
34 | return "boolean";
35 | case 'V':
36 | return "void";
37 | }
38 | return null;
39 | }
40 |
41 | public static PrimitiveType getFromChar(char ch) {
42 | switch (ch) {
43 | case 'B':
44 | return BYTE;
45 | case 'C':
46 | return CHAR;
47 | case 'D':
48 | return DOUBLE;
49 | case 'F':
50 | return FLOAT;
51 | case 'I':
52 | return INT;
53 | case 'J':
54 | return LONG;
55 | case 'S':
56 | return SHORT;
57 | case 'Z':
58 | return BOOLEAN;
59 | case 'V':
60 | return VOID;
61 | }
62 | return null;
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/Sort.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type;
2 |
3 | public class Sort {
4 | public static final int BYTE = 0;
5 | public static final int CHAR = 1;
6 | public static final int DOUBLE = 2;
7 | public static final int FLOAT = 3;
8 | public static final int INT = 4;
9 | public static final int LONG = 5;
10 | public static final int CLASS = 6;
11 | public static final int SHORT = 7;
12 | public static final int BOOLEAN = 8;
13 | public static final int ARRAY = 9;
14 | public static final int VOID = 10;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/Type.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.lang.reflect.Field;
5 | import java.lang.reflect.Method;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import me.coley.bmf.mapping.Mapping;
10 | import me.coley.bmf.type.descriptors.MethodDescriptor;
11 | import me.coley.bmf.type.descriptors.VariableDescriptor;
12 | import me.coley.bmf.util.ImmutableBox;
13 |
14 | public abstract class Type {
15 | public static final PrimitiveType BYTE = new PrimitiveType(Sort.BYTE, "B");
16 | public static final PrimitiveType CHAR = new PrimitiveType(Sort.CHAR, "C");
17 | public static final PrimitiveType DOUBLE = new PrimitiveType(Sort.DOUBLE, "D");
18 | public static final PrimitiveType FLOAT = new PrimitiveType(Sort.FLOAT, "F");
19 | public static final PrimitiveType INT = new PrimitiveType(Sort.INT, "I");
20 | public static final PrimitiveType LONG = new PrimitiveType(Sort.LONG, "J");
21 | public static final PrimitiveType SHORT = new PrimitiveType(Sort.SHORT, "S");
22 | public static final PrimitiveType BOOLEAN = new PrimitiveType(Sort.BOOLEAN, "Z");
23 | public static final PrimitiveType VOID = new PrimitiveType(Sort.VOID, "V");
24 | public static final ClassType OBJECT = new ClassType(new ImmutableBox("Ljava/lang/Object;"));
25 | public final int sort;
26 |
27 | public Type(int sort) {
28 | this.sort = sort;
29 | }
30 |
31 | abstract public String toDesc();
32 |
33 | /**
34 | * Creates a VariableDescriptor given the Mapping source and member
35 | * descriptor. Used for both fields and local variables.
36 | *
37 | * @param mapping
38 | * @param desc
39 | * @return
40 | */
41 | public static VariableDescriptor variable(Mapping mapping, String desc) {
42 | char[] carr = desc.toCharArray();
43 | Type type = null;
44 | int i = 0;
45 | while (true) {
46 | char c = carr[i];
47 | if (c == '[') {
48 | type = readArray(mapping, desc, i + 1);
49 | break;
50 | } else if (c == 'L') {
51 | int len = 1;
52 | while (c != ';') {
53 | c = carr[i + len];
54 | len++;
55 | }
56 | type = (type(mapping, desc, i, len));
57 | break;
58 | } else {
59 | Type prim = readPrim(c);
60 | if (prim != null) {
61 | type = prim;
62 | break;
63 | }
64 | }
65 | i++;
66 | }
67 | return new VariableDescriptor(type);
68 | }
69 |
70 | /**
71 | * Creates a MethodDescriptor given the Mapping source and member
72 | * descriptor.
73 | *
74 | * @param mapping
75 | * @param desc
76 | * @return
77 | */
78 | public static MethodDescriptor method(Mapping mapping, String desc) {
79 | char[] carr = desc.toCharArray();
80 | List types = new ArrayList();
81 | int i = 1;
82 | while (true) {
83 | char c = carr[i];
84 | if (c == ')') {
85 | break;
86 | }
87 | if (c == '[') {
88 | ArrayType array = readArray(mapping, desc, i + 1);
89 | types.add(array);
90 | i += array.toDesc().length() - 1;
91 | } else if (c == 'L') {
92 | int len = 1;
93 | while (c != ';') {
94 | c = carr[i + len];
95 | len++;
96 | }
97 | types.add(type(mapping, desc, i, len));
98 | i += len - 1;
99 | } else {
100 | Type prim = readPrim(c);
101 | if (prim != null) {
102 | types.add(prim);
103 | }
104 | }
105 | i++;
106 | }
107 | return new MethodDescriptor(desc, types, type(mapping, desc.substring(desc.indexOf(')') + 1)));
108 | }
109 |
110 | private static ArrayType readArray(Mapping mapping, String desc, int i) {
111 | char[] carr = desc.toCharArray();
112 | Type type = null;
113 | switch (carr[i]) {
114 | case '[':
115 | type = readArray(mapping, desc, i + 1);
116 | break;
117 | case 'L':
118 | int len = 1;
119 | char c = carr[i];
120 | while (c != ';') {
121 | c = carr[i + len];
122 | len++;
123 | }
124 | type = type(mapping, desc, i, len);
125 | i += len - 1;
126 | break;
127 | }
128 | if (type == null) {
129 | type = readPrim(carr[i]);
130 | }
131 | return new ArrayType(type);
132 | }
133 |
134 | public static Type readPrim(char c) {
135 | switch (c) {
136 | case 'B':
137 | return BYTE;
138 | case 'C':
139 | return CHAR;
140 | case 'D':
141 | return DOUBLE;
142 | case 'F':
143 | return FLOAT;
144 | case 'I':
145 | return INT;
146 | case 'J':
147 | return LONG;
148 | case 'S':
149 | return SHORT;
150 | case 'Z':
151 | return BOOLEAN;
152 | case 'V':
153 | return VOID;
154 | default:
155 | break;
156 | }
157 | return null;
158 | }
159 |
160 | private static Type type(Mapping mapping, String desc) {
161 | if (desc.length() == 1) {
162 | return readPrim(desc.charAt(0));
163 | } else if (desc.charAt(0) == '[') {
164 | return readArray(mapping, desc, 1);
165 | }
166 |
167 | String name = desc.substring(1, desc.length() - 1);
168 | return new ClassType(mapping.getClassName(name));
169 | }
170 |
171 | private static Type type(Mapping mapping, String desc, int i, int len) {
172 | String name = desc.substring(i + 1, (i + len) - 1);
173 | return new ClassType(mapping.getClassName(name));
174 | }
175 |
176 | /**
177 | * Get the type-descriptor from the reflection method.
178 | *
179 | * @param method
180 | * @return
181 | */
182 | public static String getMethodDescriptor(Method method) {
183 | String s = "(";
184 | for (final Class> c : method.getParameterTypes())
185 | s += getDescriptorForClass(c);
186 | s += ')';
187 | return s + getDescriptorForClass(method.getReturnType());
188 | }
189 |
190 | /**
191 | * Get the type-descriptor from the reflection field.
192 | *
193 | * @param field
194 | * @return
195 | */
196 | public static String getFieldDescriptor(Field field) {
197 | return getDescriptorForClass(field.getType());
198 | }
199 |
200 | public static String getConstructorDescriptor(Constructor> m) {
201 | String s = "(";
202 | for (final Class> c : m.getParameterTypes())
203 | s += getDescriptorForClass(c);
204 | s += ')';
205 | return s + "V";
206 | }
207 |
208 | /**
209 | *
211 | * From Stackoverflow
212 | *
213 | * @param c
214 | * @return
215 | */
216 | public static String getDescriptorForClass(final Class> c) {
217 | if (c.isPrimitive()) {
218 | if (c == byte.class)
219 | return "B";
220 | if (c == char.class)
221 | return "C";
222 | if (c == double.class)
223 | return "D";
224 | if (c == float.class)
225 | return "F";
226 | if (c == int.class)
227 | return "I";
228 | if (c == long.class)
229 | return "J";
230 | if (c == short.class)
231 | return "S";
232 | if (c == boolean.class)
233 | return "Z";
234 | if (c == void.class)
235 | return "V";
236 | throw new RuntimeException("Unrecognized primitive " + c);
237 | }
238 | if (c.isArray())
239 | return c.getName().replace('.', '/');
240 | return ('L' + c.getName() + ';').replace('.', '/');
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/descriptors/MemberDescriptor.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type.descriptors;
2 |
3 | public abstract class MemberDescriptor {
4 | public final String original;
5 |
6 | public MemberDescriptor(String original) {
7 | this.original = original;
8 | }
9 |
10 | public abstract String toDesc();
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/descriptors/MethodDescriptor.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type.descriptors;
2 |
3 | import java.util.List;
4 |
5 | import me.coley.bmf.type.Type;
6 |
7 | public class MethodDescriptor extends MemberDescriptor {
8 |
9 | public final List parameters;
10 | public Type returnType;
11 |
12 | public MethodDescriptor(String desc, List parameters, Type returnType) {
13 | super(desc);
14 | this.parameters = parameters;
15 | this.returnType = returnType;
16 | }
17 |
18 | @Override
19 | public String toDesc() {
20 | StringBuilder sb = new StringBuilder();
21 | sb.append("(");
22 | for (Type parameter : parameters) {
23 | sb.append(parameter.toDesc());
24 | }
25 | sb.append(")");
26 | sb.append(returnType.toDesc());
27 | return sb.toString();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/type/descriptors/VariableDescriptor.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.type.descriptors;
2 |
3 | import me.coley.bmf.type.Type;
4 |
5 | public class VariableDescriptor extends MemberDescriptor {
6 | public Type type;
7 |
8 | public VariableDescriptor(Type type) {
9 | super(type.toDesc());
10 | this.type = type;
11 | }
12 |
13 | @Override
14 | public String toDesc() {
15 | return type.toDesc();
16 | }
17 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/Access.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | /**
4 | * A utility for checking and generating object access.
5 | *
6 | * @author Matt
7 | */
8 | public class Access {
9 | // @formatter:off
10 | // Constants
11 | public static final int ABSTRACT = 0x0400;
12 | public static final int ANNOTATION = 0x2000;
13 | public static final int BDIDGE = 0x0040;
14 | public static final int ENUM = 0x4000;
15 | public static final int FINAL = 0x0010;
16 | public static final int INTERFACE = 0x0200;
17 | public static final int NATIVE = 0x0100;
18 | public static final int PRIVATE = 0x0002;
19 | public static final int PROTECTED = 0x0004;
20 | public static final int PUBLIC = 0x0001;
21 | public static final int STATIC = 0x0008;
22 | public static final int STRICT = 0x0800;
23 | public static final int SUPER = 0x0020;
24 | public static final int SYNCHRONIZED = 0x0020;
25 | public static final int SYNTHETIC = 0x1000;
26 | public static final int TRANSIENT = 0x0080;
27 | public static final int VARARGS = 0x0080;
28 | public static final int VOLATILE = 0x0040;
29 | // Access checking
30 | public static boolean isAbstract(int acc){return(acc & ABSTRACT)!=0;}
31 | public static boolean isAnnotation(int acc){return(acc & ANNOTATION)!=0;}
32 | public static boolean isBridge(int acc){return(acc & BDIDGE)!=0;}
33 | public static boolean isEnum(int acc){return(acc & ENUM)!=0;}
34 | public static boolean isFinal(int acc){return(acc & FINAL)!=0;}
35 | public static boolean isInterface(int acc){return(acc & INTERFACE)!=0;}
36 | public static boolean isNative(int acc){return(acc & NATIVE)!=0;}
37 | public static boolean isPrivate(int acc){return(acc & PRIVATE)!=0;}
38 | public static boolean isProtected(int acc){return(acc & PROTECTED)!=0;}
39 | public static boolean isPublic(int acc){return(acc & PUBLIC)!=0;}
40 | public static boolean isStatic(int acc){return(acc & STATIC)!=0;}
41 | public static boolean isStrict(int acc){return(acc & STRICT)!=0;}
42 | public static boolean isSuper(int acc){return(acc & SUPER)!=0;}
43 | public static boolean isSynchronized(int acc){return(acc & SYNCHRONIZED)!=0;}
44 | public static boolean isSynthetic(int acc){return(acc & SYNTHETIC)!=0;}
45 | public static boolean isTransient(int acc){return(acc & TRANSIENT)!=0;}
46 | public static boolean isVarargs(int acc){return(acc & VARARGS)!=0;}
47 | public static boolean isVolatile(int acc){return(acc & VOLATILE)!=0;}
48 | // Access creation
49 | public static int createAccess(int... acArgs) {
50 | int access = 0;
51 | for (int acArg : acArgs) access |= acArg;
52 | return access;
53 | }
54 | public static boolean hasAccess(int access, int... acArgs) {
55 | for (int acArg : acArgs)
56 | if ((access & acArg) == 0) return false;
57 | return true;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/Box.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | /**
4 | * Boxed generic type T
5 | *
6 | * @param
7 | */
8 | public class Box {
9 | public final T original;
10 | private T value;
11 |
12 | public Box(T value) {
13 | this.original = value;
14 | this.value = value;
15 | }
16 |
17 | public T getValue() {
18 | return value;
19 | }
20 |
21 | public void setValue(T value) {
22 | this.value = value;
23 | }
24 |
25 | public static Box string(String s) {
26 | return new Box(s);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/ClassLoadStatus.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | import java.io.InputStream;
4 | import java.lang.reflect.Method;
5 |
6 | public enum ClassLoadStatus {
7 | NOT_IN_JVM, LOAD_TRUE, LOAD_FALSE;
8 |
9 | /**
10 | * System ClassLoader
11 | */
12 | private static final ClassLoader SCL = ClassLoader.getSystemClassLoader();
13 | /**
14 | * System ClassLoader's findLoadedClass method
15 | */
16 | private static final Method SCL_FIND = getClassLoaderMethod("findLoadedClass", String.class);
17 |
18 | /**
19 | * Returns the load status of a class by its name.
20 | *
21 | * @param className
22 | * The internal class name.
23 | * @return ClassLoadStatus.
24 | */
25 | public final static ClassLoadStatus getLoadStatus(String className) {
26 | // Will throw an exception, instantly returning the NOT_IN_JVM constant.
27 | try (InputStream is = ClassLoader.getSystemResourceAsStream(className + ".class")) {
28 | // Cannot be read, not in JVM.
29 | if (is == null) {
30 | return ClassLoadStatus.NOT_IN_JVM;
31 | }
32 | // Invoke, check if exists
33 | Object find = SCL_FIND.invoke(SCL, className);
34 | if (find != null) {
35 | return ClassLoadStatus.LOAD_TRUE;
36 | }
37 | } catch (Exception e) {}
38 | // Exists, but not loaded.
39 | return ClassLoadStatus.LOAD_FALSE;
40 | }
41 |
42 | private final static Method getClassLoaderMethod(String name, Class>... args) {
43 | try {
44 | Method method = ClassLoader.class.getDeclaredMethod(name, args);
45 | method.setAccessible(true);
46 | return method;
47 | } catch (Exception e) {
48 | return null;
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/ConstUtil.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import me.coley.bmf.ClassNode;
7 | import me.coley.bmf.consts.ConstClass;
8 | import me.coley.bmf.consts.ConstUTF8;
9 | import me.coley.bmf.consts.Constant;
10 | import me.coley.bmf.consts.ConstantType;
11 |
12 | public class ConstUtil {
13 |
14 | /**
15 | * Retrieves a string from the constant pool of a given ClassNode.
16 | *
17 | * @param node
18 | * @param index
19 | * @return
20 | */
21 | public static String getUTF8(ClassNode node, int index) {
22 | return ((ConstUTF8) node.getConst(index)).getValue();
23 | }
24 |
25 | /**
26 | * Gets a name from a ConstClass at index i in a given node's constant pool.
27 | *
28 | * @param node
29 | * @param classIndex
30 | * @return
31 | */
32 | public static String getClassName(ClassNode node, int classIndex) {
33 | return ((ConstUTF8) node.getConst(((ConstClass) node.getConst(classIndex)).getValue())).getValue();
34 | }
35 |
36 | /**
37 | * Returns a list of Constants from the given ClassNode of the given type.
38 | *
39 | * @param cn
40 | * @param type
41 | * @return
42 | */
43 | @SuppressWarnings({ "rawtypes", "unchecked" })
44 | public static List getConstants(ClassNode cn, ConstantType type) {
45 | List list = new ArrayList();
46 | for (Constant c : cn.constants) {
47 | if (c == null)
48 | continue;
49 | if (c.type == type)
50 | list.add(c);
51 | }
52 | return (List) list;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/ImmutableBox.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | public class ImmutableBox extends Box {
4 |
5 | public ImmutableBox(T value) {
6 | super(value);
7 | }
8 |
9 | @Override
10 | public void setValue(T value) {
11 | // Should an exception be thrown as feedback?
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/IndexableDataStream.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.DataInputStream;
5 |
6 | /**
7 | * An extension of DataInputStream that allows access to the protected position
8 | * index.
9 | */
10 | public class IndexableDataStream extends DataInputStream {
11 | private PositionExposer exposer;
12 |
13 | public IndexableDataStream(byte[] data) {
14 | super(new PositionExposer(data));
15 | this.exposer = ((PositionExposer) in);
16 | }
17 |
18 | public int getIndex() {
19 | return exposer.getIndex();
20 | }
21 |
22 | public void reset(int len) {
23 | exposer.reset(len);
24 | }
25 |
26 | private static final class PositionExposer extends ByteArrayInputStream {
27 | public PositionExposer(byte[] data) {
28 | super(data);
29 | }
30 |
31 | public void reset(int len) {
32 | pos -= len;
33 | }
34 |
35 | public int getIndex() {
36 | return pos;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/JavaNameSorter.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | import java.util.Comparator;
4 |
5 | public class JavaNameSorter implements Comparator {
6 |
7 | @Override
8 | public int compare(String s1, String s2) {
9 | String[] split1 = s1.split("/");
10 | String[] split2 = s2.split("/");
11 | int l1 = split1.length;
12 | int l2 = split2.length;
13 | int len = Math.min(l1, l2);
14 | for (int i = 0; i < len; i++) {
15 | String p1 = split1[i];
16 | String p2 = split2[i];
17 | if (i == len - 1 && l1 != l2) {
18 | return (l1 > l2) ? -1 : 1;
19 | }
20 | int cmp = p1.compareTo(p2);
21 | if (cmp != 0) {
22 | return cmp;
23 | }
24 | }
25 | return 0;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/Measurable.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | public interface Measurable {
4 | public int getLength();
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/MeasurableUtils.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | import java.util.Collection;
4 |
5 | public class MeasurableUtils {
6 | public static int getLength(Collection extends Measurable> items) {
7 | int i = 0;
8 | for (Measurable m : items) {
9 | i += m.getLength();
10 | }
11 | return i;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/StreamUtil.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.Collection;
7 | import java.util.List;
8 | import java.util.stream.Collectors;
9 | import java.util.stream.Stream;
10 |
11 | import me.coley.bmf.util.IndexableDataStream;
12 | import me.coley.bmf.util.JavaNameSorter;
13 |
14 | public class StreamUtil {
15 | private final static int BUFF_SIZE = (int) Math.pow(128, 2);
16 |
17 | /**
18 | * Creates a DataInputStream from byte[].
19 | *
20 | * @param data
21 | * byte[] to convert to DataInputStream.
22 | * @return
23 | * @throws Exception
24 | */
25 | public static IndexableDataStream fromBytes(byte[] data) {
26 | return new IndexableDataStream(data);
27 | }
28 |
29 | /**
30 | * Reads the bytes from the inputstream into a byte array.
31 | *
32 | * @param is
33 | * InputStream to read from.
34 | * @return
35 | * @throws IOException
36 | * Thrown if the given input stream cannot be read from.
37 | */
38 | public static byte[] fromStream(InputStream is) throws IOException {
39 | try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
40 | int r;
41 | byte[] data = new byte[BUFF_SIZE];
42 | while ((r = is.read(data, 0, data.length)) != -1) {
43 | buffer.write(data, 0, r);
44 | }
45 | buffer.flush();
46 | return buffer.toByteArray();
47 | }
48 | }
49 |
50 | /**
51 | * Sorts the stream of java names.
52 | *
53 | * @param stream
54 | * Stream of names.
55 | * @return
56 | */
57 | public static Stream sortJavaNames(Stream stream) {
58 | return stream.sorted(new JavaNameSorter());
59 | }
60 |
61 | /**
62 | * Creates a list of sorted java names from a given collection.
63 | *
64 | * @param names
65 | * Collection of names.
66 | * @return
67 | */
68 | public static List listOfSortedJavaNames(Collection names) {
69 | return sortJavaNames(names.stream()).collect(Collectors.toList());
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/io/JarUtil.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util.io;
2 |
3 | import java.io.File;
4 | import java.io.FileOutputStream;
5 | import java.io.IOException;
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.function.Consumer;
11 | import java.util.jar.JarEntry;
12 | import java.util.jar.JarFile;
13 | import java.util.jar.JarOutputStream;
14 | import java.util.jar.Manifest;
15 | import java.util.zip.ZipEntry;
16 | import java.util.zip.ZipException;
17 | import java.util.zip.ZipFile;
18 |
19 | import me.coley.bmf.ClassNode;
20 | import me.coley.bmf.ClassWriter;
21 | import me.coley.bmf.util.StreamUtil;
22 |
23 | /**
24 | * A utility class for reading information from jar files.
25 | *
26 | * @author Matt
27 | */
28 | public class JarUtil {
29 | /**
30 | * Manifest entry name.
31 | */
32 | private static final String MANIFEST_ENTRY_NAME = "META-INF/MANIFEST.MF";
33 |
34 | /**
35 | * Reads all classes in a jar file and stores them in a map of byte arrays.
36 | *
37 | * @param file
38 | * @return
39 | * @throws ZipException
40 | * @throws IOException
41 | */
42 | public static Map readJarClasses(File file) throws ZipException, IOException {
43 | return readJar(file, new NameFilter() {
44 | @Override
45 | public boolean matches(String name) {
46 | return name.endsWith(".class");
47 | }
48 |
49 | @Override
50 | public String filterName(String name) {
51 | return name.replace(".class", "");
52 | }
53 | });
54 | }
55 |
56 | /**
57 | * Reads all non-class entries in a jar file and stores them in a map of
58 | * byte arrays.
59 | *
60 | * @param file
61 | * @return
62 | * @throws ZipException
63 | * @throws IOException
64 | */
65 | public static Map readJarNonClasses(File file) throws ZipException, IOException {
66 | return readJar(file, new NameFilter() {
67 | @Override
68 | public boolean matches(String name) {
69 | return !name.endsWith(".class");
70 | }
71 |
72 | @Override
73 | public String filterName(String name) {
74 | return name;
75 | }
76 | });
77 | }
78 |
79 | /**
80 | * Returns a list of entry names based on the given File and NameFilter.
81 | *
82 | * @param file
83 | * @param filter
84 | * @return
85 | * @throws ZipException
86 | * @throws IOException
87 | */
88 | public static List getEntryNames(File file, NameFilter filter) throws ZipException, IOException {
89 | List names = new ArrayList();
90 | ZipFile zip = new ZipFile(file);
91 | zip.stream().forEach(new Consumer() {
92 | @Override
93 | public void accept(ZipEntry entry) {
94 | String name = entry.getName();
95 | if (entry.isDirectory() || !filter.matches(name)) {
96 | return;
97 | }
98 | names.add(filter.filterName(name));
99 | }
100 | });
101 | zip.close();
102 | return names;
103 | }
104 |
105 | /**
106 | * Reads all entries in a jar file and stores them in a map of byte arrays.
107 | * Certain entries may be excluded bases on the NameFilter parameter.
108 | *
109 | * @param file
110 | * @param filter
111 | * @return
112 | * @throws ZipException
113 | * @throws IOException
114 | */
115 | public static Map readJar(File file, NameFilter filter) throws ZipException, IOException {
116 | Map entries = new HashMap<>();
117 | ZipFile zip = new ZipFile(file);
118 | zip.stream().forEach(new Consumer() {
119 | @Override
120 | public void accept(ZipEntry entry) {
121 | String name = entry.getName();
122 | if (entry.isDirectory() || !filter.matches(name)) {
123 | return;
124 | }
125 | try {
126 | entries.put(filter.filterName(name), StreamUtil.fromStream(zip.getInputStream(entry)));
127 | } catch (IOException e) {
128 | e.printStackTrace();
129 | }
130 | }
131 | });
132 | zip.close();
133 | return entries;
134 | }
135 |
136 | /**
137 | * Creates a new jar file given the original file in, the output file
138 | * out, and a map of ClassNodes.
139 | *
140 | * @param in
141 | * @param out
142 | * @param nodes
143 | */
144 | public static void writeJar(File in, File out, Map nodes) {
145 | writeJar(in, out, nodes, null);
146 | }
147 |
148 | /**
149 | * Creates a new jar file given the original file in, the output file
150 | * out, a map of ClassNodes, and a map of non-class entries.
151 | *
152 | *
153 | * @param in
154 | * @param out
155 | * @param nodes
156 | * @param nonClasses
157 | */
158 | public static void writeJar(File in, File out, Map nodes, Map nonClasses) {
159 | try {
160 | FileOutputStream fos = new FileOutputStream(out);
161 | Manifest manifest = getManifest(in);
162 | JarOutputStream jos = manifest != null ? new JarOutputStream(fos, manifest) : new JarOutputStream(fos);
163 | for (ClassNode node : nodes.values()) {
164 | JarEntry entry = new JarEntry(node.getName() + ".class");
165 | entry.setTime(System.currentTimeMillis());
166 | jos.putNextEntry(entry);
167 | jos.write(ClassWriter.write(node));
168 | }
169 | if (nonClasses != null) {
170 | if ((manifest != null) && nonClasses.containsKey(MANIFEST_ENTRY_NAME)) {
171 | nonClasses.remove(MANIFEST_ENTRY_NAME);
172 | }
173 | for (String entryName : nonClasses.keySet()) {
174 | JarEntry entry = new JarEntry(entryName);
175 | entry.setTime(System.currentTimeMillis());
176 | jos.putNextEntry(entry);
177 | jos.write(nonClasses.get(entryName));
178 | }
179 | }
180 | jos.close();
181 | fos.close();
182 | } catch (Exception ex) {
183 | ex.printStackTrace();
184 | }
185 | }
186 |
187 | /**
188 | * Assumes the given file is a jar and retrieves the manifest.
189 | *
190 | * @param in
191 | * @return
192 | * @throws IOException
193 | */
194 | private static Manifest getManifest(File in) throws IOException {
195 | JarFile jar = new JarFile(in);
196 | Manifest manifest = jar.getManifest();
197 | jar.close();
198 | return manifest;
199 | }
200 | }
--------------------------------------------------------------------------------
/src/main/java/me/coley/bmf/util/io/NameFilter.java:
--------------------------------------------------------------------------------
1 | package me.coley.bmf.util.io;
2 |
3 | /**
4 | * Simple filter. Implementations should check for valid input, and optionally
5 | * implement renaming of matched input.
6 | */
7 | public interface NameFilter {
8 | /**
9 | * Determines if a given name is valid.
10 | *
11 | * @param name
12 | * @return
13 | */
14 | public boolean matches(String name);
15 |
16 | /**
17 | * Returns a modified name.
18 | *
19 | * @param name
20 | * @return
21 | */
22 | public default String filterName(String name) {
23 | return name;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------