Add PE COFF line numbers to section headers

This commit is contained in:
Matt Nadareski
2022-11-05 00:08:00 -07:00
parent 41a4965775
commit e103ddd216
4 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
using System.Runtime.InteropServices;
namespace BurnOutSharp.Models.PortableExecutable
{
/// <summary>
/// COFF line numbers are no longer produced and, in the future, will
/// not be consumed.
///
/// COFF line numbers indicate the relationship between code and line
/// numbers in source files. The Microsoft format for COFF line numbers
/// is similar to standard COFF, but it has been extended to allow a
/// single section to relate to line numbers in multiple source files.
///
/// COFF line numbers consist of an array of fixed-length records.
/// The location (file offset) and size of the array are specified in
/// the section header.
/// </summary>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format"/>
[StructLayout(LayoutKind.Explicit)]
public class COFFLineNumber
{
/// <summary>
/// Used when Linenumber is zero: index to symbol table entry for a function.
/// This format is used to indicate the function to which a group of
/// line-number records refers.
/// </summary>
[FieldOffset(0)] public uint SymbolTableIndex;
/// <summary>
/// Used when Linenumber is non-zero: the RVA of the executable code that
/// corresponds to the source line indicated. In an object file, this
/// contains the VA within the section.
/// </summary>
[FieldOffset(0)] public uint VirtualAddress;
/// <summary>
/// When nonzero, this field specifies a one-based line number. When zero,
/// the Type field is interpreted as a symbol table index for a function.
/// </summary>
[FieldOffset(4)] public ushort Linenumber;
}
}

View File

@@ -7,7 +7,7 @@ namespace BurnOutSharp.Models.PortableExecutable
/// should be modified when placed in the image file and subsequently loaded
/// into memory.
///
/// mage files do not contain COFF relocations, because all referenced symbols
/// Image files do not contain COFF relocations, because all referenced symbols
/// have already been assigned addresses in a flat address space. An image
/// contains relocation information in the form of base relocations in the
/// .reloc section (unless the image has the IMAGE_FILE_RELOCS_STRIPPED attribute).

View File

@@ -36,6 +36,6 @@ namespace BurnOutSharp.Models.PortableExecutable
/// </summary>
public SectionHeader[] SectionTable { get; set; }
// TODO: Left off at "COFF Relocations (Object Only)"
// TODO: Left off at "COFF Symbol Table"
}
}

View File

@@ -105,5 +105,10 @@ namespace BurnOutSharp.Models.PortableExecutable
/// COFF Relocations (Object Only)
/// </summary>
public COFFRelocation[] COFFRelocations;
/// <summary>
/// COFF Line Numbers (Deprecated)
/// </summary>
public COFFLineNumber[] COFFLineNumbers;
}
}