コード例 #1
0
        public bool IsCatchBlockBegin(int ilOffset, out ExceptionHandlingClause exceptionHandlingClause)
        {
            exceptionHandlingClause = null;
            int handlingClauseIndex;

            if (NonIlOffsets.IsCatchBlockBegin(ilOffset, out handlingClauseIndex))
            {
                exceptionHandlingClause = _exceptionHandlingClauses[handlingClauseIndex];
                return(true);
            }
            return(false);
        }
コード例 #2
0
        private bool IsTryBlockEnd(int ilOffset, out ExceptionHandlingClause exceptionHandlingClause)
        {
            exceptionHandlingClause = null;
            int handlingClauseIndex;

            if (NonIlOffsets.IsTryBlockEnd(ilOffset, out handlingClauseIndex))
            {
                exceptionHandlingClause = _exceptionHandlingClauses[handlingClauseIndex];
                return(true);
            }
            return(false);
        }
コード例 #3
0
        private IEnumerable <int> Scan(byte[] ilBytes, IList <ExceptionHandlingClause> exceptionHandlingClauses)
        {
            IEnumerable <int> ilOffsets = ScanRawIl(ilBytes).ToList();
            var branches = new Dictionary <int, List <int> >();

            Action <int, int> addBranches = (source, target) =>
            {
                List <int> sourceList;
                if (branches.TryGetValue(target, out sourceList))
                {
                    sourceList.Add(source);
                }
                else
                {
                    branches.Add(target, new List <int>(source));
                }
            };

            foreach (var ilOffset in ilOffsets)
            {
                OpCode opCode = GetOpCodeFrom(ilBytes, ilOffset);
                if (opCode.Value == OpCodes.Switch.Value)
                {
                    int count       = GetOperandSwitchCount(ilBytes, ilOffset, opCode);
                    int beginBrList = ilOffset + opCode.Size + 4;
                    int brSource    = beginBrList + count * 4;
                    for (int index = 0; index < count; index++)
                    {
                        int brTarget = brSource + ilBytes.ReadInt32(beginBrList + index * 4);
                        addBranches(ilOffset, brTarget);
                    }
                }
                else if (opCode.OperandType == OperandType.InlineBrTarget ||
                         opCode.OperandType == OperandType.ShortInlineBrTarget)
                {
                    int brTarget = GetOperandBrTarget(ilBytes, ilOffset, opCode);
                    addBranches(ilOffset, brTarget);
                }
            }

            foreach (var ilOffset in ilOffsets)
            {
                foreach (var exceptionHandlingIndex in GetTryBlockIndices(exceptionHandlingClauses, ilOffset))
                {
                    yield return(NonIlOffsets.BeginTryBlock(exceptionHandlingIndex));
                }

                for (int index = 0; index < exceptionHandlingClauses.Count; index++)
                {
                    var exceptionHandlingClause = exceptionHandlingClauses[index];
                    if (exceptionHandlingClause.TryOffset + exceptionHandlingClause.TryLength == ilOffset)
                    {
                        yield return(NonIlOffsets.EndTryBlock(index));
                    }
                    if (exceptionHandlingClause.HandlerOffset == ilOffset)
                    {
                        if (exceptionHandlingClause.Flags == ExceptionHandlingClauseOptions.Clause)
                        {
                            yield return(NonIlOffsets.BeginCatchBlock(index));
                        }
                        if (exceptionHandlingClause.Flags == ExceptionHandlingClauseOptions.Fault)
                        {
                            yield return(NonIlOffsets.BeginCatchBlock(index));
                        }
                        if (exceptionHandlingClause.Flags == ExceptionHandlingClauseOptions.Finally)
                        {
                            yield return(NonIlOffsets.BeginFinallyBlock(index));
                        }
                    }
                    if (exceptionHandlingClause.HandlerOffset + exceptionHandlingClause.HandlerLength == ilOffset)
                    {
                        yield return(NonIlOffsets.EndHandlerBlock(index));
                    }
                    if (exceptionHandlingClause.Flags == ExceptionHandlingClauseOptions.Filter &&
                        exceptionHandlingClause.FilterOffset == ilOffset)
                    {
                        yield return(NonIlOffsets.BeginFilterBlock(index));
                    }
                }

                List <int> brSource;
                if (branches.TryGetValue(ilOffset, out brSource))
                {
                    yield return(NonIlOffsets.Label(ilOffset));
                }

                yield return(ilOffset);
            }
        }
コード例 #4
0
 public static bool IsLabel(int ilOffset, out int id)
 {
     return(NonIlOffsets.IsLabel(ilOffset, out id));
 }