private bool TryLocateNativeReadyToRunHeader() { PEExportTable exportTable = CompositeReader.GetExportTable(); if (exportTable.TryGetValue("RTR_HEADER", out _readyToRunHeaderRVA)) { _composite = true; return(true); } return(false); }
private unsafe void Initialize(IAssemblyMetadata metadata) { _assemblyCache = new List <IAssemblyMetadata>(); if (CompositeReader == null) { byte[] image = File.ReadAllBytes(Filename); Image = image; CompositeReader = new PEReader(Unsafe.As <byte[], ImmutableArray <byte> >(ref image)); } else { ImmutableArray <byte> content = CompositeReader.GetEntireImage().GetContent(); Image = Unsafe.As <ImmutableArray <byte>, byte[]>(ref content); } if (metadata == null && CompositeReader.HasMetadata) { metadata = new StandaloneAssemblyMetadata(CompositeReader); } if (metadata != null) { if ((CompositeReader.PEHeaders.CorHeader.Flags & CorFlags.ILLibrary) == 0) { if (!TryLocateNativeReadyToRunHeader()) { throw new BadImageFormatException("The file is not a ReadyToRun image"); } Debug.Assert(Composite); } else { _assemblyCache.Add(metadata); DirectoryEntry r2rHeaderDirectory = CompositeReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory; _readyToRunHeaderRVA = r2rHeaderDirectory.RelativeVirtualAddress; Debug.Assert(!Composite); } } else if (!TryLocateNativeReadyToRunHeader()) { throw new BadImageFormatException($"ECMA metadata / RTR_HEADER not found in file '{Filename}'"); } }
private void DuellReaders(CompositeReader other, AtomicReader memIndexReader) { AtomicReader competitor = SlowCompositeReaderWrapper.Wrap(other); Fields memFields = memIndexReader.Fields; foreach (string field in competitor.Fields) { Terms memTerms = memFields.GetTerms(field); Terms iwTerms = memIndexReader.GetTerms(field); if (iwTerms is null) { assertNull(memTerms); } else { NumericDocValues normValues = competitor.GetNormValues(field); NumericDocValues memNormValues = memIndexReader.GetNormValues(field); if (normValues != null) { // mem idx always computes norms on the fly assertNotNull(memNormValues); assertEquals(normValues.Get(0), memNormValues.Get(0)); } assertNotNull(memTerms); assertEquals(iwTerms.DocCount, memTerms.DocCount); assertEquals(iwTerms.SumDocFreq, memTerms.SumDocFreq); assertEquals(iwTerms.SumTotalTermFreq, memTerms.SumTotalTermFreq); TermsEnum iwTermsIter = iwTerms.GetEnumerator(); TermsEnum memTermsIter = memTerms.GetEnumerator(); if (iwTerms.HasPositions) { bool offsets = iwTerms.HasOffsets && memTerms.HasOffsets; while (iwTermsIter.MoveNext()) { assertTrue(memTermsIter.MoveNext()); assertEquals(iwTermsIter.Term, memTermsIter.Term); DocsAndPositionsEnum iwDocsAndPos = iwTermsIter.DocsAndPositions(null, null); DocsAndPositionsEnum memDocsAndPos = memTermsIter.DocsAndPositions(null, null); while (iwDocsAndPos.NextDoc() != DocsAndPositionsEnum.NO_MORE_DOCS) { assertEquals(iwDocsAndPos.DocID, memDocsAndPos.NextDoc()); assertEquals(iwDocsAndPos.Freq, memDocsAndPos.Freq); for (int i = 0; i < iwDocsAndPos.Freq; i++) { assertEquals("term: " + iwTermsIter.Term.Utf8ToString(), iwDocsAndPos.NextPosition(), memDocsAndPos.NextPosition()); if (offsets) { assertEquals(iwDocsAndPos.StartOffset, memDocsAndPos.StartOffset); assertEquals(iwDocsAndPos.EndOffset, memDocsAndPos.EndOffset); } } } } } else { while (iwTermsIter.MoveNext()) { assertEquals(iwTermsIter.Term, memTermsIter.Term); DocsEnum iwDocsAndPos = iwTermsIter.Docs(null, null); DocsEnum memDocsAndPos = memTermsIter.Docs(null, null); while (iwDocsAndPos.NextDoc() != DocsAndPositionsEnum.NO_MORE_DOCS) { assertEquals(iwDocsAndPos.DocID, memDocsAndPos.NextDoc()); assertEquals(iwDocsAndPos.Freq, memDocsAndPos.Freq); } } } } } }
/// <summary> /// Get the index in the image byte array corresponding to the RVA /// </summary> /// <param name="rva">The relative virtual address</param> public int GetOffset(int rva) { return(CompositeReader.GetOffset(rva)); }