Exemplo n.º 1
0
        /// <summary>
        /// Reads a single lookup switch at the current position of the provided reader.
        /// </summary>
        /// <param name="reader">The reader to use.</param>
        /// <returns>The lookup switch</returns>
        public static LookupSwitch FromReader(IBigEndianReader reader)
        {
            var lookup = new LookupSwitch
            {
                DefaultOffset = reader.ReadInt32(),
            };

            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                int key    = reader.ReadInt32();
                int offset = reader.ReadInt32();
                lookup.Table[key] = offset;
            }

            return(lookup);
        }
Exemplo n.º 2
0
        private object ReadRawOperand(ByteOpCode opcode)
        {
            switch (opcode.OperandType)
            {
            case ByteCodeOperandType.None:
                return(null);

            case ByteCodeOperandType.Byte:
            case ByteCodeOperandType.ConstantIndex:
            case ByteCodeOperandType.LocalIndex:
            case ByteCodeOperandType.PrimitiveType:
                return(_reader.ReadByte());

            case ByteCodeOperandType.Short:
            case ByteCodeOperandType.WideConstantIndex:
            case ByteCodeOperandType.BranchOffset:
            case ByteCodeOperandType.LocalConst:
            case ByteCodeOperandType.FieldIndex:
            case ByteCodeOperandType.MethodIndex:
            case ByteCodeOperandType.ClassIndex:
                return(_reader.ReadInt16());

            case ByteCodeOperandType.TableSwitch:
                _reader.Position = FileSegment.Align((uint)_reader.Position, 4);
                return(TableSwitch.FromReader(_reader));

            case ByteCodeOperandType.LookupSwitch:
                _reader.Position = FileSegment.Align((uint)_reader.Position, 4);
                return(LookupSwitch.FromReader(_reader));

            case ByteCodeOperandType.WideIndexCountZero:
            case ByteCodeOperandType.WideIndexByte:
            case ByteCodeOperandType.WideBranchOffset:
            case ByteCodeOperandType.DynamicIndex:
                return(_reader.ReadInt32());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }