mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix elevated pipe access rights
This commit is contained in:
@@ -81,7 +81,14 @@ public sealed partial class App : Application
|
||||
LogDiagnosticInformation();
|
||||
|
||||
// Manually invoke
|
||||
activation.Activate(HutaoActivationArguments.FromAppActivationArguments(activatedEventArgs));
|
||||
HutaoActivationArguments hutaoArgs = HutaoActivationArguments.FromAppActivationArguments(activatedEventArgs);
|
||||
if (hutaoArgs.Kind is HutaoActivationKind.Toast)
|
||||
{
|
||||
Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
activation.Activate(hutaoArgs);
|
||||
activation.PostInitialization();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -50,13 +50,6 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
|
||||
/// <inheritdoc/>
|
||||
public void Activate(HutaoActivationArguments args)
|
||||
{
|
||||
// Before activate, we try to redirect to the opened process in App,
|
||||
// And we check if it's a toast activation.
|
||||
if (args.Kind is HutaoActivationKind.Toast)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HandleActivationAsync(args).SafeForget();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,42 @@ using System.Security.Principal;
|
||||
namespace Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
|
||||
[Injection(InjectAs.Singleton)]
|
||||
[ConstructorGenerated]
|
||||
internal sealed partial class PrivateNamedPipeServer : IDisposable
|
||||
{
|
||||
private readonly PrivateNamedPipeMessageDispatcher messageDispatcher;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
private readonly NamedPipeServerStream serverStream = new("Snap.Hutao.PrivateNamedPipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
|
||||
|
||||
private readonly CancellationTokenSource serverTokenSource = new();
|
||||
private readonly SemaphoreSlim serverSemaphore = new(1);
|
||||
|
||||
private readonly NamedPipeServerStream serverStream;
|
||||
|
||||
public PrivateNamedPipeServer(IServiceProvider serviceProvider)
|
||||
{
|
||||
messageDispatcher = serviceProvider.GetRequiredService<PrivateNamedPipeMessageDispatcher>();
|
||||
runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
|
||||
|
||||
PipeSecurity? pipeSecurity = default;
|
||||
|
||||
if (runtimeOptions.IsElevated)
|
||||
{
|
||||
SecurityIdentifier everyOne = new(WellKnownSidType.WorldSid, null);
|
||||
|
||||
pipeSecurity = new();
|
||||
pipeSecurity.AddAccessRule(new PipeAccessRule(everyOne, PipeAccessRights.FullControl, AccessControlType.Allow));
|
||||
}
|
||||
|
||||
serverStream = NamedPipeServerStreamAcl.Create(
|
||||
"Snap.Hutao.PrivateNamedPipe",
|
||||
PipeDirection.InOut,
|
||||
NamedPipeServerStream.MaxAllowedServerInstances,
|
||||
PipeTransmissionMode.Byte,
|
||||
PipeOptions.Asynchronous | PipeOptions.WriteThrough,
|
||||
0,
|
||||
0,
|
||||
pipeSecurity);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
serverTokenSource.Cancel();
|
||||
@@ -33,17 +60,6 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
|
||||
{
|
||||
using (await serverSemaphore.EnterAsync(serverTokenSource.Token).ConfigureAwait(false))
|
||||
{
|
||||
if (runtimeOptions.IsElevated)
|
||||
{
|
||||
SecurityIdentifier everyOne = new(WellKnownSidType.WorldSid, null);
|
||||
SecurityIdentifier users = new(WellKnownSidType.BuiltinUsersSid, null);
|
||||
|
||||
PipeSecurity pipeSecurity = new();
|
||||
pipeSecurity.AddAccessRule(new PipeAccessRule(everyOne, PipeAccessRights.ReadWrite, AccessControlType.Allow));
|
||||
pipeSecurity.AddAccessRule(new PipeAccessRule(users, PipeAccessRights.ReadWrite, AccessControlType.Allow));
|
||||
serverStream.SetAccessControl(pipeSecurity);
|
||||
}
|
||||
|
||||
while (!serverTokenSource.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"Snap.Hutao": {
|
||||
"commandName": "MsixPackage",
|
||||
"nativeDebugging": false,
|
||||
"doNotLaunchApp": false,
|
||||
"doNotLaunchApp": true,
|
||||
"allowLocalNetworkLoopbackProperty": true
|
||||
},
|
||||
"[Unpackaged] Snap.Hutao": {
|
||||
|
||||
Reference in New Issue
Block a user