예제 #1
0
        /// <summary>
        /// Creates and reads the field info
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="javaClass"></param>
        /// <returns></returns>
        public static JavaFieldInfo CreateAndRead(BinaryReader reader, JavaClass javaClass)
        {
            var field = new JavaFieldInfo();

            field.Read(reader, javaClass);
            return(field);
        }
예제 #2
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);
            }
        }