AsmResolver.Net.Msil.MethodBody.GetInstructionByOffset C# (CSharp) Method

GetInstructionByOffset() public method

public GetInstructionByOffset ( int offset ) : MsilInstruction
offset int
return MsilInstruction
        public MsilInstruction GetInstructionByOffset(int offset)
        {
            return Instructions.FirstOrDefault(x => x.Offset == offset);
        }

Usage Example

Beispiel #1
0
        public static ExceptionHandler FromReader(MethodBody methodBody, IBinaryStreamReader reader, bool fatFormat)
        {
            var offset                   = reader.Position;
            var handerType               = fatFormat ? reader.ReadUInt32() : reader.ReadUInt16();
            var tryOffset                = fatFormat ? reader.ReadInt32() : reader.ReadUInt16();
            var tryLength                = fatFormat ? reader.ReadInt32() : reader.ReadByte();
            var handlerOffset            = fatFormat ? reader.ReadInt32() : reader.ReadUInt16();
            var handlerLength            = fatFormat ? reader.ReadInt32() : reader.ReadByte();
            var classTokenOrFilterOffset = reader.ReadUInt32();

            var handler = new ExceptionHandler((ExceptionHandlerType)handerType)
            {
                StartOffset  = offset,
                IsFat        = fatFormat,
                MethodBody   = methodBody,
                TryStart     = methodBody.GetInstructionByOffset(tryOffset),
                TryEnd       = methodBody.GetInstructionByOffset(tryOffset + tryLength),
                HandlerStart = methodBody.GetInstructionByOffset(handlerOffset),
                HandlerEnd   = methodBody.GetInstructionByOffset(handlerOffset + handlerLength),
            };

            switch (handler.HandlerType)
            {
            case ExceptionHandlerType.Exception:
                handler.CatchType = (ITypeDefOrRef)((IOperandResolver)methodBody).ResolveMember(new MetadataToken(classTokenOrFilterOffset));
                break;

            case ExceptionHandlerType.Filter:
                handler.FilterStart = methodBody.GetInstructionByOffset((int)classTokenOrFilterOffset);
                break;
            }

            return(handler);
        }
All Usage Examples Of AsmResolver.Net.Msil.MethodBody::GetInstructionByOffset