Skip to content

Commit 3c65bd6

Browse files
committed
Brush up
1 parent 213177d commit 3c65bd6

3 files changed

Lines changed: 8 additions & 86 deletions

File tree

‎src/Files.App/Data/Contracts/IWindowsSecurityService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public interface IWindowsSecurityService
1111
/// <summary>
1212
/// Gets a value that indicates whether the application is elevated.
1313
/// </summary>
14-
/// <returns>Returns true if the application is elevated via UAC prompt OR the application is elevated by default because the user, who launched the application, is in Administrators group; otherwise, false.</returns>
14+
/// <returns>Returns true if the application is elevated; otherwise, false.</returns>
1515
bool IsAppElevated();
1616

1717
/// <summary>
1818
/// Gets a value that indicates whether the application can drag &amp; drop.
1919
/// </summary>
2020
/// <remarks>
21-
/// Drag &amp; drop onto an elevated app is not allowed (just crashes) due to the Windows limitation by its design.
21+
/// Drag &amp; drop onto an elevated app is not allowed (just crashes) due to UIPI.
2222
/// <br/>
2323
/// <br/>
2424
/// For more info, visit:

‎src/Files.App/NativeMethods.txt‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,3 @@ DesktopWallpaper
9494
SHCreateShellItemArrayFromIDLists
9595
ILCreateFromPath
9696
CLSIDFromString
97-
AllocateAndInitializeSid
98-
CheckTokenMembership
99-
FreeSid
100-
GetCurrentProcessToken
101-
GetTokenInformation
102-
LocalAlloc
103-
CloseHandle
104-
TOKEN_ELEVATION_TYPE
105-
TOKEN_ELEVATION
106-
GetCurrentProcess
107-
OpenProcessToken
Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Microsoft.Extensions.Logging;
5-
using Windows.Win32;
6-
using Windows.Win32.Foundation;
7-
using Windows.Win32.Security;
8-
using Windows.Win32.System.Memory;
9-
104
namespace Files.App.Services
115
{
126
/// <inheritdoc cref="IWindowsSecurityService"/>
@@ -22,80 +16,19 @@ public unsafe bool IsAppElevated()
2216
}
2317

2418
/// <inheritdoc/>
25-
public bool IsElevationRequired(string path)
19+
public unsafe bool CanDragAndDrop()
2620
{
27-
if (string.IsNullOrEmpty(path))
28-
return false;
29-
30-
// TODO: Use PInvoke partial class in a separate project
31-
return Win32PInvoke.IsElevationRequired(path);
21+
return !IsAppElevated();
3222
}
3323

3424
/// <inheritdoc/>
35-
public unsafe bool CanDragAndDrop()
25+
public bool IsElevationRequired(string path)
3626
{
37-
//HANDLE hToken = default;
38-
//uint cbTokenInfo = 0u;
39-
//TOKEN_ELEVATION_TYPE* pTokenElevationTypeInfo = default;
40-
//TOKEN_ELEVATION* pTokenElevationInfo = default;
41-
42-
try
43-
{
44-
//if (!PInvoke.OpenProcessToken(PInvoke.GetCurrentProcess(), TOKEN_ACCESS_MASK.TOKEN_QUERY, &hToken))
45-
//{
46-
// throw new InvalidOperationException();
47-
//}
48-
49-
//// Get size of TOKEN_ELEVATION_TYPE first
50-
//PInvoke.GetTokenInformation(hToken, TOKEN_INFORMATION_CLASS.TokenElevationType, null, 0, &cbTokenInfo);
51-
52-
//// Allocate TOKEN_ELEVATION_TYPE
53-
//pTokenElevationTypeInfo = (TOKEN_ELEVATION_TYPE*)PInvoke.LocalAlloc(LOCAL_ALLOC_FLAGS.LPTR, cbTokenInfo);
54-
//if (pTokenElevationTypeInfo == null)
55-
//{
56-
// PInvoke.CloseHandle(hToken);
57-
// throw new InvalidOperationException();
58-
//}
59-
60-
//// Get the actual TOKEN_ELEVATION_TYPE
61-
//PInvoke.GetTokenInformation(hToken, TOKEN_INFORMATION_CLASS.TokenElevationType, pTokenElevationTypeInfo, cbTokenInfo, &cbTokenInfo);
62-
63-
//// Get size of TOKEN_ELEVATION first
64-
//PInvoke.GetTokenInformation(hToken, TOKEN_INFORMATION_CLASS.TokenElevation, null, 0, &cbTokenInfo);
65-
66-
//// Allocate TOKEN_ELEVATION
67-
//pTokenElevationInfo = (TOKEN_ELEVATION*)PInvoke.LocalAlloc(LOCAL_ALLOC_FLAGS.LPTR, cbTokenInfo);
68-
//if (pTokenElevationInfo == null)
69-
//{
70-
// PInvoke.CloseHandle(hToken);
71-
// throw new InvalidOperationException();
72-
//}
73-
74-
//// Get the actual TOKEN_ELEVATION
75-
//PInvoke.GetTokenInformation(hToken, TOKEN_INFORMATION_CLASS.TokenElevation, pTokenElevationInfo, cbTokenInfo, &cbTokenInfo);
76-
77-
//// UAC is fully disabled
78-
// if (*pTokenElevationTypeInfo is TOKEN_ELEVATION_TYPE.TokenElevationTypeDefault &&
79-
// pTokenElevationInfo->TokenIsElevated == 1u)
80-
// return false;
81-
82-
return !IsAppElevated();
83-
}
84-
catch (Exception ex)
85-
{
86-
App.Logger.LogWarning(ex, ex.Message);
87-
88-
// Disable it, just in case
27+
if (string.IsNullOrEmpty(path))
8928
return false;
90-
}
91-
finally
92-
{
93-
//if (pTokenElevationTypeInfo is not null)
94-
// PInvoke.LocalFree((HLOCAL)pTokenElevationTypeInfo);
9529

96-
//if (pTokenElevationInfo is not null)
97-
// PInvoke.LocalFree((HLOCAL)pTokenElevationInfo);
98-
}
30+
// TODO: Use PInvoke partial class in a separate project
31+
return Win32PInvoke.IsElevationRequired(path);
9932
}
10033
}
10134
}

0 commit comments

Comments
 (0)