예제 #1
0
        public static IAttribute ReadAttribute(this ClassReader reader, ConstantPool pool)
        {
            var nameIndex = reader.ReadU2();
            var length    = reader.ReadU4();
            var name      = pool.GetUtf8String(nameIndex);

            if (!Enum.TryParse <AttributeType>(name, true, out var type))
            {
                type = AttributeType.Unparsed;
            }
            switch (type)
            {
            case AttributeType.Deprecated:
                return(new DeprecatedAttribute());

            case AttributeType.Synthetic:
                return(new SyntheticAttribute());

            case AttributeType.SourceFile:
                var fileNameIndex = reader.ReadU2();
                return(new SourceFileAttribute(pool.GetUtf8String(fileNameIndex)));

            case AttributeType.ConstantValue:
                var constantIndex = reader.ReadU2();
                return(new ConstantValueAttribute(pool.GetConstant(constantIndex)));

            case AttributeType.Code:
                ushort stack = reader.ReadU2(), locals = reader.ReadU2();
                var    codelength = reader.ReadU4();
                var    code       = reader.ReadBytes((int)codelength);
                return(new CodeAttribute(stack, locals, code, ReadExceptionTables(reader), ReadAttributes(reader, pool)));

            case AttributeType.Exceptions:
                return(new ExceptionsAttribute(reader.ReadU2S()));

            case AttributeType.LineNumberTable:
                return(new LineNumberTableAttribute(ReadLineNumberTableEntrys(reader)));

            case AttributeType.LocalVariableTable:
                return(new LocalVariableTableAttribute(ReadLocalVariableTableEntrys(reader)));
            }
            return(new UnparsedAttribute(reader.ReadBytes((int)length)));
        }
예제 #2
0
        static void Main(string[] args)
        {
            var jrePath = Environment.GetEnvironmentVariable("JAVA_HOME");
            var entry   = EntryFactory.CreateEntry(Path.Combine(jrePath, "jre", "*"));
            var data    = entry.ReadClass("java.lang.Object");

            Console.WriteLine(data);
            var reader = new ClassReader(data);//@"E:\workcode\zbj\八戒招聘\hr-saas\zbj-zhaopin-admin\zbj-hr-saas-web-manage-ui\target\classes\com\zbj\hr\listener\TaskServlet.class"

            Console.WriteLine("jvm class magic:{0}", reader.ReadU4());
        }
예제 #3
0
 public void ReadAttributeInfo(ClassReader classReader, ConstantPool constantPool)
 {
     this.attributeLength = classReader.ReadU4();
     Read(classReader, constantPool);
 }