From cdbf10ba8e64b06ce09701217d085ab173a11817 Mon Sep 17 00:00:00 2001 From: praydog Date: Sun, 25 Feb 2024 04:23:09 -0800 Subject: [PATCH] Configs: Add warning prompt when DLL is detected in the ZIP file --- UEVR/GameConfig.cs | 17 ++++++++++++++ UEVR/MainWindow.xaml.cs | 32 ++++++++++++++++++-------- UEVR/VDWarnDialog.xaml | 33 ++++++++++++++++++++++----- UEVR/VDWarnDialog.xaml.cs | 7 ++++++ UEVR/YesNoDialog.xaml | 47 +++++++++++++++++++++++++++++++++++++++ UEVR/YesNoDialog.xaml.cs | 35 +++++++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 15 deletions(-) create mode 100644 UEVR/YesNoDialog.xaml create mode 100644 UEVR/YesNoDialog.xaml.cs diff --git a/UEVR/GameConfig.cs b/UEVR/GameConfig.cs index 7be54a1..fed2cf7 100644 --- a/UEVR/GameConfig.cs +++ b/UEVR/GameConfig.cs @@ -62,6 +62,23 @@ private static string GetRelativePath(string fullPath, string basePath) { return fullPath.Substring(basePath.Length); } + public static bool ZipContainsDLL(string sourceArchiveFileName) { + try { + using (ZipArchive archive = ZipFile.OpenRead(sourceArchiveFileName)) { + foreach (ZipArchiveEntry entry in archive.Entries) { + if (entry.FullName.ToLower().EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { + return true; + } + } + } + } catch (Exception ex) { + Console.WriteLine($"An error occurred: {ex.Message}"); + } + + // No .DLL files found + return false; + } + public static string? ExtractZipToDirectory(string sourceArchiveFileName, string destinationDirectoryName, string gameName) { try { string tempExtractionPath = Path.Combine(destinationDirectoryName, "temp_extraction"); diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index 9791241..c8409e3 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -531,21 +531,35 @@ private void ImportConfig_Clicked(object sender, RoutedEventArgs e) { Directory.CreateDirectory(gameGlobalDir); } - var finalGameName = GameConfig.ExtractZipToDirectory(importPath, gameGlobalDir, gameName); + bool wantsExtract = true; - if (finalGameName == null) { - MessageBox.Show("Failed to extract the ZIP file."); - return; + if (GameConfig.ZipContainsDLL(importPath)) { + string message = "The selected config file includes a DLL (plugin), which may execute actions on your system.\n" + + "Only import configs with DLLs from trusted sources to avoid potential risks.\n" + + "Do you still want to proceed with the import?"; + var dialog = new YesNoDialog("DLL Warning", message); + dialog.ShowDialog(); + + wantsExtract = dialog.DialogResultYes; } - var finalDirectory = System.IO.Path.Combine(globalDir, finalGameName); - NavigateToDirectory(finalDirectory); + if (wantsExtract) { + var finalGameName = GameConfig.ExtractZipToDirectory(importPath, gameGlobalDir, gameName); - RefreshCurrentConfig(); + if (finalGameName == null) { + MessageBox.Show("Failed to extract the ZIP file."); + return; + } + var finalDirectory = System.IO.Path.Combine(globalDir, finalGameName); + NavigateToDirectory(finalDirectory); - if (m_connected) { - SharedMemory.SendCommand(SharedMemory.Command.ReloadConfig); + RefreshCurrentConfig(); + + + if (m_connected) { + SharedMemory.SendCommand(SharedMemory.Command.ReloadConfig); + } } } catch (Exception ex) { MessageBox.Show("An error occurred: " + ex.Message); diff --git a/UEVR/VDWarnDialog.xaml b/UEVR/VDWarnDialog.xaml index f7ac91a..39ac23f 100644 --- a/UEVR/VDWarnDialog.xaml +++ b/UEVR/VDWarnDialog.xaml @@ -15,11 +15,32 @@ WindowStartupLocation="CenterScreen" WindowStyle="None" Title="VD Warning" Height="200" Width="400"> - - - - -