From e42f85183e8f5d163c4e3ed9d55270f739d306d6 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Tue, 4 Jun 2019 08:27:55 -0500 Subject: [PATCH] First run now makes sure permissions are workable --- IPA.Injector/IPA.Injector.csproj | 1 + IPA.Injector/Injector.cs | 3 ++ IPA.Injector/PermissionFix.cs | 65 +++++++++++++++++++++++++++++++ Refs/Assembly-CSharp.dll | Bin 634368 -> 634368 bytes Refs/Unity.TextMeshPro.dll | Bin 84480 -> 84480 bytes 5 files changed, 69 insertions(+) create mode 100644 IPA.Injector/PermissionFix.cs diff --git a/IPA.Injector/IPA.Injector.csproj b/IPA.Injector/IPA.Injector.csproj index 4ce26d0b..12dfc25d 100644 --- a/IPA.Injector/IPA.Injector.csproj +++ b/IPA.Injector/IPA.Injector.csproj @@ -56,6 +56,7 @@ + diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index f9a55974..8a8bb50b 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -19,6 +19,7 @@ namespace IPA.Injector public static class Injector { private static Task pluginAsyncLoadTask; + private static Task permissionFixTask; // ReSharper disable once UnusedParameter.Global public static void Main(string[] args) @@ -62,6 +63,7 @@ namespace IPA.Injector LibLoader.SetupAssemblyFilenames(true); pluginAsyncLoadTask = PluginLoader.LoadTask(); + permissionFixTask = PermissionFix.FixPermissions(new DirectoryInfo(Environment.CurrentDirectory)); } catch (Exception e) { @@ -264,6 +266,7 @@ namespace IPA.Injector { // wait for plugins to finish loading pluginAsyncLoadTask.Wait(); + permissionFixTask.Wait(); log.Debug("Plugins loaded"); log.Debug(string.Join(", ", PluginLoader.PluginsMetadata)); PluginComponent.Create(); diff --git a/IPA.Injector/PermissionFix.cs b/IPA.Injector/PermissionFix.cs new file mode 100644 index 00000000..bd8c4723 --- /dev/null +++ b/IPA.Injector/PermissionFix.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.AccessControl; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; + +namespace IPA.Injector +{ + internal static class PermissionFix + { + public static Task FixPermissions(DirectoryInfo root) + { + if (!root.Exists) return Task.CompletedTask; + + return Task.Run(() => + { + try + { + var acl = root.GetAccessControl(); + + var rules = acl.GetAccessRules(true, true, typeof(SecurityIdentifier)); + + var requestedRights = FileSystemRights.Modify; + var requestedInheritance = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit; + var requestedPropagation = PropagationFlags.InheritOnly; + + bool hasRule = false; + for (var i = 0; i < rules.Count; i++) + { + var rule = rules[i]; + + if (rule is FileSystemAccessRule fsrule + && fsrule.AccessControlType == AccessControlType.Allow + && fsrule.InheritanceFlags.HasFlag(requestedInheritance) + && fsrule.PropagationFlags == requestedPropagation + && fsrule.FileSystemRights.HasFlag(requestedRights)) + { hasRule = true; break; } + } + + if (!hasRule) + { // this is *sooo* fucking slow on first run + acl.AddAccessRule( + new FileSystemAccessRule( + new SecurityIdentifier(WellKnownSidType.WorldSid, null), + requestedRights, + requestedInheritance, + requestedPropagation, + AccessControlType.Allow + ) + ); + root.SetAccessControl(acl); + } + } + catch (Exception e) + { + Logging.Logger.log.Warn("Error configuring permissions in the game install dir"); + Logging.Logger.log.Warn(e); + } + }); + } + } +} diff --git a/Refs/Assembly-CSharp.dll b/Refs/Assembly-CSharp.dll index f560a39b2c9388203add6c5dde1ef874e25866b0..40b6c6cdeaa1b4db75b56360620d60d8803fdc82 100644 GIT binary patch delta 62 zcmV-E0Kxx&+$MnBCXk2%P0xXfg^B@%iUNg-1BHqNg^C4*iUx&>2epa_D&-IcDJfBN U@tjVm!5R~7=o3@7#N`M)$Scno2epa_D&-I*0Vb%! UtfNMZ`Gv!}bf?9)#N`M)$Vv+wUH||9 diff --git a/Refs/Unity.TextMeshPro.dll b/Refs/Unity.TextMeshPro.dll index 8a8bce24e0d0ea4c0681970eaa2588777ab114f6..8cbb46063a7aef5ea9626382bf1d7d90d0f1aee1 100644 GIT binary patch delta 41 xcmZpe!rCx}bwUS|*ZIb-tzC?EY6A1V%4I8_J>lGc>`AR+#y+O)H`Ew4lmTrC5jp?> delta 41 xcmZpe!rCx}bwUSI!}7+itzC?EY634qSd26m6*){uZLne9mN