public static ConstantPoolDescription ParseData(byte[] data, ref int pos)
        {
            ConstantPoolDescription res = new ConstantPoolDescription();

            res.Tag = (ConstantPoolTag)data[pos++];
            switch (res.Tag)
            {
            case ConstantPoolTag.CONSTANT_Class:
                res.Info = CONSTANT_Class_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_Fieldref:
            case ConstantPoolTag.CONSTANT_Methodref:
            case ConstantPoolTag.CONSTANT_InterfaceMethodref:
                res.Info = CONSTANT_GeneralRef_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_String:
                res.Info = CONSTANT_String_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_Integer:
            case ConstantPoolTag.CONSTANT_Float:
                res.Info = CONSTANT_B4_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_Long:
            case ConstantPoolTag.CONSTANT_Double:
                res.Info = CONSTANT_B8_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_NameAndType:
                res.Info = CONSTANT_NameAndType_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_Utf8:
                res.Info = CONSTANT_Utf8_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_MethodHandle:
                res.Info = CONSTANT_MethodHandle_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_MethodType:
                res.Info = CONSTANT_MethodType_info.ParseData(data, ref pos);
                break;

            case ConstantPoolTag.CONSTANT_InvokeDynamic:
                res.Info = CONSTANT_InvokeDynamic_info.ParseData(data, ref pos);
                break;
            }
            return(res);
        }
示例#2
0
        private static ConstantPoolDescription[] CalcConstantPool(List <ConstantPoolDescription> constantPool)
        {
            int size = constantPool.Count;

            foreach (var constant in constantPool)
            {
                if (constant.Tag == ConstantPoolTag.CONSTANT_Long || constant.Tag == ConstantPoolTag.CONSTANT_Double)
                {
                    ++size;
                }
            }
            var res = new ConstantPoolDescription[size];
            int i   = 0;

            foreach (var constant in constantPool)
            {
                res[i++] = constant;
                if (constant.Tag == ConstantPoolTag.CONSTANT_Long || constant.Tag == ConstantPoolTag.CONSTANT_Double)
                {
                    ++i;
                }
            }
            return(res);
        }
示例#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);
        }