示例#1
0
        public LiftedList <T> LoadDirectChildren <T>(
            MetadataTable childTable,
            GetTokenDelegate tokenSelector,
            CreateObjectDelegateEX <T> factory,
            MetadataTable parentTable,
            void *parentRow
            ) where T : class
        {
            var            firstMemberIndex = (ZeroBasedIndex)tokenSelector(parentRow);
            ZeroBasedIndex lastMemberIndex;
            var            tableIndex = GetRowIndex(parentTable, parentRow);

            if (tableIndex == GetRowCount(parentTable) - 1)
            {
                lastMemberIndex = new ZeroBasedIndex(GetRowCount(childTable));
            }
            else
            {
                lastMemberIndex = (ZeroBasedIndex)tokenSelector(GetRow(tableIndex + 1, parentTable));
            }
            var ret = new LiftedList <T>(
                (lastMemberIndex - firstMemberIndex).Value,
                index => GetRow(firstMemberIndex + index, childTable),
                factory,
                () => IsDisposed
                );

            return(ret);
        }
示例#2
0
        public LiftedList <TChild> LoadIndirectChildren <TChild, TParentField>(
            TParentField parent,
            MetadataTable childTable,
            UnsafeSelector <TParentField> parentSelector,
            CreateObjectDelegate <TChild> factory
            ) where TChild : class
        {
            CheckDisposed();
            //It is valid for the child table to not be sorted, but I don't expect such a case to occur in practice.
            //I imagine that this could maybe happen with ENC, but we don't need to be able to decompile enc assemblies.
            //In either case, if we do end up needing to support assemblies with unsorted meta-data tables, then we should probably
            //add our best attempt at an efficent fallback in that case. For now we just throw.
            IsSorted(childTable).Assume("The generic param constraint table is not sorted.");

            var glb = GreatestLowerBound(
                childTable,
                parent,
                parentSelector
                );
            var lub = LeastUpperBound(
                childTable,
                parent,
                parentSelector
                );

            var ret = new LiftedList <TChild>(
                (glb - lub - 1).Value,
                index => GetRow(index.ToZB() + lub + 1, childTable),
                factory,
                () => IsDisposed
                );

            return(ret);
        }
示例#3
0
        void LoadExceptionHandlers()
        {
            var header = GetMethodHeader();
            IReadOnlyList <ExceptionHandler> exceptionHandlers;

            if (!header.MoreSectionsFollow())
            {
                exceptionHandlers = (new List <ExceptionHandler>(0)).AsReadOnly();
            }
            else
            {
                var pExceptionHeader = (byte *)Util.Pad(
                    ((IntPtr)(header.RawHeader + header.Size + header.CodeSize)),
                    (IntPtr)4
                    );
                var flags = (ExceptionHeaderFlags)(*pExceptionHeader);

                ExceptionHeader exceptionHeader = null;
                while (
                    (flags & ExceptionHeaderFlags.EHTable) == 0 &&
                    (flags & ExceptionHeaderFlags.MoreSects) != 0
                    )
                {
                    if ((flags & ExceptionHeaderFlags.FatFormat) != 0)
                    {
                        exceptionHeader = new ExceptionHeader((FatExceptionHeader *)pExceptionHeader);
                    }
                    else
                    {
                        exceptionHeader = new ExceptionHeader((TinyExceptionHeader *)pExceptionHeader);
                    }

                    pExceptionHeader += exceptionHeader.DataSize;
                    flags             = (ExceptionHeaderFlags)(*pExceptionHeader);
                }

                exceptionHeader.AssumeNotNull();

                if ((flags & ExceptionHeaderFlags.EHTable) != 0)
                {
                    exceptionHandlers = new LiftedList <ExceptionHandler>(
                        exceptionHeader.NumberOfExceptionClauses,
                        index => exceptionHeader.GetExceptionHandler(index, Module),
                        () => Module.PEFile.IsDisposed
                        );
                }
                else
                {
                    exceptionHandlers = (new List <ExceptionHandler>(0)).AsReadOnly();
                }
            }
            #pragma warning disable 420
            Interlocked.CompareExchange(ref m_exceptionHandlers, exceptionHandlers, null);
            #pragma warning restore 420
        }
示例#4
0
        static LiftedList <Instruction> GetSwitchTargets(IParseState <byte, InstructionParseState> input, int n)
        {
            var remainingInput   = input.RemainingInput;
            var methodDefinition = input.Result.MethodDefinition;
            var context          = input.Result.InstructionContext;
            var operand          = new LiftedList <Instruction>(
                n,
                index => {
                var target = remainingInput.SubList(checked ((index + 1) * 4)).ReadLittleEndianInt();
                return(methodDefinition.FindInstruction(context.Offset + context.Size + target));
            }
                );

            return(operand);
        }
