From b8d63d1a1132878f283bba9281ac1dce3b8c3cd1 Mon Sep 17 00:00:00 2001 From: Gustave Monce Date: Tue, 24 Dec 2019 08:36:20 +0100 Subject: [PATCH] Fixed an issue regarding ACLs and Sahara handling --- FilePickerControl.xaml.cs | 12 ++++++++---- Models/NativeMethods.cs | 2 -- Models/PatchEngine.cs | 14 ++++++++++---- Models/QualcommSahara.cs | 2 +- Views/BusyView.xaml | 22 ++++++++++++---------- WPinternals.Core.csproj | 7 ++++--- WPinternals.Core.csproj.user | 2 +- 7 files changed, 36 insertions(+), 25 deletions(-) diff --git a/FilePickerControl.xaml.cs b/FilePickerControl.xaml.cs index ac728ce..334b177 100644 --- a/FilePickerControl.xaml.cs +++ b/FilePickerControl.xaml.cs @@ -155,7 +155,8 @@ namespace WPinternals FlowDirection.LeftToRight, new Typeface(PathTextBlock.FontFamily, PathTextBlock.FontStyle, PathTextBlock.FontWeight, PathTextBlock.FontStretch), FontSize, - Foreground + Foreground, + 100 / 96 ); resultSize.Height = formatted.Height; @@ -175,7 +176,8 @@ namespace WPinternals FlowDirection.LeftToRight, new Typeface(CaptionTextBlock.FontFamily, CaptionTextBlock.FontStyle, CaptionTextBlock.FontWeight, CaptionTextBlock.FontStretch), FontSize, - Foreground + Foreground, + 100 / 96 ); double CaptionWidth = formatted.Width; if (CaptionWidth > 0) @@ -203,7 +205,8 @@ namespace WPinternals FlowDirection.LeftToRight, new Typeface(PathTextBlock.FontFamily, PathTextBlock.FontStyle, PathTextBlock.FontWeight, PathTextBlock.FontStretch), FontSize, - Foreground + Foreground, + 100 / 96 ); if (NewWidth < 0) @@ -275,7 +278,8 @@ namespace WPinternals FlowDirection.LeftToRight, new Typeface(PathTextBlock.FontFamily, PathTextBlock.FontStyle, PathTextBlock.FontWeight, PathTextBlock.FontStretch), FontSize, - Foreground + Foreground, + 100 / 96 ); widthOK = formatted.Width < MaxWidth; diff --git a/Models/NativeMethods.cs b/Models/NativeMethods.cs index 07ae6eb..53adc30 100644 --- a/Models/NativeMethods.cs +++ b/Models/NativeMethods.cs @@ -267,10 +267,8 @@ namespace WPinternals public static extern bool DeviceIoControl( IntPtr hDevice, uint IoControlCode, - [MarshalAs(UnmanagedType.AsAny)] [In] object InBuffer, uint nInBufferSize, - [MarshalAs(UnmanagedType.AsAny)] [Out] object OutBuffer, uint nOutBufferSize, ref uint pBytesReturned, diff --git a/Models/PatchEngine.cs b/Models/PatchEngine.cs index 376de7a..7c81d51 100644 --- a/Models/PatchEngine.cs +++ b/Models/PatchEngine.cs @@ -413,6 +413,8 @@ namespace WPinternals { if (FilePath.Contains(':')) { + FileInfo fileInfo = new FileInfo(FilePath); + // Enable Take Ownership AND Restore ownership to original owner // Take Ownership Privilge is not enough. // We need Restore Privilege. @@ -427,17 +429,18 @@ namespace WPinternals } // Backup original owner and ACL - - OriginalACL = new FileSecurity(FilePath, AccessControlSections.Owner | AccessControlSections.Group | AccessControlSections.Access); + OriginalACL = fileInfo.GetAccessControl(); // And take the original security to create new security rules. - FileSecurity NewACL = new FileSecurity(FilePath, AccessControlSections.Owner | AccessControlSections.Group | AccessControlSections.Access); + FileSecurity NewACL = fileInfo.GetAccessControl(); // Take ownership NewACL.SetOwner(WindowsIdentity.GetCurrent().User); + fileInfo.SetAccessControl(NewACL); // And create a new access rule NewACL.SetAccessRule(new FileSystemAccessRule(WindowsIdentity.GetCurrent().User, FileSystemRights.FullControl, AccessControlType.Allow)); + fileInfo.SetAccessControl(NewACL); // Open the file for patching Stream = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite); @@ -457,10 +460,13 @@ namespace WPinternals if (FilePath.Contains(':')) { + FileInfo fileInfo = new FileInfo(FilePath); + // Restore original owner and access rules. // The OriginalACL cannot be reused directly. - FileSecurity NewACL = new FileSecurity(FilePath, AccessControlSections.Owner | AccessControlSections.Group | AccessControlSections.Access); + FileSecurity NewACL = fileInfo.GetAccessControl(); NewACL.SetSecurityDescriptorBinaryForm(OriginalACL.GetSecurityDescriptorBinaryForm()); + fileInfo.SetAccessControl(NewACL); // Revert to self RestorePrivilege.Revert(); diff --git a/Models/QualcommSahara.cs b/Models/QualcommSahara.cs index 3b75924..e75dca8 100644 --- a/Models/QualcommSahara.cs +++ b/Models/QualcommSahara.cs @@ -320,7 +320,7 @@ namespace WPinternals { LogFile.Log("Problem while starting programmer. Attempting again.", LogType.FileAndConsole); } - } while (!Started || count >= 3); + } while (!Started || count < 3); if (count >= 3 && !Started) { LogFile.Log("Maximum number of attempts to start the programmer exceeded.", LogType.FileAndConsole); diff --git a/Views/BusyView.xaml b/Views/BusyView.xaml index 645f600..3679a55 100644 --- a/Views/BusyView.xaml +++ b/Views/BusyView.xaml @@ -48,16 +48,18 @@ DEALINGS IN THE SOFTWARE. - - - - - - - - - - + + + + + + + + + + + + diff --git a/WPinternals.Core.csproj b/WPinternals.Core.csproj index 358dace..53284b1 100644 --- a/WPinternals.Core.csproj +++ b/WPinternals.Core.csproj @@ -32,10 +32,11 @@ - + - - + + + diff --git a/WPinternals.Core.csproj.user b/WPinternals.Core.csproj.user index fd91379..c38f68c 100644 --- a/WPinternals.Core.csproj.user +++ b/WPinternals.Core.csproj.user @@ -1,7 +1,7 @@  - <_LastSelectedProfileId>G:\Projects\WPinternals\Properties\PublishProfiles\FolderProfile.pubxml + <_LastSelectedProfileId>M:\Projects\WPinternals\Properties\PublishProfiles\FolderProfile.pubxml