Skip to content

Commit 42f7277

Browse files
committed
add protection from running as admin
1 parent ced7d15 commit 42f7277

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Ps3DiscDumper/Dumper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ namespace Ps3DiscDumper
2626
{
2727
public class Dumper: IDisposable
2828
{
29-
public const string Version = "3.3.3";
29+
public const string Version = "3.3.4";
3030

31-
private static readonly Regex VersionParts = new Regex(@"(?<ver>\d+(\.\d+){0,2})[ \-]*(?<pre>.*)", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
31+
private static readonly Regex VersionParts = new(@"(?<ver>\d+(\.\d+){0,2})[ \-]*(?<pre>.*)", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
3232
private static readonly HashSet<char> InvalidChars = new(Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()));
3333
private static readonly char[] MultilineSplit = {'\r', '\n'};
3434
private long currentSector;

UI.WinForms.Msil/Program.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices;
26
using System.Windows.Forms;
37

48
namespace UI.WinForms.Msil
@@ -9,11 +13,22 @@ static class Program
913
/// The main entry point for the application.
1014
/// </summary>
1115
[STAThread]
12-
static void Main()
16+
static void Main(string[] args)
1317
{
1418
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
1519
Application.EnableVisualStyles();
1620
Application.SetCompatibleTextRenderingDefault(false);
21+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
22+
{
23+
using var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
24+
var principal = new System.Security.Principal.WindowsPrincipal(identity);
25+
if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)
26+
&& !args.Any(p => p.Equals("/IUnderstandThatRunningSoftwareAsAdministratorIsDangerousAndNotRecommendedForAnyone")))
27+
{
28+
MessageBox.Show("Please do not run software as Administrator unless application was designed to properly handle it, and it is explicitly required.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
29+
Environment.Exit(-1);
30+
}
31+
}
1732
Application.Run(new MainForm());
1833
}
1934
}

0 commit comments

Comments
 (0)