From 4f24288e20acbeef69d7c6df2aefbc6e22cb09bb Mon Sep 17 00:00:00 2001 From: Imgaojp Date: Sat, 18 Feb 2017 14:26:07 +0800 Subject: [PATCH] classfile --- src/com/gabongao/jvm/classfile/AttrCode.java | 76 ++++++++++++++ .../jvm/classfile/AttrConstantValue.java | 46 +++++++++ .../jvm/classfile/AttrDeprecated.java | 36 +++++++ .../jvm/classfile/AttrExceptions.java | 46 +++++++++ .../jvm/classfile/AttrLineNumberTable.java | 71 ++++++++++++++ .../jvm/classfile/AttrLocalVariableTable.java | 98 +++++++++++++++++++ .../gabongao/jvm/classfile/AttrMarker.java | 40 ++++++++ .../jvm/classfile/AttrSourceFile.java | 51 ++++++++++ .../gabongao/jvm/classfile/AttrSynthetic.java | 36 +++++++ .../gabongao/jvm/classfile/AttrUnparsed.java | 49 ++++++++++ .../jvm/classfile/ConstantClassInfo.java | 51 ++++++++++ .../jvm/classfile/ConstantFieldrefInfo.java | 39 ++++++++ .../ConstantInterfaceMemberrefInfo.java | 39 ++++++++ .../jvm/classfile/ConstantMemberrefInfo.java | 62 ++++++++++++ .../jvm/classfile/ConstantMethodrefInfo.java | 39 ++++++++ .../classfile/ConstantNameAndTypeInfo.java | 43 ++++++++ .../jvm/classfile/ConstantStringInfo.java | 52 ++++++++++ .../jvm/classfile/ConstantUtf8Info.java | 57 +++++++++++ 18 files changed, 931 insertions(+) create mode 100644 src/com/gabongao/jvm/classfile/AttrCode.java create mode 100644 src/com/gabongao/jvm/classfile/AttrConstantValue.java create mode 100644 src/com/gabongao/jvm/classfile/AttrDeprecated.java create mode 100644 src/com/gabongao/jvm/classfile/AttrExceptions.java create mode 100644 src/com/gabongao/jvm/classfile/AttrLineNumberTable.java create mode 100644 src/com/gabongao/jvm/classfile/AttrLocalVariableTable.java create mode 100644 src/com/gabongao/jvm/classfile/AttrMarker.java create mode 100644 src/com/gabongao/jvm/classfile/AttrSourceFile.java create mode 100644 src/com/gabongao/jvm/classfile/AttrSynthetic.java create mode 100644 src/com/gabongao/jvm/classfile/AttrUnparsed.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantClassInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantFieldrefInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantInterfaceMemberrefInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantMemberrefInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantMethodrefInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantNameAndTypeInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantStringInfo.java create mode 100644 src/com/gabongao/jvm/classfile/ConstantUtf8Info.java diff --git a/src/com/gabongao/jvm/classfile/AttrCode.java b/src/com/gabongao/jvm/classfile/AttrCode.java new file mode 100644 index 0000000..9889a4a --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrCode.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrCode implements AttributeInfo { + char maxStack, maxLocals; + byte[] code; + ConstantPool constantPool; + AttributeInfo[] attributes; + ExceptionTableEntry[] exceptionTableEntries; + + + public AttrCode(ConstantPool constantPool) { + this.constantPool = constantPool; + } + + @Override + public void readInfo(ClassReader classReader) { + maxStack = classReader.readUint16(); + maxLocals = classReader.readUint16(); + int codeLength = classReader.readUint32(); + code = classReader.readBytes(codeLength); + exceptionTableEntries = readExceptionTable(classReader); + attributes = ClassFile.readAttributes(classReader, constantPool); + } + + public ExceptionTableEntry[] readExceptionTable(ClassReader classReader) { + char exceptionTableLength = classReader.readUint16(); + ExceptionTableEntry[] exceptionTableEntries = new ExceptionTableEntry[exceptionTableLength]; + for (int i = 0; i < exceptionTableLength; i++) { + exceptionTableEntries[i] = new ExceptionTableEntry(classReader.readUint16(), classReader.readUint16(), classReader.readUint16(), classReader.readUint16()); + } + return exceptionTableEntries; + } + + class ExceptionTableEntry { + char startPc, endPc, handlerPc, catchType; + + ExceptionTableEntry(char startPc, char endPc, char handlerPc, char catchType) { + this.startPc = startPc; + this.endPc = endPc; + this.handlerPc = handlerPc; + this.catchType = catchType; + } + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrConstantValue.java b/src/com/gabongao/jvm/classfile/AttrConstantValue.java new file mode 100644 index 0000000..730a6bc --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrConstantValue.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrConstantValue implements AttributeInfo { + char constantValueIndex; + + @Override + public void readInfo(ClassReader classReader) { + constantValueIndex = classReader.readUint16(); + } + + public char getConstantValueIndex() { + return constantValueIndex; + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrDeprecated.java b/src/com/gabongao/jvm/classfile/AttrDeprecated.java new file mode 100644 index 0000000..0004b98 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrDeprecated.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrDeprecated extends AttrMarker { +} diff --git a/src/com/gabongao/jvm/classfile/AttrExceptions.java b/src/com/gabongao/jvm/classfile/AttrExceptions.java new file mode 100644 index 0000000..0e50622 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrExceptions.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrExceptions implements AttributeInfo { + char[] exceptionIndexTable; + + @Override + public void readInfo(ClassReader classReader) { + exceptionIndexTable = classReader.readUint16s(); + } + + public char[] getExceptionIndexTable() { + return exceptionIndexTable; + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrLineNumberTable.java b/src/com/gabongao/jvm/classfile/AttrLineNumberTable.java new file mode 100644 index 0000000..c3cb9a2 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrLineNumberTable.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrLineNumberTable implements AttributeInfo { + LineNumberTableEntry[] lineNumberTable; + + @Override + public void readInfo(ClassReader classReader) { + char lineNumberTableLength = classReader.readUint16(); + lineNumberTable = new LineNumberTableEntry[lineNumberTableLength]; + for (int i = 0; i < lineNumberTableLength; i++) { + lineNumberTable[i] = new LineNumberTableEntry(classReader.readUint16(), classReader.readUint16()); + } + } + + class LineNumberTableEntry { + char startPc, lineNumber; + + LineNumberTableEntry(char startPc, char lineNumber) { + this.startPc = startPc; + this.lineNumber = lineNumber; + } + + public char getStartPc() { + return startPc; + } + + public void setStartPc(char startPc) { + this.startPc = startPc; + } + + public char getLineNumber() { + return lineNumber; + } + + public void setLineNumber(char lineNumber) { + this.lineNumber = lineNumber; + } + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrLocalVariableTable.java b/src/com/gabongao/jvm/classfile/AttrLocalVariableTable.java new file mode 100644 index 0000000..66c8ccc --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrLocalVariableTable.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrLocalVariableTable implements AttributeInfo { + LocalVariableTableEntry[] localVariableTable; + + @Override + public void readInfo(ClassReader classReader) { + char localVariableTableLength = classReader.readUint16(); + localVariableTable = new LocalVariableTableEntry[localVariableTableLength]; + for (int i = 0; i < localVariableTableLength; i++) { + localVariableTable[i] = new LocalVariableTableEntry(classReader.readUint16(), classReader.readUint16(), classReader.readUint16(), classReader.readUint16(), classReader.readUint16()); + } + } + + class LocalVariableTableEntry { + char startPc, length, nameIndex, descriptorIndex, index; + + LocalVariableTableEntry(char startPc, char length, char nameIndex, char descriptorIndex, char index) { + this.startPc = startPc; + this.length = length; + this.nameIndex = nameIndex; + this.descriptorIndex = descriptorIndex; + this.index = index; + } + + public char getStartPc() { + return startPc; + } + + public void setStartPc(char startPc) { + this.startPc = startPc; + } + + public char getLength() { + return length; + } + + public void setLength(char length) { + this.length = length; + } + + public char getNameIndex() { + return nameIndex; + } + + public void setNameIndex(char nameIndex) { + this.nameIndex = nameIndex; + } + + public char getDescriptorIndex() { + return descriptorIndex; + } + + public void setDescriptorIndex(char descriptorIndex) { + this.descriptorIndex = descriptorIndex; + } + + public char getIndex() { + return index; + } + + public void setIndex(char index) { + this.index = index; + } + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrMarker.java b/src/com/gabongao/jvm/classfile/AttrMarker.java new file mode 100644 index 0000000..0c29a4b --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrMarker.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrMarker implements AttributeInfo { + @Override + public void readInfo(ClassReader classReader) { + //read nothing + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrSourceFile.java b/src/com/gabongao/jvm/classfile/AttrSourceFile.java new file mode 100644 index 0000000..4ea3feb --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrSourceFile.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrSourceFile implements AttributeInfo { + ConstantPool constantPool; + char sourceFileIndex; + + public AttrSourceFile(ConstantPool constantPool) { + this.constantPool = constantPool; + } + + @Override + public void readInfo(ClassReader classReader) { + sourceFileIndex = classReader.readUint16(); + } + + public String getFileName() { + return constantPool.getUTF8(sourceFileIndex); + } +} diff --git a/src/com/gabongao/jvm/classfile/AttrSynthetic.java b/src/com/gabongao/jvm/classfile/AttrSynthetic.java new file mode 100644 index 0000000..ab853e9 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrSynthetic.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrSynthetic extends AttrMarker { +} diff --git a/src/com/gabongao/jvm/classfile/AttrUnparsed.java b/src/com/gabongao/jvm/classfile/AttrUnparsed.java new file mode 100644 index 0000000..871c853 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/AttrUnparsed.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class AttrUnparsed implements AttributeInfo { + String name; + int length; + byte[] info; + + public AttrUnparsed(String attrName, int attrlen) { + name = attrName; + length = attrlen; + } + + @Override + public void readInfo(ClassReader classReader) { + info = classReader.readBytes(length); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantClassInfo.java b/src/com/gabongao/jvm/classfile/ConstantClassInfo.java new file mode 100644 index 0000000..1edcde4 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantClassInfo.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantClassInfo extends ConstantInfo { + ConstantPool constantPool; + char nameIndex; + + public ConstantClassInfo(ConstantPool constantPool) { + this.constantPool = constantPool; + } + + @Override + public void readInfo(ClassReader classReader) { + nameIndex = classReader.readUint16(); + } + + public String getName() { + return constantPool.getUTF8(nameIndex); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantFieldrefInfo.java b/src/com/gabongao/jvm/classfile/ConstantFieldrefInfo.java new file mode 100644 index 0000000..139ab9d --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantFieldrefInfo.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantFieldrefInfo extends ConstantMemberrefInfo { + public ConstantFieldrefInfo(ConstantPool constantPool) { + super(constantPool); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantInterfaceMemberrefInfo.java b/src/com/gabongao/jvm/classfile/ConstantInterfaceMemberrefInfo.java new file mode 100644 index 0000000..900bec9 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantInterfaceMemberrefInfo.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantInterfaceMemberrefInfo extends ConstantMemberrefInfo { + public ConstantInterfaceMemberrefInfo(ConstantPool constantPool) { + super(constantPool); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantMemberrefInfo.java b/src/com/gabongao/jvm/classfile/ConstantMemberrefInfo.java new file mode 100644 index 0000000..98924e9 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantMemberrefInfo.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantMemberrefInfo extends ConstantInfo { + ConstantPool constantPool; + char classIndex, nameAndTypeIndex; + + public ConstantMemberrefInfo() { + + } + + public ConstantMemberrefInfo(ConstantPool constantPool) { + this.constantPool = constantPool; + } + + @Override + public void readInfo(ClassReader classReader) { + classIndex = classReader.readUint16(); + nameAndTypeIndex = classReader.readUint16(); + } + + public String className() { + return constantPool.getClassName(classIndex); + } + + public String[] nameAndDescriptor() { + return constantPool.getNameAndType(nameAndTypeIndex); + } + + +} diff --git a/src/com/gabongao/jvm/classfile/ConstantMethodrefInfo.java b/src/com/gabongao/jvm/classfile/ConstantMethodrefInfo.java new file mode 100644 index 0000000..7ab4fe1 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantMethodrefInfo.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantMethodrefInfo extends ConstantMemberrefInfo { + public ConstantMethodrefInfo(ConstantPool constantPool) { + super(constantPool); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantNameAndTypeInfo.java b/src/com/gabongao/jvm/classfile/ConstantNameAndTypeInfo.java new file mode 100644 index 0000000..6f5b789 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantNameAndTypeInfo.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantNameAndTypeInfo extends ConstantInfo { + char nameIndex, descriptorIndex; + + @Override + public void readInfo(ClassReader classReader) { + nameIndex = classReader.readUint16(); + descriptorIndex = classReader.readUint16(); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantStringInfo.java b/src/com/gabongao/jvm/classfile/ConstantStringInfo.java new file mode 100644 index 0000000..65391ec --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantStringInfo.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantStringInfo extends ConstantInfo { + private ConstantPool constantPool; + private char stringIndex; + + + public ConstantStringInfo(ConstantPool constantPool) { + this.constantPool = constantPool; + } + + @Override + public void readInfo(ClassReader classReader) { + stringIndex = classReader.readUint16(); + } + + public String getString() { + return constantPool.getUTF8(stringIndex); + } +} diff --git a/src/com/gabongao/jvm/classfile/ConstantUtf8Info.java b/src/com/gabongao/jvm/classfile/ConstantUtf8Info.java new file mode 100644 index 0000000..5b88880 --- /dev/null +++ b/src/com/gabongao/jvm/classfile/ConstantUtf8Info.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.gabongao.jvm.classfile; + +/** + *         ┏┓   ┏┓+ + + *        ┏┛┻━━━┛┻┓ + + + *        ┃       ┃ + *        ┃   ━   ┃ ++ + + + + *        ████━████ ┃+ + *        ┃       ┃ + + *        ┃   ┻   ┃ + *        ┃       ┃ + + + *        ┗━┓   ┏━┛ + *          ┃   ┃ + *          ┃   ┃ + + + + + *          ┃   ┃    Code is far away from bug with the animal protecting + *          ┃   ┃ +     神兽保佑,代码无bug + *          ┃   ┃ + *          ┃   ┃  + + *          ┃    ┗━━━┓ + + + *          ┃        ┣┓ + *          ┃        ┏┛ + *          ┗┓┓┏━┳┓┏┛ + + + + + *           ┃┫┫ ┃┫┫ + *           ┗┻┛ ┗┻┛+ + + + + * Created by Imgaojp on 2017/2/18. + */ +public class ConstantUtf8Info extends ConstantInfo { + private String string; + + @Override + public void readInfo(ClassReader classReader) { + int length = classReader.readUint16(); + byte[] bytes = classReader.readBytes(length); + string = decodeMUTF8(bytes); + } + + private String decodeMUTF8(byte[] bytes) { + try { + return new String(bytes, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public String getString() { + return string; + } +}