Skip to content

Commit

Permalink
Better path anonymization
Browse files Browse the repository at this point in the history
Added HTML tags and OS info
  • Loading branch information
Aragas committed Sep 27, 2024
1 parent 27e266f commit 99e70c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ private static string GetBase(CrashReportModel crashReport, IEnumerable<LogSourc
return $$"""
<html>
<head>
<title>{{crashReport.Metadata.GameName}} Crash Report</title>
<meta charset='utf-8' />
<title>{{crashReport.Metadata.GameName}} Crash Report</title>
<meta name='description' content='{{crashReport.Metadata.GameName}} Crash Report File.'>
<meta http-equiv='content-language' content='en-gb'>
<style>
.headers {
font-family: 'Consolas', monospace;
Expand Down Expand Up @@ -85,6 +87,7 @@ private static string GetBase(CrashReportModel crashReport, IEnumerable<LogSourc
<![endif]>
</head>
<body style='background-color: #ececec;'>
<h1 style='display: none;'>{{crashReport.Metadata.GameName}} Crash Report</h1>
<table style='width: 100%;'>
<tbody>
<tr>
Expand All @@ -100,6 +103,7 @@ Most likely this error was caused by a custom installed module.
If you were in the middle of something, the progress might be lost.
<br />
<br />
Operating System: {{crashReport.Metadata.OperatingSystemType}} ({{crashReport.Metadata.OperatingSystemVersion}})
Launcher: {{crashReport.Metadata.LauncherType}} ({{crashReport.Metadata.LauncherVersion}})
<br />
Runtime: {{crashReport.Metadata.Runtime}}
Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.CrashReport/CrashReportInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static CrashReportModel ToModel(CrashReportInfo crashReport,
var metadata = crashReportMetadataProvider.GetCrashReportMetadataModel(crashReport);
metadata.Runtime ??= System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
var process = Process.GetCurrentProcess();
var nativeModules = NativeModuleUtils.CollectModules(process);
var nativeModules = NativeModuleUtils.CollectModules(process, pathAnonymizer);
var nativeAssemblies = nativeModules.Select(x => new NativeAssemblyModel
{
Id = new AssemblyIdModel
Expand Down
8 changes: 6 additions & 2 deletions src/BUTR.CrashReport/Utils/NativeModuleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
using BUTR.CrashReport.Interfaces;

namespace BUTR.CrashReport.Utils;

Expand All @@ -20,7 +21,7 @@ internal static class NativeModuleUtils
private static readonly byte[] MachOMagic = [0xFE, 0xED, 0xFA, 0xCE];
private static readonly byte[] MachOMagic64 = [0xFE, 0xED, 0xFA, 0xCF];

public static List<NativeModule> CollectModules(Process process) => process.Modules.OfType<ProcessModule>().Select(x =>
public static List<NativeModule> CollectModules(Process process, IPathAnonymizer pathAnonymizer) => process.Modules.OfType<ProcessModule>().Select(x =>
{
try
{
Expand All @@ -45,7 +46,10 @@ public static List<NativeModule> CollectModules(Process process) => process.Modu

var version = x.FileVersionInfo.FileVersion ?? x.FileVersionInfo.ProductVersion;

return new NativeModule(x.ModuleName, Anonymizer.AnonymizePath(x.FileName), version, arch, (uint) fs.Length, x.BaseAddress, (uint) x.ModuleMemorySize, hash);
if (!pathAnonymizer.TryHandlePath(x.FileName, out var anonymizedPath))
anonymizedPath = Anonymizer.AnonymizePath(x.FileName);

return new NativeModule(x.ModuleName, anonymizedPath, version, arch, (uint) fs.Length, x.BaseAddress, (uint) x.ModuleMemorySize, hash);
}
catch
{
Expand Down

0 comments on commit 99e70c6

Please sign in to comment.