From 5d8b7d9b3de68e6215c10b9fd223b7f1d5e40dea Mon Sep 17 00:00:00 2001 From: Noah Snelson Date: Sun, 3 Sep 2023 12:01:17 -0700 Subject: [PATCH] Port Mesa wrapper script from Autopatcher, patch openssl (#52) * Add logic to patch `libcrypto`/`libssl` if `PATCHOPENSSL` is set * Convert `File.Move` to `File.Copy`, add log for patching OpenSSL --- AM2RLauncher/AM2RLauncher.Gtk/Program.cs | 6 +++++- AM2RLauncher/AM2RLauncherLib/Profile.cs | 25 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs index 223c7a6..bf827ca 100644 --- a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs @@ -70,6 +70,10 @@ internal static class MainClass log.Info("On AppImage configuration."); #endif + #if PATCHOPENSSL + log.Info("On configuration for patching OpenSSL 1.0.0."); + #endif + try { Application gtkLauncher = new Application(Eto.Platforms.Gtk); @@ -96,4 +100,4 @@ internal static class MainClass MessageBox.Show($"{Language.Text.UnhandledException}\n*****Stack Trace*****\n\n{e.ExceptionObject}", "GTK", MessageBoxType.Error); }); } -} \ No newline at end of file +} diff --git a/AM2RLauncher/AM2RLauncherLib/Profile.cs b/AM2RLauncher/AM2RLauncherLib/Profile.cs index 00b51c7..e0e0643 100644 --- a/AM2RLauncher/AM2RLauncherLib/Profile.cs +++ b/AM2RLauncher/AM2RLauncherLib/Profile.cs @@ -481,7 +481,28 @@ public static class Profile log.Info("Linux specific formatting finished."); #if NOAPPIMAGE - // TODO: figure out a way to use patchelf to have users not rely on deprecated insecure ssl deps. + + #if PATCHOPENSSL + log.Info("Patching openssl 1.0.0..."); + + Process patchLibcryptoProcess = new Process(); + ProcessStartInfo patchLibcryptoStartInfo = new ProcessStartInfo { + UseShellExecute = false, + WorkingDirectory = tempPath, + FileName = "patchelf", + Arguments = $"\"{tempPath}/{exe}\" --replace-needed \"libcrypto.so.1.0.0\" \"libcurl.so\" --replace-needed \"libssl.so.1.0.0\" \"libcurl.so\"" + }; + + patchLibcryptoProcess.StartInfo = patchLibcryptoStartInfo; + patchLibcryptoProcess.Start(); + patchLibcryptoProcess.WaitForExit(); + + log.Info("Patched openssl."); + + #endif + + File.Move($"{tempPath}/{exe}", $"{tempPath}/.runner-unwrapped"); + File.Copy($"{Core.PatchDataPath}/data/mesa-wrapper.sh", $"{tempPath}/runner"); #else // Copy AppImage template to here HelperMethods.DirectoryCopy($"{Core.PatchDataPath}/data/AM2R.AppDir", $"{tempPath}/AM2R.AppDir/"); @@ -867,4 +888,4 @@ public static class Profile log.Info($"Profile {profile.Name} process exited."); } -} \ No newline at end of file +}