/// <summary>
        /// Reads the attribute info
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="javaClass"></param>
        public override void Read(BinaryReader reader, JavaClass javaClass)
        {
            MaxStack  = reader.ReadUInt16();
            MaxLocals = reader.ReadUInt16();

            // Reads the code
            var len = reader.ReadUInt32();

            Code = reader.ReadBytes((int)len);

            // Reads the exception
            var exceptions = reader.ReadUInt16();

            Exceptions = new JavaExceptionTable[exceptions];
            for (int i = 0; i < exceptions; i++)
            {
                Exceptions[i] = JavaExceptionTable.CreateAndRead(reader, javaClass);
            }

            // Reads the attributes
            var attributes = reader.ReadUInt16();

            Attributes = new JavaAttributeInfo[attributes];
            for (int i = 0; i < attributes; i++)
            {
                Attributes[i] = JavaAttributeInfo.CreateAndRead(reader, javaClass);
            }
        }
示例#2
0
        /// <summary>
        /// Reads the method info
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="javaClass"></param>
        public void Read(BinaryReader reader, JavaClass javaClass)
        {
            AccessFlag      = (JavaAccessFlag)reader.ReadUInt16();
            NameIndex       = reader.ReadUInt16();
            DescriptorIndex = reader.ReadUInt16();

            // Reads the attributes
            var attributes = reader.ReadUInt16();

            Attributes = new JavaAttributeInfo[attributes];
            for (int i = 0; i < attributes; i++)
            {
                Attributes[i] = JavaAttributeInfo.CreateAndRead(reader, javaClass);
            }
        }
示例#3
0
        /// <summary>
        /// Reads the class file by the given binary reader.
        /// Remember: This must be an big endian reader!
        /// </summary>
        /// <param name="reader"></param>
        public void Read(BinaryReader reader)
        {
            // Reads the magic number
            var magic = reader.ReadUInt32();

            if (magic != MagicNumber)
            {
                throw new JavaClassMagicNumberException();
            }
            MinorVersion = reader.ReadUInt16();
            MajorVersion = reader.ReadUInt16();

            // Reads the constant pool.
            // The first constnat (0) is always zero.
            // The first valid index is 1.
            var constants = reader.ReadUInt16();

            ConstantPool = new JavaConstantInfo[constants];
            for (int i = 1; i < constants; i++)
            {
                var constant = JavaConstantInfo.CreateAndRead(reader);
                ConstantPool[i] = constant;

                // There is an odd special case for double and long.
                // For some reasons you have to add an empty index
                // if you read an double or long constant.
                if (constant.Type == ConstantInfoType.Double ||
                    constant.Type == ConstantInfoType.Long)
                {
                    i++;
                }
            }

            AccessFlag = (JavaAccessFlag)reader.ReadUInt16();
            ThisClass  = reader.ReadUInt16();
            SuperClass = reader.ReadUInt16();

            // Reads the interfaces
            var interfaces = reader.ReadUInt16();

            Interfaces = new ushort[interfaces];
            for (int i = 0; i < interfaces; i++)
            {
                Interfaces[i] = reader.ReadUInt16();
            }

            // Reads the fields
            var fields = reader.ReadUInt16();

            Fields = new JavaFieldInfo[fields];
            for (int i = 0; i < fields; i++)
            {
                Fields[i] = JavaFieldInfo.CreateAndRead(reader, this);
            }

            // Reads the methods
            var methods = reader.ReadUInt16();

            Methods = new JavaMethodInfo[methods];
            for (int i = 0; i < methods; i++)
            {
                Methods[i] = JavaMethodInfo.CreateAndRead(reader, this);
            }

            // Reads the attributes
            var attributes = reader.ReadUInt16();

            Attributes = new JavaAttributeInfo[attributes];
            for (int i = 0; i < attributes; i++)
            {
                Attributes[i] = JavaAttributeInfo.CreateAndRead(reader, this);
            }
        }