Skip to content

Commit

Permalink
Fixed path anonymization and normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Oct 4, 2024
1 parent 6fdb180 commit 708cc43
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/BUTR.CrashReport/CrashReportInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ public static CrashReportInfo Create(Exception exception, Dictionary<string, str
/// Creates the CrashReportInfo based on initial crash report data.
/// </summary>
private CrashReportInfo(Exception exception, Dictionary<string, string> additionalMetadata,
IStacktraceFilter stacktraceFilter, IAssemblyUtilities assemblyUtilities,
IModuleProvider moduleProvider, ILoaderPluginProvider loaderPluginProvider, IHarmonyProvider harmonyProvider)
IStacktraceFilter stacktraceFilter,
IAssemblyUtilities assemblyUtilities,
IModuleProvider moduleProvider,
ILoaderPluginProvider loaderPluginProvider,
IHarmonyProvider harmonyProvider)
{
var assemblies = assemblyUtilities.Assemblies().ToArray();

Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.CrashReport/Utils/Anonymizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void Add(string? path, string name)
/// <returns>The anonymized path.</returns>
public static string AnonymizePath(string path)
{
var normalizedPath = path;
var normalizedPath = path.NormalizePath();
var entries = SplitWithIndex(normalizedPath, Path.DirectorySeparatorChar);

foreach (var kv in AnonymizationPaths)
Expand Down
7 changes: 4 additions & 3 deletions src/BUTR.CrashReport/Utils/CrashReportModelUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ static bool IsProtectedFromDisassembly(Assembly assembly)

type = assemblyUtilities.GetAssemblyType(type, crashReport, assembly);

var anonymizedPath = !assembly.IsDynamic ? assembly.Location : string.Empty;
if (!assembly.IsDynamic && !pathAnonymizer.TryHandlePath(anonymizedPath, out anonymizedPath))
anonymizedPath = Anonymizer.AnonymizePath(anonymizedPath);
var path = !assembly.IsDynamic ? assembly.Location : string.Empty;
var anonymizedPath = string.Empty;
if (!assembly.IsDynamic && !pathAnonymizer.TryHandlePath(path, out anonymizedPath))
anonymizedPath = Anonymizer.AnonymizePath(path);

assemblyModels.Add(new()
{
Expand Down
6 changes: 4 additions & 2 deletions src/BUTR.CrashReport/Utils/NativeModuleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public static List<NativeModule> CollectModules(Process process, IPathAnonymizer

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

if (!pathAnonymizer.TryHandlePath(x.FileName, out var anonymizedPath))
anonymizedPath = Anonymizer.AnonymizePath(x.FileName);
var path = x.FileName;
var anonymizedPath = string.Empty;
if (!pathAnonymizer.TryHandlePath(path, out anonymizedPath))
anonymizedPath = Anonymizer.AnonymizePath(path);

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

0 comments on commit 708cc43

Please sign in to comment.