public static JavaClass ReadJavaClass(byte[] bytecode)
        {
            BytecodeReader reader = new BytecodeReader(bytecode);

            // ca fe ba be
            uint magic = reader.ReadUInt();

            // Версии
            ushort minorVersion      = reader.ReadUShort();
            ushort majorVersion      = reader.ReadUShort();
            ushort constantPoolCount = reader.ReadUShort();

            ConstantPool constantPool = ReadConstantPool(reader, constantPoolCount);

            ushort accessFlags = reader.ReadUShort();
            // Индекс констанnы class текущего класса в пуле констант
            ushort thisClass       = reader.ReadUShort();
            ushort superClass      = reader.ReadUShort();
            ushort interfacesCount = reader.ReadUShort();

            Interfaces interfaces = ReadInterfaces(reader, interfacesCount, constantPool);

            ushort       fieldsCount = reader.ReadUShort();
            List <Field> fields      = new List <Field>();

            for (int i = 0; i < fieldsCount; i++)
            {
                fields.Add(ReadField(reader, fieldsCount, constantPool));
            }

            ushort        methodsCount = reader.ReadUShort();
            List <Method> methods      = new List <Method>();

            for (short i = 0; i < methodsCount; i++)
            {
                methods.Add(ReadMethod(reader, methodsCount, constantPool));
            }

            ushort attributesCount = reader.ReadUShort();

            Attributes attributes = ReadAttributes(reader, attributesCount, constantPool);

            return(new JavaClass(magic, minorVersion, majorVersion, constantPoolCount, constantPool, accessFlags,
                                 thisClass, superClass, interfacesCount, interfaces, fieldsCount, fields, methodsCount,
                                 methods, attributesCount, attributes));
        }
예제 #2
0
        /// <summary>
        /// Перенос данных из *.class файла в память
        /// </summary>
        /// <param name="bytecode"></param>
        public JavaClass(uint magic, ushort minorVersion, ushort majorVersion, ushort constantPoolCount,
                         ConstantPool constantPool, ushort accessFlags, ushort thisClass, ushort superClass, ushort interfacesCount,
                         Interfaces interfaces, ushort fieldsCount, List <Field> fields, ushort methodsCount,
                         List <Method> methods, ushort attributesCount, Attributes attributes)
        {
            this.magic             = magic;
            this.minorVersion      = minorVersion;
            this.majorVersion      = majorVersion;
            this.constantPoolCount = constantPoolCount;
            this.accessFlags       = accessFlags;
            this.thisClass         = thisClass;
            this.superClass        = superClass;
            this.interfacesCount   = interfacesCount;
            this.interfaces        = interfaces;
            this.fieldsCount       = fieldsCount;
            this.fields            = fields;
            this.methodsCount      = methodsCount;
            this.methods           = methods;
            this.attributesCount   = attributesCount;
            this.attributes        = attributes;

            thisClassName = constantPool.GetConstantUtf8(constantPool.GetConstantClass(thisClass).NameIndex).Value;
        }