-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #528 from MindscapeHQ/sean/portable-pdb-support
Add Portable PDB support to Raygun4Net and Raygun4NetCore
- Loading branch information
Showing
14 changed files
with
440 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Mindscape.Raygun4Net.Core/Diagnostics/PEDebugInformation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace Mindscape.Raygun4Net.Diagnostics; | ||
|
||
public sealed class PEDebugInformation | ||
{ | ||
/// <summary> | ||
/// The signature of the PE and PDB linking them together - usually a GUID | ||
/// </summary> | ||
public string Signature { get; internal set; } | ||
|
||
/// <summary> | ||
/// Checksum of the PE & PDB. Format: {algorithm}:{hash:X} | ||
/// </summary> | ||
public string Checksum { get; internal set; } | ||
|
||
/// <summary> | ||
/// The full location of the PDB at build time | ||
/// </summary> | ||
public string File { get; internal set; } | ||
|
||
/// <summary> | ||
/// The generated Timestamp of the code at build time stored as hex | ||
/// </summary> | ||
public string Timestamp { get; internal set; } | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
Mindscape.Raygun4Net.Core/Diagnostics/PortableExecutableReaderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection.PortableExecutable; | ||
|
||
namespace Mindscape.Raygun4Net.Diagnostics; | ||
|
||
internal static class PortableExecutableReaderExtensions | ||
{ | ||
public static PEReader GetFileSystemPEReader(string moduleName) | ||
{ | ||
try | ||
{ | ||
// Read into memory to avoid any premature stream closures | ||
var bytes = ImmutableArray.Create(File.ReadAllBytes(moduleName)); | ||
return new PEReader(bytes); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"Could not open module [{moduleName}] from disk: {ex}"); | ||
return null; | ||
} | ||
} | ||
|
||
public static bool TryGetDebugInformation(this PEReader peReader, out PEDebugInformation debugInformation) | ||
{ | ||
try | ||
{ | ||
debugInformation = GetDebugInformation(peReader); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"Error reading PE Debug Data: {ex}"); | ||
} | ||
|
||
debugInformation = null; | ||
return false; | ||
} | ||
|
||
private static PEDebugInformation GetDebugInformation(this PEReader peReader) | ||
{ | ||
var debugInfo = new PEDebugInformation | ||
{ | ||
Timestamp = $"{peReader.PEHeaders.CoffHeader.TimeDateStamp:X8}" | ||
}; | ||
|
||
foreach (var entry in peReader.ReadDebugDirectory()) | ||
{ | ||
if (entry.Type == DebugDirectoryEntryType.CodeView) | ||
{ | ||
// Read the CodeView data | ||
var codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry); | ||
|
||
debugInfo.File = codeViewData.Path; | ||
debugInfo.Signature = codeViewData.Guid.ToString(); | ||
} | ||
|
||
if (entry.Type == DebugDirectoryEntryType.PdbChecksum) | ||
{ | ||
var checksumEntry = peReader.ReadPdbChecksumDebugDirectoryData(entry); | ||
var checksumHex = BitConverter.ToString(checksumEntry.Checksum.ToArray()).Replace("-", "").ToUpperInvariant(); | ||
debugInfo.Checksum = $"{checksumEntry.AlgorithmName}:{checksumHex}"; | ||
} | ||
} | ||
|
||
return debugInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.