IsConsistent() private method

private IsConsistent ( ) : bool
return bool
Esempio n. 1
0
        private void *Resolve(RVAAndSize rva)
        {
            //1. Can we find the section containing the address
            FluentAsserts.Assume(rva.IsConsistent());
            if (rva.IsZero())
            {
                return(null);
            }
            var pSection = FindSection(rva.RVA);

            if (pSection == null)
            {
                return(null);
            }

            //2. Does the section have initialized data?
            if (pSection->PointerToRawData == 0 || pSection->SizeOfRawData == 0)
            {
                return(null);
            }

            //3. Is the item located entirely within the initialized data portion of the section?
            //Although it is possible that some portion could be placed inside unitialized data,
            //it is unlikely. Such a case is more likely indicative of a malformed image.
            try
            {
                if (checked (rva.RVA - pSection->VirtualAddress) > pSection->SizeOfRawData)
                {
                    return(null);
                }

                if (checked (rva.RVA - pSection->VirtualAddress + rva.Size) > pSection->SizeOfRawData)
                {
                    return(null);
                }
            }
            catch (OverflowException)
            {
                return(null);
            }
            return((m_pData + (rva.RVA - pSection->VirtualAddress)) + pSection->PointerToRawData);
        }
Esempio n. 2
0
        public unsafe bool Verify(OptionalHeader optionalHeader)
        {
            //1. The header size must be consistent with the other places it is reported.
            if (HeaderSize < sizeof(CLRHeader))
            {
                return(false);
            }

            if (HeaderSize < optionalHeader.CLRRuntimeHeader.Size)
            {
                return(false);
            }

            //2. We require metadata versions between 2.0 and 2.5.
            if (MajorRuntimeVersion != 2)
            {
                return(false);
            }

            if (MinorRuntimeVersion > 5)
            {
                return(false);
            }
            //3. The total size of the meta-data must be at least large enough to store the metadata root.
            if (Metadata.RVA == 0 || Metadata.Size < MetadataRoot.MinSize)
            {
                return(false);
            }

            //4. If any "uknown" flags are present, we reject the image.
            if ((Flags & ~CLRHeaderFlags.KnownFlags) != 0)
            {
                return(false);
            }

            //4. We don't support mixed-mode assemblies.
            const CLRHeaderFlags requiredFlags = CLRHeaderFlags.COMIMAGE_FLAGS_ILONLY;

            if ((Flags & requiredFlags) != requiredFlags)
            {
                return(false);
            }

            const CLRHeaderFlags disallowedFlags = CLRHeaderFlags.COMIMAGE_FLAGS_NATIVE_ENTRYPOINT;

            if ((Flags & disallowedFlags) != 0)
            {
                return(false);
            }

            //5. The StrongNameSignature pointer should have a zero size only if it is null.
            if (!StrongNameSignature.IsConsistent())
            {
                return(false);
            }

            //6. We should have a Strong name pointer iif the image is marked as being strong named signed.
            if (StrongNameSignature.IsZero() != ((Flags & CLRHeaderFlags.COMIMAGE_FLAGS_STRONGNAMESIGNED) == 0))
            {
                return(false);
            }

            //7. There should be a null code manager table pointer.
            if (!CodeManagerTable.IsZero())
            {
                return(false);
            }

            //8. There should be no vtable fixups.
            if (!VTableFixups.IsZero())
            {
                return(false);
            }

            return(true);
        }