public static IConstantInfo ReadConstantInfo(this ClassReader reader, ConstantPool pool) { var tag = reader.ReadU1(); var type = (ConstantType)tag; switch (type) { case ConstantType.Class: return(new ClassConstantInfo(pool, reader.ReadU2())); case ConstantType.FieldRef: return(new FieldRefConstantInfo(pool, reader.ReadU2(), reader.ReadU2())); case ConstantType.MethodRef: return(new MethodRefConstantInfo(pool, reader.ReadU2(), reader.ReadU2())); case ConstantType.InterfaceMethodRef: return(new InterfaceMethodRefConstantInfo(pool, reader.ReadU2(), reader.ReadU2())); case ConstantType.String: return(new StringConstantInfo(pool, reader.ReadU2())); case ConstantType.Integer: return(new IntegerConstantInfo(reader.ReadInt())); case ConstantType.Float: return(new FloatConstantInfo(reader.ReadFloat())); case ConstantType.Long: return(new LongConstantInfo(reader.ReadLong())); case ConstantType.Double: return(new DoubleConstantInfo(reader.ReadDouble())); case ConstantType.NameAndType: return(new NameAndTypeConstantInfo(reader.ReadU2(), reader.ReadU2())); case ConstantType.Utf8: return(new Utf8ConstantInfo(reader.ReadUTF())); case ConstantType.MethodHandle: break; case ConstantType.MethodType: break; case ConstantType.InvokeDynamic: break; default: throw new ArgumentOutOfRangeException(); } throw new NotImplementedException(); }
public MemberInfo(ClassReader classReader, ConstantPool constantPool) { this.accessFlag = classReader.ReadU2(); this.nameIndex = classReader.ReadU2(); this.descriptorIndex = classReader.ReadU2(); this.attributesCount = classReader.ReadU2(); this.attributes = new AttributeInfo[this.attributesCount]; for (int i = 0; i < this.attributesCount; i++) { this.attributes[i] = AttributeInfoReader.Read(classReader, constantPool); } }
private static LineNumberTableEntry[] ReadLineNumberTableEntrys(this ClassReader reader) { var count = reader.ReadU2(); var tables = new LineNumberTableEntry[count]; for (var i = 0; i < tables.Length; i++) { tables[i] = new LineNumberTableEntry() { StartPc = reader.ReadU2(), LineNumber = reader.ReadU2() }; } return(tables); }
private static ExceptionTable[] ReadExceptionTables(this ClassReader reader) { var count = reader.ReadU2(); var tables = new ExceptionTable[count]; for (int i = 0; i < tables.Length; i++) { tables[i] = new ExceptionTable() { StartPc = reader.ReadU2(), EndPc = reader.ReadU2(), HandlePc = reader.ReadU2(), CatchType = reader.ReadU2() }; } return(tables); }
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))); }
public static IAttribute[] ReadAttributes(this ClassReader reader, ConstantPool pool) { var count = reader.ReadU2(); var attributes = new IAttribute[count]; for (int i = 0; i < attributes.Length; i++) { attributes[i] = ReadAttribute(reader, pool); } return(attributes); }
public static IConstantInfo[] ReadConstantInfos(this ClassReader reader, ConstantPool pool) { var count = reader.ReadU2(); var infos = new IConstantInfo[count]; for (int i = 1; i < infos.Length; i++) { infos[i] = reader.ReadConstantInfo(pool); if (infos[i].Type == ConstantType.Double || infos[i].Type == ConstantType.Long) { i++; } } return(infos); }
public static AttributeInfo Read(ClassReader classReader, ConstantPool constantPool) { ushort attributeNameIndex = classReader.ReadU2(); string attributeName = Encoding.UTF8.GetString(((ConstantUtf8)constantPool.ConstantPoolInfo[attributeNameIndex]).Bytes); AttributeInfo attributeInfo = null; switch (attributeName) { case "ConstantValue": attributeInfo = new ConstantValue(); break; case "Code": attributeInfo = new Code(); break; case "Deprecated": attributeInfo = new Deprecated(); break; case "LineNumberTable": attributeInfo = new LineNumberTable(); break; case "LocalVariableTable": attributeInfo = new LocalVariableTable(); break; case "SourceFile": attributeInfo = new SourceFile(); break; case "Synthetic": attributeInfo = new Synthetic(); break; case "Exceptions": attributeInfo = new Exceptions(); break; case "Signature": attributeInfo = new Signature(); break; //case "StackMapTable": // attributeInfo = null; default: throw new Exception("no such attribute error"); } attributeInfo.AttributeName = attributeName; attributeInfo.ReadAttributeInfo(classReader, constantPool); return(attributeInfo); }
private static LocalVariableTableEntry[] ReadLocalVariableTableEntrys(this ClassReader reader) { var count = reader.ReadU2(); var tables = new LocalVariableTableEntry[count]; for (var i = 0; i < tables.Length; i++) { tables[i] = new LocalVariableTableEntry() { StartPc = reader.ReadU2(), Length = reader.ReadU2(), NameIndex = reader.ReadU2(), DescriptorIndex = reader.ReadU2(), Index = reader.ReadU2() }; } return(tables); }