diff --git a/Lycoris b/Lycoris new file mode 160000 index 0000000..8f1a917 --- /dev/null +++ b/Lycoris @@ -0,0 +1 @@ +Subproject commit 8f1a917838204fa3677de3d4de3e6e3b2d7a440e diff --git a/src/main/java/org/momento/lycoris/mixins/mixin/classe/ClassWrapper.java b/src/main/java/org/momento/lycoris/mixins/mixin/classe/ClassWrapper.java index 27921d9..2c10669 100644 --- a/src/main/java/org/momento/lycoris/mixins/mixin/classe/ClassWrapper.java +++ b/src/main/java/org/momento/lycoris/mixins/mixin/classe/ClassWrapper.java @@ -29,6 +29,7 @@ public enum AccessFlag { private char value; + // set up flags reading and their properties AccessFlag(char value) { this.value = value; } @@ -36,7 +37,7 @@ public enum AccessFlag { public char getValue() { return value; } public char setValue(char value) { this.value = value; return value; } - + // map values public static AccessFlag fromValue(final char value) { for (final AccessFlag flag : AccessFlag.values()) { if (flag.getValue() == value) @@ -65,6 +66,7 @@ public void removeAccessFlag(final AccessFlag flag) { } } + // setup decoding attributes to class private final int magic; private final char minorVersion; private final char majorVersion; @@ -106,16 +108,22 @@ public ClassWrapper(final int magic, final char minorVersion, final char majorVe public MethodInfo[] getMethods() { return methods; } public AttributeInfo[] getAttributes() { return attributes; } + + // reading class info header public static ClassWrapper decode(ByteBuffer buffer) { int magic = buffer.getInt(); char minorVersion = buffer.getChar(); char majorVersion = buffer.getChar(); + + // start decoding info ConstantPool[] constantPool = new ConstantPool[buffer.getChar() - 1]; for (int i = 0; i < constantPool.length; ++i) constantPool[i] = ConstantPool.decode(buffer); + AccessFlag flag = AccessFlag.fromValue(buffer.getChar()); char thisClass = buffer.getChar(); char superClass = buffer.getChar(); + char[] interfaces = new char[buffer.getChar()]; for (int i = 0; i < interfaces.length; ++i) interfaces[i] = buffer.getChar(); @@ -128,15 +136,17 @@ public static ClassWrapper decode(ByteBuffer buffer) { AttributeInfo[] attributes = new AttributeInfo[buffer.getChar()]; for (int i = 0; i < attributes.length; ++i) attributes[i] = AttributeInfo.decode(constantPool, buffer); - return new ClassWrapper(magic, minorVersion, majorVersion, constantPool, flag, thisClass, superClass, interfaces, fields, methods, attributes); + + return new ClassWrapper(magic, minorVersion, majorVersion, constantPool, flag, thisClass, superClass, interfaces, fields, methods, attributes); } - + // error edge case public static ClassWrapper decode(Path path) throws IOException { byte[] bytes = Files.readAllBytes(path); ByteBuffer buffer = ByteBuffer.wrap(bytes); return decode(buffer); } + // create and encode to bytebuffer @Override public void encode(ByteBuffer buffer) { buffer.putInt(magic);