/// <summary> /// Read a Code attribute /// </summary> private CodeAttribute ReadCodeAttribute(MethodDefinition method, ConstantPool cp) { var maxStack = stream.ReadU2(); var maxLocals = stream.ReadU2(); var codeLength = (int)stream.ReadU4(); var code = new byte[codeLength]; stream.Read(code, 0, codeLength); var result = new CodeAttribute(method, cp, maxStack, maxLocals, code); var ecount = stream.ReadU2(); for (var i = 0; i < ecount; i++) { var startPC = stream.ReadU2(); var endPC = stream.ReadU2(); var handlerPC = stream.ReadU2(); var catchTypeIndex = stream.ReadU2(); var catchType = (catchTypeIndex != 0) ? cp.GetEntry <ConstantPoolClass>(catchTypeIndex).Type : null; result.Add(new ExceptionHandler(result, startPC, endPC, handlerPC, catchType)); } ReadAttributes(cp, result); return(result); }
/// <summary> /// Read a InnerClasses attribute /// </summary> private InnerClassesAttribute ReadInnerClassesAttribute(ConstantPool cp) { var result = new InnerClassesAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var innerClassIndex = stream.ReadU2(); var innerClass = (innerClassIndex != 0) ? cp.GetEntry <ConstantPoolClass>(innerClassIndex).Type : null; var outerClassIndex = stream.ReadU2(); var outerClass = (outerClassIndex != 0) ? cp.GetEntry <ConstantPoolClass>(outerClassIndex).Type : null; var innerNameIndex = stream.ReadU2(); var innerName = (innerNameIndex != 0) ? cp.GetEntry <ConstantPoolUtf8>(innerNameIndex).Value : null; var accessFlags = (NestedClassAccessFlags)stream.ReadU2(); result.Classes.Add(new InnerClass(cp.Loader, innerClass, outerClass, innerName, accessFlags)); } return(result); }
/// <summary> /// Read a LocalVariableTable attribute /// </summary> private LocalVariableTableAttribute ReadLocalVariableTableAttribute(ConstantPool cp) { var result = new LocalVariableTableAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var startPC = stream.ReadU2(); var length = stream.ReadU2(); var nameIndex = stream.ReadU2(); var name = cp.GetEntry <ConstantPoolUtf8>(nameIndex).Value; var descriptorIndex = stream.ReadU2(); var descriptor = cp.GetEntry <ConstantPoolUtf8>(descriptorIndex).Value; var variableType = Descriptors.ParseFieldType(descriptor); var index = stream.ReadU2(); result.Variables.Add(new LocalVariable(startPC, length, name, variableType, index)); } return(result); }
/// <summary> /// Read a Exceptions attribute /// </summary> private ExceptionsAttribute ReadExceptionsAttribute(ConstantPool cp) { var result = new ExceptionsAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var index = stream.ReadU2(); result.Exceptions.Add(cp.GetEntry <ConstantPoolClass>(index).Type); } return(result); }
public override void ProcessFromConstantPool(ConstantPool constantPool) { switch (ReferenceKind) { case ReferenceKindType.GetField: case ReferenceKindType.GetStatic: case ReferenceKindType.PutField: case ReferenceKindType.PutStatic: Reference = constantPool.GetEntry <FieldReferenceEntry>(referenceIndex); break; case ReferenceKindType.InvokeVirtual: case ReferenceKindType.NewInvokeSpecial: Reference = constantPool.GetEntry <MethodReferenceEntry>(referenceIndex); break; case ReferenceKindType.InvokeStatic: case ReferenceKindType.InvokeSpecial: try { Reference = constantPool.GetEntry <MethodReferenceEntry>(referenceIndex); } catch (InvalidCastException) { Reference = constantPool.GetEntry <InterfaceMethodReferenceEntry>(referenceIndex); } break; case ReferenceKindType.InvokeReference: Reference = constantPool.GetEntry <InterfaceMethodReferenceEntry>(referenceIndex); break; default: throw new ArgumentOutOfRangeException(nameof(ReferenceKind)); } }
/// <summary> /// Read the header /// </summary> internal void ReadHeader(ClassFile cf) { var magic = stream.ReadU4(); if (magic != ClassFile.Magic) { throw new Dot42Exception("Invalid magic"); } cf.MinorVersion = stream.ReadU2(); cf.MajorVersion = stream.ReadU2(); var cpCount = stream.ReadU2(); var cp = new ConstantPool(cpCount, cf.Loader); for (var i = 1; i < cpCount; i++) { var tag = (ConstantPoolTags)stream.ReadU1(); ConstantPoolEntry entry; int tmp; switch (tag) { case ConstantPoolTags.Class: entry = new ConstantPoolClass(cp, stream.ReadU2()); break; case ConstantPoolTags.Fieldref: tmp = stream.ReadU2(); entry = new ConstantPoolFieldRef(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.Methodref: tmp = stream.ReadU2(); entry = new ConstantPoolMethodRef(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.InterfaceMethodref: tmp = stream.ReadU2(); entry = new ConstantPoolInterfaceMethodRef(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.String: entry = new ConstantPoolString(cp, stream.ReadU2()); break; case ConstantPoolTags.Integer: entry = new ConstantPoolInteger(cp, stream.ReadS4()); break; case ConstantPoolTags.Float: entry = new ConstantPoolFloat(cp, stream.ReadF4()); break; case ConstantPoolTags.Long: entry = new ConstantPoolLong(cp, stream.ReadS8()); break; case ConstantPoolTags.Double: entry = new ConstantPoolDouble(cp, stream.ReadF8()); break; case ConstantPoolTags.NameAndType: tmp = stream.ReadU2(); entry = new ConstantPoolNameAndType(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.Utf8: tmp = stream.ReadU2(); entry = new ConstantPoolUtf8(cp, stream.ReadUTF8(tmp)); break; default: throw new Dot42Exception("Unknown constant pool tag: " + (int)tag); } cp[i] = entry; if ((tag == ConstantPoolTags.Double) || (tag == ConstantPoolTags.Long)) { i++; } } cf.ClassAccessFlags = (ClassAccessFlags)stream.ReadU2(); var index = stream.ReadU2(); cf.ClassName = cp.GetEntry <ConstantPoolClass>(index).Name; index = stream.ReadU2(); cf.SuperClass = (index == 0) ? null : new ObjectTypeReference(cp.GetEntry <ConstantPoolClass>(index).Name, null); // Interfaces var icount = stream.ReadU2(); var interfaces = new string[icount]; for (var i = 0; i < icount; i++) { index = stream.ReadU2(); interfaces[i] = cp.GetEntry <ConstantPoolClass>(index).Name; } cf.Interfaces = interfaces.Select(x => new ObjectTypeReference(x, null)).ToArray(); // Fields var fcount = stream.ReadU2(); for (var i = 0; i < fcount; i++) { var accessFlags = (FieldAccessFlags)stream.ReadU2(); var nameIndex = stream.ReadU2(); var descriptorIndex = stream.ReadU2(); var name = cp.GetEntry <ConstantPoolUtf8>(nameIndex).Value; var descriptor = cp.GetEntry <ConstantPoolUtf8>(descriptorIndex).Value; var field = new FieldDefinition(cf, accessFlags, name, descriptor, null); ReadAttributes(cp, field); cf.Fields.Add(field); } // Methods var mcount = stream.ReadU2(); for (var i = 0; i < mcount; i++) { var accessFlags = (MethodAccessFlags)stream.ReadU2(); var nameIndex = stream.ReadU2(); var descriptorIndex = stream.ReadU2(); var name = cp.GetEntry <ConstantPoolUtf8>(nameIndex).Value; var descriptor = cp.GetEntry <ConstantPoolUtf8>(descriptorIndex).Value; var method = new MethodDefinition(cf, accessFlags, name, descriptor, null); ReadAttributes(cp, method); cf.Methods.Add(method); } // Attributes ReadAttributes(cp, cf); }
/// <summary> /// Read a list of attributes /// </summary> private void ReadAttributes(ConstantPool cp, IModifiableAttributeProvider provider) { var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var nameIndex = stream.ReadU2(); var name = cp.GetEntry <ConstantPoolUtf8>(nameIndex).Value; var length = stream.ReadU4(); Attribute attr; int tmp; switch (name) { case CodeAttribute.AttributeName: attr = ReadCodeAttribute((MethodDefinition)provider, cp); break; case ConstantValueAttribute.AttributeName: tmp = stream.ReadU2(); attr = new ConstantValueAttribute(((IConstantPoolValue)cp[tmp]).Value); break; case ExceptionsAttribute.AttributeName: attr = ReadExceptionsAttribute(cp); break; case InnerClassesAttribute.AttributeName: attr = ReadInnerClassesAttribute(cp); break; case SyntheticAttribute.AttributeName: attr = new SyntheticAttribute(); break; case SourceFileAttribute.AttributeName: tmp = stream.ReadU2(); attr = new SourceFileAttribute(cp.GetEntry <ConstantPoolUtf8>(tmp).Value); break; case LineNumberTableAttribute.AttributeName: attr = ReadLineNumberTableAttribute(); break; case LocalVariableTableAttribute.AttributeName: attr = ReadLocalVariableTableAttribute(cp); break; case DeprecatedAttribute.AttributeName: attr = new DeprecatedAttribute(); break; case OverrideAttribute.AttributeName: attr = new OverrideAttribute(); break; case SignatureAttribute.AttributeName: tmp = stream.ReadU2(); attr = new SignatureAttribute(cp.GetEntry <ConstantPoolUtf8>(tmp).Value); break; case RuntimeVisibleAnnotationsAttribute.AttributeName: attr = new RuntimeVisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeInvisibleAnnotationsAttribute.AttributeName: attr = new RuntimeInvisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeVisibleParameterAnnotationsAttribute.AttributeName: attr = new RuntimeVisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeInvisibleParameterAnnotationsAttribute.AttributeName: attr = new RuntimeInvisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case AnnotationDefaultAttribute.AttributeName: attr = new AnnotationDefaultAttribute(ReadElementValue(cp)); break; default: stream.Skip(length); attr = new UnknownAttribute(name); break; } provider.Add(attr); } provider.AttributesLoaded(); }
/// <summary> /// Gets the containing pool /// </summary> protected T GetEntry <T>(int index) where T : ConstantPoolEntry { return(constantPool.GetEntry <T>(index)); }
/// <summary> /// Read a LocalVariableTable attribute /// </summary> private LocalVariableTableAttribute ReadLocalVariableTableAttribute(ConstantPool cp) { var result = new LocalVariableTableAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var startPC = stream.ReadU2(); var length = stream.ReadU2(); var nameIndex = stream.ReadU2(); var name = cp.GetEntry<ConstantPoolUtf8>(nameIndex).Value; var descriptorIndex = stream.ReadU2(); var descriptor = cp.GetEntry<ConstantPoolUtf8>(descriptorIndex).Value; var variableType = Descriptors.ParseFieldType(descriptor); var index = stream.ReadU2(); result.Variables.Add(new LocalVariable(startPC, length, name, variableType, index)); } return result; }
/// <summary> /// Read a InnerClasses attribute /// </summary> private InnerClassesAttribute ReadInnerClassesAttribute(ConstantPool cp) { var result = new InnerClassesAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var innerClassIndex = stream.ReadU2(); var innerClass = (innerClassIndex != 0) ? cp.GetEntry<ConstantPoolClass>(innerClassIndex).Type : null; var outerClassIndex = stream.ReadU2(); var outerClass = (outerClassIndex != 0) ? cp.GetEntry<ConstantPoolClass>(outerClassIndex).Type : null; var innerNameIndex = stream.ReadU2(); var innerName = (innerNameIndex != 0) ? cp.GetEntry<ConstantPoolUtf8>(innerNameIndex).Value : null; var accessFlags = (NestedClassAccessFlags)stream.ReadU2(); result.Classes.Add(new InnerClass(cp.Loader, innerClass, outerClass, innerName, accessFlags)); } return result; }
/// <summary> /// Read a Exceptions attribute /// </summary> private ExceptionsAttribute ReadExceptionsAttribute(ConstantPool cp) { var result = new ExceptionsAttribute(); var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var index = stream.ReadU2(); result.Exceptions.Add(cp.GetEntry<ConstantPoolClass>(index).Type); } return result; }
/// <summary> /// Read the header /// </summary> internal void ReadHeader(ClassFile cf) { var magic = stream.ReadU4(); if (magic != ClassFile.Magic) throw new Dot42Exception("Invalid magic"); cf.MinorVersion = stream.ReadU2(); cf.MajorVersion = stream.ReadU2(); var cpCount = stream.ReadU2(); var cp = new ConstantPool(cpCount, cf.Loader); for (var i = 1; i < cpCount; i++) { var tag = (ConstantPoolTags) stream.ReadU1(); ConstantPoolEntry entry; int tmp; switch (tag) { case ConstantPoolTags.Class: entry = new ConstantPoolClass(cp, stream.ReadU2()); break; case ConstantPoolTags.Fieldref: tmp = stream.ReadU2(); entry = new ConstantPoolFieldRef(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.Methodref: tmp = stream.ReadU2(); entry = new ConstantPoolMethodRef(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.InterfaceMethodref: tmp = stream.ReadU2(); entry = new ConstantPoolInterfaceMethodRef(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.String: entry = new ConstantPoolString(cp, stream.ReadU2()); break; case ConstantPoolTags.Integer: entry = new ConstantPoolInteger(cp, stream.ReadS4()); break; case ConstantPoolTags.Float: entry = new ConstantPoolFloat(cp, stream.ReadF4()); break; case ConstantPoolTags.Long: entry = new ConstantPoolLong(cp, stream.ReadS8()); break; case ConstantPoolTags.Double: entry = new ConstantPoolDouble(cp, stream.ReadF8()); break; case ConstantPoolTags.NameAndType: tmp = stream.ReadU2(); entry = new ConstantPoolNameAndType(cp, tmp, stream.ReadU2()); break; case ConstantPoolTags.Utf8: tmp = stream.ReadU2(); entry = new ConstantPoolUtf8(cp, stream.ReadUTF8(tmp)); break; default: throw new Dot42Exception("Unknown constant pool tag: " + (int)tag); } cp[i] = entry; if ((tag == ConstantPoolTags.Double) || (tag == ConstantPoolTags.Long)) i++; } cf.ClassAccessFlags = (ClassAccessFlags) stream.ReadU2(); var index = stream.ReadU2(); cf.ClassName = cp.GetEntry<ConstantPoolClass>(index).Name; index = stream.ReadU2(); cf.SuperClass = (index == 0) ? null : new ObjectTypeReference(cp.GetEntry<ConstantPoolClass>(index).Name, null); // Interfaces var icount = stream.ReadU2(); var interfaces = new string[icount]; for (var i = 0; i < icount; i++) { index = stream.ReadU2(); interfaces[i] = cp.GetEntry<ConstantPoolClass>(index).Name; } cf.Interfaces = interfaces.Select(x => new ObjectTypeReference(x, null)).ToArray(); // Fields var fcount = stream.ReadU2(); for (var i = 0; i < fcount; i++) { var accessFlags = (FieldAccessFlags) stream.ReadU2(); var nameIndex = stream.ReadU2(); var descriptorIndex = stream.ReadU2(); var name = cp.GetEntry<ConstantPoolUtf8>(nameIndex).Value; var descriptor = cp.GetEntry<ConstantPoolUtf8>(descriptorIndex).Value; var field = new FieldDefinition(cf, accessFlags, name, descriptor, null); ReadAttributes(cp, field); cf.Fields.Add(field); } // Methods var mcount = stream.ReadU2(); for (var i = 0; i < mcount; i++) { var accessFlags = (MethodAccessFlags)stream.ReadU2(); var nameIndex = stream.ReadU2(); var descriptorIndex = stream.ReadU2(); var name = cp.GetEntry<ConstantPoolUtf8>(nameIndex).Value; var descriptor = cp.GetEntry<ConstantPoolUtf8>(descriptorIndex).Value; var method = new MethodDefinition(cf, accessFlags, name, descriptor, null); ReadAttributes(cp, method); cf.Methods.Add(method); } // Attributes ReadAttributes(cp, cf); }
/// <summary> /// Read a Code attribute /// </summary> private CodeAttribute ReadCodeAttribute(MethodDefinition method, ConstantPool cp) { var maxStack = stream.ReadU2(); var maxLocals = stream.ReadU2(); var codeLength = (int)stream.ReadU4(); var code = new byte[codeLength]; stream.Read(code, 0, codeLength); var result = new CodeAttribute(method, cp, maxStack, maxLocals, code); var ecount = stream.ReadU2(); for (var i = 0; i < ecount; i++) { var startPC = stream.ReadU2(); var endPC = stream.ReadU2(); var handlerPC = stream.ReadU2(); var catchTypeIndex = stream.ReadU2(); var catchType = (catchTypeIndex != 0) ? cp.GetEntry<ConstantPoolClass>(catchTypeIndex).Type : null; result.Add(new ExceptionHandler(result, startPC, endPC, handlerPC, catchType)); } ReadAttributes(cp, result); return result; }
/// <summary> /// Read a list of attributes /// </summary> private void ReadAttributes(ConstantPool cp, IModifiableAttributeProvider provider) { var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var nameIndex = stream.ReadU2(); var name = cp.GetEntry<ConstantPoolUtf8>(nameIndex).Value; var length = stream.ReadU4(); Attribute attr; int tmp; switch (name) { case CodeAttribute.AttributeName: attr = ReadCodeAttribute((MethodDefinition)provider, cp); break; case ConstantValueAttribute.AttributeName: tmp = stream.ReadU2(); attr = new ConstantValueAttribute(((IConstantPoolValue)cp[tmp]).Value); break; case ExceptionsAttribute.AttributeName: attr = ReadExceptionsAttribute(cp); break; case InnerClassesAttribute.AttributeName: attr = ReadInnerClassesAttribute(cp); break; case SyntheticAttribute.AttributeName: attr = new SyntheticAttribute(); break; case SourceFileAttribute.AttributeName: tmp = stream.ReadU2(); attr = new SourceFileAttribute(cp.GetEntry<ConstantPoolUtf8>(tmp).Value); break; case LineNumberTableAttribute.AttributeName: attr = ReadLineNumberTableAttribute(); break; case LocalVariableTableAttribute.AttributeName: attr = ReadLocalVariableTableAttribute(cp); break; case DeprecatedAttribute.AttributeName: attr = new DeprecatedAttribute(); break; case OverrideAttribute.AttributeName: attr = new OverrideAttribute(); break; case SignatureAttribute.AttributeName: tmp = stream.ReadU2(); attr = new SignatureAttribute(cp.GetEntry<ConstantPoolUtf8>(tmp).Value); break; case RuntimeVisibleAnnotationsAttribute.AttributeName: attr = new RuntimeVisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeInvisibleAnnotationsAttribute.AttributeName: attr = new RuntimeInvisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeVisibleParameterAnnotationsAttribute.AttributeName: attr = new RuntimeVisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeInvisibleParameterAnnotationsAttribute.AttributeName: attr = new RuntimeInvisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case AnnotationDefaultAttribute.AttributeName: attr = new AnnotationDefaultAttribute(ReadElementValue(cp)); break; default: stream.Skip(length); attr = new UnknownAttribute(name); break; } provider.Add(attr); } provider.AttributesLoaded(); }
public override void ProcessFromConstantPool(ConstantPool constantPool) { Descriptor = constantPool.GetEntry <Utf8Entry>(descriptorIndex); }
public override void ProcessFromConstantPool(ConstantPool constantPool) { Name = constantPool.GetEntry <Utf8Entry>(nameIndex); }
/// <summary> /// Parse the entire byte array into instructions. /// </summary> private List <Instruction> Parse() { var instructions = new List <Instruction>(); for (var offset = 0; offset < code.Length;) { var startOffset = offset; var opcode = (Code)code[offset++]; object operand = null; object operand2 = null; switch (opcode) { case Code.AALOAD: case Code.AASTORE: case Code.ACONST_NULL: case Code.ARETURN: case Code.ARRAYLENGTH: case Code.ATHROW: case Code.BALOAD: case Code.BASTORE: case Code.CALOAD: case Code.CASTORE: case Code.D2F: case Code.D2I: case Code.D2L: case Code.DADD: case Code.DALOAD: case Code.DASTORE: case Code.DCMPG: case Code.DCMPL: case Code.DDIV: case Code.DMUL: case Code.DNEG: case Code.DREM: case Code.DRETURN: case Code.DSUB: case Code.DUP: case Code.DUP_X1: case Code.DUP_X2: case Code.DUP2: case Code.DUP2_X1: case Code.DUP2_X2: case Code.F2D: case Code.F2I: case Code.F2L: case Code.FADD: case Code.FALOAD: case Code.FASTORE: case Code.FCMPG: case Code.FCMPL: case Code.FDIV: case Code.FMUL: case Code.FNEG: case Code.FREM: case Code.FRETURN: case Code.FSUB: case Code.I2B: case Code.I2C: case Code.I2D: case Code.I2F: case Code.I2L: case Code.I2S: case Code.IADD: case Code.IALOAD: case Code.IAND: case Code.IASTORE: case Code.IDIV: case Code.IMUL: case Code.INEG: case Code.IOR: case Code.IREM: case Code.IRETURN: case Code.ISHL: case Code.ISHR: case Code.ISUB: case Code.IUSHR: case Code.IXOR: case Code.L2D: case Code.L2F: case Code.L2I: case Code.LADD: case Code.LALOAD: case Code.LAND: case Code.LASTORE: case Code.LCMP: case Code.LDIV: case Code.LMUL: case Code.LNEG: case Code.LOR: case Code.LREM: case Code.LRETURN: case Code.LSHL: case Code.LSHR: case Code.LSUB: case Code.LUSHR: case Code.LXOR: case Code.MONITORENTER: case Code.MONITOREXIT: case Code.NOP: case Code.POP: case Code.POP2: case Code.RETURN: case Code.SALOAD: case Code.SASTORE: case Code.SWAP: // Single byte break; case Code.ALOAD: case Code.ASTORE: case Code.DLOAD: case Code.DSTORE: case Code.FLOAD: case Code.FSTORE: case Code.ILOAD: case Code.ISTORE: case Code.LLOAD: case Code.LSTORE: // Single U8 operand operand = GetLocalVariable(startOffset, ReadU8(ref offset)); break; case Code.ALOAD_0: case Code.ALOAD_1: case Code.ALOAD_2: case Code.ALOAD_3: operand = GetLocalVariable(startOffset, opcode - Code.ALOAD_0); break; case Code.ANEWARRAY: case Code.CHECKCAST: case Code.INSTANCEOF: case Code.NEW: // U16 class reference operand = cp.GetEntry <ConstantPoolClass>(ReadU16(ref offset)); break; case Code.ASTORE_0: case Code.ASTORE_1: case Code.ASTORE_2: case Code.ASTORE_3: operand = GetLocalVariable(startOffset, opcode - Code.ASTORE_0); break; case Code.BIPUSH: operand = ReadS8(ref offset); break; case Code.DCONST_0: operand = 0.0; break; case Code.DCONST_1: operand = 1.0; break; case Code.DLOAD_0: case Code.DLOAD_1: case Code.DLOAD_2: case Code.DLOAD_3: operand = GetLocalVariable(startOffset, opcode - Code.DLOAD_0); break; case Code.DSTORE_0: case Code.DSTORE_1: case Code.DSTORE_2: case Code.DSTORE_3: operand = GetLocalVariable(startOffset, opcode - Code.DSTORE_0); break; case Code.FCONST_0: operand = 0.0f; break; case Code.FCONST_1: operand = 1.0f; break; case Code.FCONST_2: operand = 2.0f; break; case Code.FLOAD_0: case Code.FLOAD_1: case Code.FLOAD_2: case Code.FLOAD_3: operand = GetLocalVariable(startOffset, opcode - Code.FLOAD_0); break; case Code.FSTORE_0: case Code.FSTORE_1: case Code.FSTORE_2: case Code.FSTORE_3: operand = GetLocalVariable(startOffset, opcode - Code.FSTORE_0); break; case Code.GETFIELD: case Code.GETSTATIC: case Code.PUTFIELD: case Code.PUTSTATIC: // U16 field reference operand = cp.GetEntry <ConstantPoolFieldRef>(ReadU16(ref offset)); break; case Code.GOTO: case Code.IF_ACMPEQ: case Code.IF_ACMPNE: case Code.IF_ICMPEQ: case Code.IF_ICMPNE: case Code.IF_ICMPLT: case Code.IF_ICMPGE: case Code.IF_ICMPGT: case Code.IF_ICMPLE: case Code.IFEQ: case Code.IFNE: case Code.IFLT: case Code.IFGE: case Code.IFGT: case Code.IFLE: case Code.IFNONNULL: case Code.IFNULL: case Code.JSR: operand = new BranchOffset(ReadS16(ref offset)); break; case Code.GOTO_W: case Code.JSR_W: operand = new BranchOffset(ReadS32(ref offset)); break; case Code.ICONST_M1: case Code.ICONST_0: case Code.ICONST_1: case Code.ICONST_2: case Code.ICONST_3: case Code.ICONST_4: case Code.ICONST_5: operand = (int)(opcode - Code.ICONST_0); break; case Code.IINC: operand = GetLocalVariable(startOffset, ReadU8(ref offset)); operand2 = ReadS8(ref offset); break; case Code.ILOAD_0: case Code.ILOAD_1: case Code.ILOAD_2: case Code.ILOAD_3: operand = GetLocalVariable(startOffset, opcode - Code.ILOAD_0); break; case Code.INVOKEINTERFACE: // U16 method/imethod reference operand = cp[ReadU16(ref offset)]; operand2 = ReadU8(ref offset); offset++; // '0' break; case Code.INVOKESPECIAL: case Code.INVOKESTATIC: case Code.INVOKEVIRTUAL: // U16 method/imethod reference operand = cp[ReadU16(ref offset)]; break; case Code.ISTORE_0: case Code.ISTORE_1: case Code.ISTORE_2: case Code.ISTORE_3: operand = GetLocalVariable(startOffset, opcode - Code.ISTORE_0); break; case Code.LCONST_0: operand = 0L; break; case Code.LCONST_1: operand = 1L; break; case Code.LDC: operand = cp[ReadU8(ref offset)]; break; case Code.LDC_W: case Code.LDC2_W: operand = cp[ReadU16(ref offset)]; break; case Code.LLOAD_0: case Code.LLOAD_1: case Code.LLOAD_2: case Code.LLOAD_3: operand = GetLocalVariable(startOffset, opcode - Code.LLOAD_0); break; case Code.LOOKUPSWITCH: operand = ReadLookupSwitch(ref offset); break; case Code.LSTORE_0: case Code.LSTORE_1: case Code.LSTORE_2: case Code.LSTORE_3: operand = GetLocalVariable(startOffset, opcode - Code.LSTORE_0); break; case Code.MULTIANEWARRAY: operand = cp.GetEntry <ConstantPoolClass>(ReadU16(ref offset)); operand2 = ReadU8(ref offset); break; case Code.NEWARRAY: operand = ReadU8(ref offset); break; case Code.RET: operand = GetLocalVariable(startOffset, ReadU8(ref offset)); break; case Code.SIPUSH: operand = ReadS16(ref offset); break; case Code.TABLESWITCH: operand = ReadTableSwitch(ref offset); break; case Code.WIDE: opcode = (Code)code[offset++]; operand = GetLocalVariable(startOffset, ReadU16(ref offset)); if (opcode == Code.IINC) { operand2 = ReadS16(ref offset); } break; } instructions.Add(new Instruction(startOffset, opcode, operand, operand2)); } return(instructions); }
public override void ProcessFromConstantPool(ConstantPool constantPool) { Class = constantPool.GetEntry <ClassEntry>(classIndex); NameAndType = constantPool.GetEntry <NameAndTypeEntry>(nameAndTypeIndex); }