Ejemplo n.º 1
0
        public static CodeAttributeParser ParseData(ClassFile cFile, byte[] data)
        {
            int pos = 0;
            CodeAttributeParser res = new CodeAttributeParser();

            res.MaxStack  = Utils.ReadUShort(data, ref pos);
            res.MaxLocals = Utils.ReadUShort(data, ref pos);

            res.CodeLength = Utils.ReadUInt(data, ref pos);
            res.Code       = new byte[res.CodeLength];
            for (int i = 0; i < res.CodeLength; ++i)
            {
                res.Code[i] = data[pos++];
            }

            res.ExceptionTableLength = Utils.ReadUShort(data, ref pos);
            res.ExceptionTable       = new ExceptionTableDescription[res.ExceptionTableLength];
            for (int i = 0; i < res.ExceptionTableLength; ++i)
            {
                res.ExceptionTable[i] = ExceptionTableDescription.ParseData(data, ref pos);
            }

            res.AttributesCount = Utils.ReadUShort(data, ref pos);
            res.Attributes      = new AttributeDescription[res.AttributesCount];
            for (int i = 0; i < res.AttributesCount; ++i)
            {
                res.Attributes[i] = AttributeDescription.ParseData(data, ref pos);
            }

            res.AttributeParsers = AttributeParser.GenerateAttributeMap(cFile, res.Attributes);
            return(res);
        }
Ejemplo n.º 2
0
        public static MethodInfo ParseData(ClassFile cFile, byte[] data, ref int pos)
        {
            MethodInfo res = new MethodInfo();

            res.AccessFlags     = Utils.ReadUShort(data, ref pos);
            res.NameIndex       = Utils.ReadUShort(data, ref pos);
            res.DescriptorIndex = Utils.ReadUShort(data, ref pos);
            res.AttributesCount = Utils.ReadUShort(data, ref pos);
            res.Attributes      = new AttributeDescription[res.AttributesCount];
            for (uint i = 0; i < res.AttributesCount; ++i)
            {
                res.Attributes[i] = AttributeDescription.ParseData(data, ref pos);
            }

            res.AttributeParsers = AttributeParser.GenerateAttributeMap(cFile, res.Attributes);
            return(res);
        }
Ejemplo n.º 3
0
        public static ClassFile ParseClassFile(byte[] data)
        {
            ClassFile res = new ClassFile();
            int       pos = 0;

            for (int i = 0; i < 4; ++i)
            {
                res.Magic[i] = data[pos++];
            }

            res.MinorVersion = Utils.ReadUShort(data, ref pos);
            res.MajorVersion = Utils.ReadUShort(data, ref pos);

            res.ConstantPoolCount = Utils.ReadUShort(data, ref pos);
            res.ConstantPool      = new ConstantPoolDescription[res.ConstantPoolCount - 1];
            for (int i = 0; i < res.ConstantPoolCount - 1; ++i)
            {
                ConstantPoolDescription cpd = ConstantPoolDescription.ParseData(data, ref pos);
                res.ConstantPool[i] = cpd;
                res.INDEX_TO_CONST_MAP.Add(i, cpd);
                if (cpd.Tag == ConstantPoolTag.CONSTANT_Double || cpd.Tag == ConstantPoolTag.CONSTANT_Long)
                {
                    ;
                    ++i;                    // f*****g java
                }
            }

            res.AccessFlags = Utils.ReadUShort(data, ref pos);
            res.ThisClass   = Utils.ReadUShort(data, ref pos);
            res.SuperClass  = Utils.ReadUShort(data, ref pos);

            res.InterfacesCount = Utils.ReadUShort(data, ref pos);
            res.Interfaces      = new ushort[res.InterfacesCount];
            for (int i = 0; i < res.InterfacesCount; ++i)
            {
                res.Interfaces[i] = Utils.ReadUShort(data, ref pos);
            }

            res.FieldsCount = Utils.ReadUShort(data, ref pos);
            res.Fields      = new FieldInfo[res.FieldsCount];
            for (int i = 0; i < res.FieldsCount; ++i)
            {
                res.Fields[i] = FieldInfo.ParseData(res, data, ref pos);
            }

            res.MethodsCount = Utils.ReadUShort(data, ref pos);
            res.Methods      = new MethodInfo[res.MethodsCount];
            for (int i = 0; i < res.MethodsCount; ++i)
            {
                res.Methods[i] = MethodInfo.ParseData(res, data, ref pos);
            }

            res.AttributesCount = Utils.ReadUShort(data, ref pos);
            res.Attributes      = new AttributeDescription[res.AttributesCount];
            for (int i = 0; i < res.AttributesCount; ++i)
            {
                res.Attributes[i] = AttributeDescription.ParseData(data, ref pos);
            }

            res.AttributeParsers = AttributeParser.GenerateAttributeMap(res, res.Attributes);
            return(res);
        }