示例#5
0
        void LoadAssociations()
        {
            if (m_associatedEvents == null)
            {
                var associations = Module.GetAssociations(MetadataTable.MethodDef.RowIndex(m_pRow, Module.PEFile));
                ((int)MetadataTable.Event).AssumeLT((int)MetadataTable.Property);

                var firstProperty = associations.LeastUpperBound(
                    x => ((MethodSemanticsRow *)x)->GetAssosication(Module.PEFile).Table,
                    MetadataTable.Event
                    );
                var eventRows    = associations.SubList(0, firstProperty);
                var propertyRows = associations.SubList(firstProperty);

                var associatedEvents = new LiftedList <Event>(
                    eventRows.Count,
                    index => DeclaringType.Events[
                        (((MethodSemanticsRow *)eventRows[index])->GetAssosication(Module.PEFile).Index
                         - DeclaringType.FirstEventIndex).Value
                    ],
                    () => Module.PEFile.IsDisposed
                    );

                var associatedProperties = new LiftedList <Property>(
                    propertyRows.Count,
                    index => DeclaringType.Properties[
                        (((MethodSemanticsRow *)propertyRows[index])->GetAssosication(Module.PEFile).Index
                         - DeclaringType.FirstPropertyIndex).Value
                    ],
                    () => Module.PEFile.IsDisposed
                    );
                #pragma warning disable 420
                Interlocked.CompareExchange(ref m_associatedEvents, associatedEvents, null);
                Interlocked.CompareExchange(ref m_associatedProperties, associatedProperties, null);
                #pragma warning restore 420
            }
        }
示例#6
0
        void LoadExceptionHandlers()
        {
            var header = GetMethodHeader();
            IReadOnlyList<ExceptionHandler> exceptionHandlers;
            if (! header.MoreSectionsFollow()) {
                exceptionHandlers = (new List<ExceptionHandler>(0)).AsReadOnly();
            }
            else {
                var pExceptionHeader = (byte*) Util.Pad(
                    ((IntPtr) (header.RawHeader + header.Size + header.CodeSize)),
                    (IntPtr) 4
                );
                var flags = (ExceptionHeaderFlags) (*pExceptionHeader);

                ExceptionHeader exceptionHeader = null;
                while (
                    (flags & ExceptionHeaderFlags.EHTable) == 0
                    && (flags & ExceptionHeaderFlags.MoreSects) != 0
                ) {
                    if ((flags & ExceptionHeaderFlags.FatFormat) != 0) {
                        exceptionHeader = new ExceptionHeader((FatExceptionHeader*) pExceptionHeader);
                    }
                    else {
                        exceptionHeader = new ExceptionHeader((TinyExceptionHeader*) pExceptionHeader);
                    }

                    pExceptionHeader += exceptionHeader.DataSize;
                    flags = (ExceptionHeaderFlags) (*pExceptionHeader);
                }

                exceptionHeader.AssumeNotNull();

                if ((flags & ExceptionHeaderFlags.EHTable) != 0) {
                    exceptionHandlers = new LiftedList<ExceptionHandler>(
                        exceptionHeader.NumberOfExceptionClauses,
                        index => exceptionHeader.GetExceptionHandler(index, Module),
                        () => Module.PEFile.IsDisposed
                    );
                }
                else {
                    exceptionHandlers = (new List<ExceptionHandler>(0)).AsReadOnly();
                }
            }
            #pragma warning disable 420
            Interlocked.CompareExchange(ref m_exceptionHandlers, exceptionHandlers, null);
            #pragma warning restore 420
        }
示例#7
0
        void LoadAssociations()
        {
            if (m_associatedEvents == null) {
                var associations = Module.GetAssociations(MetadataTable.MethodDef.RowIndex(m_pRow, Module.PEFile));
                ((int)MetadataTable.Event).AssumeLT((int)MetadataTable.Property);

                var firstProperty =associations.LeastUpperBound(
                    x => ((MethodSemanticsRow*) x)->GetAssosication(Module.PEFile).Table,
                    MetadataTable.Event
                );
                var eventRows = associations.SubList(0, firstProperty);
                var propertyRows = associations.SubList(firstProperty);

                var associatedEvents = new LiftedList<Event>(
                    eventRows.Count,
                    index => DeclaringType.Events[
                        (((MethodSemanticsRow*)eventRows[index])->GetAssosication(Module.PEFile).Index
                        - DeclaringType.FirstEventIndex).Value
                    ],
                    () => Module.PEFile.IsDisposed
                );

                var associatedProperties = new LiftedList<Property>(
                    propertyRows.Count,
                    index => DeclaringType.Properties[
                        (((MethodSemanticsRow*)propertyRows[index])->GetAssosication(Module.PEFile).Index
                        - DeclaringType.FirstPropertyIndex).Value
                    ],
                    () => Module.PEFile.IsDisposed
                );
                #pragma warning disable 420
                Interlocked.CompareExchange(ref m_associatedEvents, associatedEvents, null);
                Interlocked.CompareExchange(ref m_associatedProperties, associatedProperties, null);
                #pragma warning restore 420
            }
        }