From 45f5d1f27b52a663aa57c9618278d8f0e461cbaf Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Mon, 30 Sep 2024 10:12:22 +0300 Subject: [PATCH] Added Wine detection Fixed Launcher line rendering on HTML --- .../CrashReportCreatorHelper.cs | 10 ++++++++++ src/BUTR.CrashReport.Models/OperatingSystemType.cs | 5 +++++ .../CrashReportHtml.Html.cs | 1 + .../Renderer/ImGuiRenderer.01.Summary.cs | 3 ++- src/BUTR.CrashReport/Utils/NativeModuleUtils.cs | 6 +++--- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs b/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs index f1af0f6..bb8e19f 100644 --- a/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs +++ b/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs @@ -140,7 +140,12 @@ public virtual CrashReportMetadataModel GetCrashReportMetadataModel(CrashReportI private OperatingSystemType GetOperatingSystemType() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var handle = GetModuleHandle("ntdll.dll"); + if (handle != IntPtr.Zero && GetProcAddress(handle, "wine_get_version") != IntPtr.Zero) + return OperatingSystemType.WindowsOnWine; return OperatingSystemType.Windows; + } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return OperatingSystemType.Linux; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -159,7 +164,12 @@ private OperatingSystemType GetOperatingSystemType() return null; } + [DllImport("kernel32", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true)] + static extern IntPtr GetProcAddress(IntPtr hModule, string procName); + [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)] + public static extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPWStr)] string lpModuleName); + [DllImport("ntdll.dll", SetLastError = true)] private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); [StructLayout(LayoutKind.Sequential)] diff --git a/src/BUTR.CrashReport.Models/OperatingSystemType.cs b/src/BUTR.CrashReport.Models/OperatingSystemType.cs index d1a0d1d..9cc6ded 100644 --- a/src/BUTR.CrashReport.Models/OperatingSystemType.cs +++ b/src/BUTR.CrashReport.Models/OperatingSystemType.cs @@ -24,4 +24,9 @@ public enum OperatingSystemType /// MacOS operating system. /// MacOS = 3, + + /// + /// Wine emulating a Windows operating system. + /// + WindowsOnWine = 4, } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs b/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs index c1738c3..70ed529 100644 --- a/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs +++ b/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs @@ -104,6 +104,7 @@ Most likely this error was caused by a custom installed module.

Operating System: {{crashReport.Metadata.OperatingSystemType.ToString()}} ({{crashReport.Metadata.OperatingSystemVersion}}) +
Launcher: {{crashReport.Metadata.LauncherType}} ({{crashReport.Metadata.LauncherVersion}})
Runtime: {{crashReport.Metadata.Runtime}} diff --git a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.01.Summary.cs b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.01.Summary.cs index e2d1808..0893ab1 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.01.Summary.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.01.Summary.cs @@ -8,6 +8,7 @@ partial class ImGuiRenderer "Windows"u8.ToArray(), // Windows "Linux"u8.ToArray(), // Linux "MacOS"u8.ToArray(), // MacOS + "Windows on Wine"u8.ToArray(), // WindowsWine ]; private bool _addScreenshots; @@ -75,7 +76,7 @@ private void RenderSummary() _imgui.Text("If you were in the middle of something, the progress might be lost.\0"u8); _imgui.NewLine(); - + _imgui.TextSameLine("Operating System: \0"u8); _imgui.TextSameLine(_operatingSystemTypeNames[(int) _crashReport.Metadata.OperatingSystemType]); _imgui.TextSameLine(" (\0"u8); diff --git a/src/BUTR.CrashReport/Utils/NativeModuleUtils.cs b/src/BUTR.CrashReport/Utils/NativeModuleUtils.cs index 0462ea2..0cb5a6d 100644 --- a/src/BUTR.CrashReport/Utils/NativeModuleUtils.cs +++ b/src/BUTR.CrashReport/Utils/NativeModuleUtils.cs @@ -1,4 +1,5 @@ -using BUTR.CrashReport.Models; +using BUTR.CrashReport.Interfaces; +using BUTR.CrashReport.Models; using ELFSharp.ELF; using ELFSharp.MachO; @@ -9,7 +10,6 @@ using System.IO; using System.Linq; using System.Reflection.PortableExecutable; -using BUTR.CrashReport.Interfaces; namespace BUTR.CrashReport.Utils; @@ -48,7 +48,7 @@ public static List CollectModules(Process process, IPathAnonymizer 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