Skip to content

Commit

Permalink
Improve error message when failing to locate an RVA in the R2R reader
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Sep 23, 2024
1 parent ac80472 commit a295c46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public static int GetOffset(this PEReader reader, int rva)
int index = reader.PEHeaders.GetContainingSectionIndex(rva);
if (index == -1)
{
throw new BadImageFormatException("Failed to convert invalid RVA to offset: " + rva);
var sectionInfo = new StringBuilder();
foreach (var sh in reader.PEHeaders.SectionHeaders)
sectionInfo.AppendLine($" {sh.Name} PTRD={sh.PointerToRawData} SORD={sh.SizeOfRawData} VA={sh.VirtualAddress} VS={sh.VirtualSize}");
throw new BadImageFormatException($"Failed to convert invalid RVA to offset: {rva}.\nSections:\n{sectionInfo}");
}
SectionHeader containingSection = reader.PEHeaders.SectionHeaders[index];
return rva - containingSection.VirtualAddress + containingSection.PointerToRawData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ private void FindOwnerCompositeExecutable()
}

/// <summary>
/// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/zap/zapimport.cpp">ZapImportSectionsTable::Save</a>
/// originally based on <a href="https://github.com/dotnet/coreclr/blob/master/src/zap/zapimport.cpp">ZapImportSectionsTable::Save</a>
/// </summary>
private void EnsureImportSections()
{
Expand Down

0 comments on commit a295c46

Please sign in to comment.