コード例 #1
0
        public static IConstantInfo ReadConstantInfo(this ClassReader reader, ConstantPool pool)
        {
            var tag  = reader.ReadU1();
            var type = (ConstantType)tag;

            switch (type)
            {
            case ConstantType.Class:
                return(new ClassConstantInfo(pool, reader.ReadU2()));

            case ConstantType.FieldRef:
                return(new FieldRefConstantInfo(pool, reader.ReadU2(), reader.ReadU2()));

            case ConstantType.MethodRef:
                return(new MethodRefConstantInfo(pool, reader.ReadU2(), reader.ReadU2()));

            case ConstantType.InterfaceMethodRef:
                return(new InterfaceMethodRefConstantInfo(pool, reader.ReadU2(), reader.ReadU2()));

            case ConstantType.String:
                return(new StringConstantInfo(pool, reader.ReadU2()));

            case ConstantType.Integer:
                return(new IntegerConstantInfo(reader.ReadInt()));

            case ConstantType.Float:
                return(new FloatConstantInfo(reader.ReadFloat()));

            case ConstantType.Long:
                return(new LongConstantInfo(reader.ReadLong()));

            case ConstantType.Double:
                return(new DoubleConstantInfo(reader.ReadDouble()));

            case ConstantType.NameAndType:
                return(new NameAndTypeConstantInfo(reader.ReadU2(), reader.ReadU2()));

            case ConstantType.Utf8:
                return(new Utf8ConstantInfo(reader.ReadUTF()));

            case ConstantType.MethodHandle:
                break;

            case ConstantType.MethodType:
                break;

            case ConstantType.InvokeDynamic:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            throw new NotImplementedException();
        }
コード例 #2
0
ファイル: MemberInfo.cs プロジェクト: tinelion/cs_jvm
        public MemberInfo(ClassReader classReader, ConstantPool constantPool)
        {
            this.accessFlag      = classReader.ReadU2();
            this.nameIndex       = classReader.ReadU2();
            this.descriptorIndex = classReader.ReadU2();
            this.attributesCount = classReader.ReadU2();
            this.attributes      = new AttributeInfo[this.attributesCount];

            for (int i = 0; i < this.attributesCount; i++)
            {
                this.attributes[i] = AttributeInfoReader.Read(classReader, constantPool);
            }
        }
コード例 #3
0
ファイル: AttributeFactory.cs プロジェクト: molunshang/JVM
        private static LineNumberTableEntry[] ReadLineNumberTableEntrys(this ClassReader reader)
        {
            var count  = reader.ReadU2();
            var tables = new LineNumberTableEntry[count];

            for (var i = 0; i < tables.Length; i++)
            {
                tables[i] = new LineNumberTableEntry()
                {
                    StartPc    = reader.ReadU2(),
                    LineNumber = reader.ReadU2()
                };
            }
            return(tables);
        }
コード例 #4
0
ファイル: AttributeFactory.cs プロジェクト: molunshang/JVM
        private static ExceptionTable[] ReadExceptionTables(this ClassReader reader)
        {
            var count  = reader.ReadU2();
            var tables = new ExceptionTable[count];

            for (int i = 0; i < tables.Length; i++)
            {
                tables[i] = new ExceptionTable()
                {
                    StartPc   = reader.ReadU2(),
                    EndPc     = reader.ReadU2(),
                    HandlePc  = reader.ReadU2(),
                    CatchType = reader.ReadU2()
                };
            }
            return(tables);
        }
コード例 #5
0
ファイル: AttributeFactory.cs プロジェクト: molunshang/JVM
        public static IAttribute ReadAttribute(this ClassReader reader, ConstantPool pool)
        {
            var nameIndex = reader.ReadU2();
            var length    = reader.ReadU4();
            var name      = pool.GetUtf8String(nameIndex);

            if (!Enum.TryParse <AttributeType>(name, true, out var type))
            {
                type = AttributeType.Unparsed;
            }
            switch (type)
            {
            case AttributeType.Deprecated:
                return(new DeprecatedAttribute());

            case AttributeType.Synthetic:
                return(new SyntheticAttribute());

            case AttributeType.SourceFile:
                var fileNameIndex = reader.ReadU2();
                return(new SourceFileAttribute(pool.GetUtf8String(fileNameIndex)));

            case AttributeType.ConstantValue:
                var constantIndex = reader.ReadU2();
                return(new ConstantValueAttribute(pool.GetConstant(constantIndex)));

            case AttributeType.Code:
                ushort stack = reader.ReadU2(), locals = reader.ReadU2();
                var    codelength = reader.ReadU4();
                var    code       = reader.ReadBytes((int)codelength);
                return(new CodeAttribute(stack, locals, code, ReadExceptionTables(reader), ReadAttributes(reader, pool)));

            case AttributeType.Exceptions:
                return(new ExceptionsAttribute(reader.ReadU2S()));

            case AttributeType.LineNumberTable:
                return(new LineNumberTableAttribute(ReadLineNumberTableEntrys(reader)));

            case AttributeType.LocalVariableTable:
                return(new LocalVariableTableAttribute(ReadLocalVariableTableEntrys(reader)));
            }
            return(new UnparsedAttribute(reader.ReadBytes((int)length)));
        }
コード例 #6
0
ファイル: AttributeFactory.cs プロジェクト: molunshang/JVM
        public static IAttribute[] ReadAttributes(this ClassReader reader, ConstantPool pool)
        {
            var count      = reader.ReadU2();
            var attributes = new IAttribute[count];

            for (int i = 0; i < attributes.Length; i++)
            {
                attributes[i] = ReadAttribute(reader, pool);
            }
            return(attributes);
        }
コード例 #7
0
        public static IConstantInfo[] ReadConstantInfos(this ClassReader reader, ConstantPool pool)
        {
            var count = reader.ReadU2();
            var infos = new IConstantInfo[count];

            for (int i = 1; i < infos.Length; i++)
            {
                infos[i] = reader.ReadConstantInfo(pool);
                if (infos[i].Type == ConstantType.Double || infos[i].Type == ConstantType.Long)
                {
                    i++;
                }
            }
            return(infos);
        }
コード例 #8
0
ファイル: AttributeInfo.cs プロジェクト: tinelion/cs_jvm
        public static AttributeInfo Read(ClassReader classReader, ConstantPool constantPool)
        {
            ushort        attributeNameIndex = classReader.ReadU2();
            string        attributeName      = Encoding.UTF8.GetString(((ConstantUtf8)constantPool.ConstantPoolInfo[attributeNameIndex]).Bytes);
            AttributeInfo attributeInfo      = null;

            switch (attributeName)
            {
            case "ConstantValue":
                attributeInfo = new ConstantValue(); break;

            case "Code":
                attributeInfo = new Code(); break;

            case "Deprecated":
                attributeInfo = new Deprecated(); break;

            case "LineNumberTable":
                attributeInfo = new LineNumberTable(); break;

            case "LocalVariableTable":
                attributeInfo = new LocalVariableTable(); break;

            case "SourceFile":
                attributeInfo = new SourceFile(); break;

            case "Synthetic":
                attributeInfo = new Synthetic(); break;

            case "Exceptions":
                attributeInfo = new Exceptions(); break;

            case "Signature":
                attributeInfo = new Signature(); break;

            //case "StackMapTable":
            //    attributeInfo = null;
            default:
                throw new Exception("no such attribute error");
            }
            attributeInfo.AttributeName = attributeName;
            attributeInfo.ReadAttributeInfo(classReader, constantPool);
            return(attributeInfo);
        }
コード例 #9
0
ファイル: AttributeFactory.cs プロジェクト: molunshang/JVM
        private static LocalVariableTableEntry[] ReadLocalVariableTableEntrys(this ClassReader reader)
        {
            var count  = reader.ReadU2();
            var tables = new LocalVariableTableEntry[count];

            for (var i = 0; i < tables.Length; i++)
            {
                tables[i] = new LocalVariableTableEntry()
                {
                    StartPc         = reader.ReadU2(),
                    Length          = reader.ReadU2(),
                    NameIndex       = reader.ReadU2(),
                    DescriptorIndex = reader.ReadU2(),
                    Index           = reader.ReadU2()
                };
            }
            return(tables);
        }