├── UWPSettingsEditor_Demo.png
├── src
├── UWPSettingsEditor
│ ├── Assets
│ │ ├── Exit_16x.png
│ │ ├── OpenFile_16x.png
│ │ ├── RegistryIcon.png
│ │ └── Close_White_16x.png
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── Interfaces
│ │ └── IValueDataSet.cs
│ ├── packages.config
│ ├── App.xaml.cs
│ ├── Program.cs
│ ├── Controls
│ │ ├── DateTimeOffsetComponent.xaml
│ │ ├── StringComponent.xaml
│ │ ├── IntComponent.xaml
│ │ ├── StringComponent.xaml.cs
│ │ ├── BooleanComponent.xaml
│ │ ├── BooleanComponent.xaml.cs
│ │ ├── DateTimeOffsetComponent.xaml.cs
│ │ ├── CharComponent.xaml
│ │ ├── GuidComponent.xaml
│ │ ├── PointSizeComponent.xaml
│ │ ├── Basic
│ │ │ └── DateTimePicker.xaml
│ │ ├── GuidComponent.xaml.cs
│ │ ├── RectComponent.xaml
│ │ ├── CharComponent.xaml.cs
│ │ ├── RectComponent.xaml.cs
│ │ ├── PointSizeComponent.xaml.cs
│ │ └── IntComponent.xaml.cs
│ ├── Windows
│ │ ├── AboutWindow.xaml
│ │ ├── AboutWindow.xaml.cs
│ │ ├── EditValueWindow.xaml
│ │ ├── CreateValueWindow.xaml
│ │ ├── EditValueWindow.xaml.cs
│ │ └── CreateValueWindow.xaml.cs
│ ├── App.config
│ ├── Converters
│ │ ├── TreeViewLineConverter.cs
│ │ └── DataTypeEnumToStringConverter.cs
│ ├── Registry
│ │ ├── Util
│ │ │ ├── Sizes.cs
│ │ │ ├── MathUtilities.cs
│ │ │ ├── Range.cs
│ │ │ └── Numbers.cs
│ │ ├── Ownership.cs
│ │ ├── ValueFlags.cs
│ │ ├── Internal
│ │ │ ├── SetupHelper.cs
│ │ │ ├── UnixFileType.cs
│ │ │ ├── FileLocator.cs
│ │ │ ├── FileOpenEventArgs.cs
│ │ │ └── LocalFileLocator.cs
│ │ ├── Interfaces
│ │ │ ├── IByteArraySerializable.cs
│ │ │ └── IBuffer.cs
│ │ ├── BinHeader.cs
│ │ ├── RegistryValueType.cs
│ │ ├── RegistryCorruptException.cs
│ │ ├── Cell.cs
│ │ ├── ListCell.cs
│ │ ├── RegistryKeyFlags.cs
│ │ ├── SecurityCell.cs
│ │ ├── ValueCell.cs
│ │ ├── HiveHeader.cs
│ │ └── KeyNodeCell.cs
│ ├── Classes
│ │ ├── PrimitiveStructs.cs
│ │ ├── NativeMethods.cs
│ │ ├── Models.cs
│ │ ├── MethodHelpers.cs
│ │ └── Serializer.cs
│ ├── Enums
│ │ └── DataTypeEnum.cs
│ └── app.manifest
├── UWPSettingsEditorPkg
│ ├── Images
│ │ ├── StoreLogo.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Wide310x150Logo.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ └── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── Package.appxmanifest
│ └── UWPSettingsEditorPkg.wapproj
└── UWPSettingsEditor.sln
├── README.md
├── LICENSE
└── .gitignore
/UWPSettingsEditor_Demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/UWPSettingsEditor_Demo.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Assets/Exit_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditor/Assets/Exit_16x.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UWPSettingsEditor ALPHA
2 | Edit any settings.dat (UWP settings)
3 |
4 | 
5 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Assets/OpenFile_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditor/Assets/OpenFile_16x.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Assets/RegistryIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditor/Assets/RegistryIcon.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/StoreLogo.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Assets/Close_White_16x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditor/Assets/Close_White_16x.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Images/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ADeltaX/UWPSettingsEditor/HEAD/src/UWPSettingsEditorPkg/Images/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Interfaces/IValueDataSet.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace UWPSettingsEditor.Interfaces
4 | {
5 | public interface IValueDataSet : INotifyPropertyChanged
6 | {
7 | void SetValueData(byte[] dataRaw);
8 | byte[] GetValueData();
9 | bool IsDataValid { get; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace UWPSettingsEditor
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace UWPSettingsEditor
11 | {
12 | public class Program
13 | {
14 | [STAThreadAttribute]
15 | public static void Main()
16 | {
17 | App.Main();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/DateTimeOffsetComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Windows/AboutWindow.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Windows/AboutWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Shapes;
14 |
15 | namespace UWPSettingsEditor
16 | {
17 | ///
18 | /// Interaction logic for About.xaml
19 | ///
20 | public partial class AboutWindow : Window
21 | {
22 | public AboutWindow()
23 | {
24 | InitializeComponent();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/StringComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/IntComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Converters/TreeViewLineConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Controls;
7 | using System.Windows.Data;
8 |
9 | namespace UWPSettingsEditor.Converters
10 | {
11 | class TreeViewLineConverter : IValueConverter
12 | {
13 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
14 | {
15 | TreeViewItem item = (TreeViewItem)value;
16 | ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(item);
17 |
18 | //if (ic == null)
19 | // return false;
20 |
21 | return ic.ItemContainerGenerator.IndexFromContainer(item) == ic.Items.Count - 1;
22 | }
23 |
24 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
25 | {
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 ADeltaX
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/StringComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Windows.Controls;
4 | using UWPSettingsEditor.Interfaces;
5 | using static UWPSettingsEditor.UWPDeserializer;
6 | using static UWPSettingsEditor.UWPSerializer;
7 |
8 | namespace UWPSettingsEditor.Controls
9 | {
10 | ///
11 | /// Interaction logic for StringComponent.xaml
12 | ///
13 | public partial class StringComponent : UserControl, IValueDataSet
14 | {
15 | private DateTimeOffset _timestamp;
16 |
17 | public StringComponent()
18 | {
19 | InitializeComponent();
20 | _timestamp = DateTimeOffset.Now;
21 | }
22 |
23 | public bool IsDataValid => true;
24 |
25 | public event PropertyChangedEventHandler PropertyChanged;
26 |
27 | public byte[] GetValueData() => FromString(TextBox.Text, _timestamp);
28 |
29 | public void SetValueData(byte[] dataRaw)
30 | {
31 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
32 |
33 | _timestamp = GetDateTimeOffset(tmp.Key);
34 | TextBox.Text = GetString(tmp.Value);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UWPSettingsEditor.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.6.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/BooleanComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | True
19 |
20 | False
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/BooleanComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Windows.Controls;
4 | using UWPSettingsEditor.Interfaces;
5 | using static UWPSettingsEditor.UWPDeserializer;
6 | using static UWPSettingsEditor.UWPSerializer;
7 |
8 | namespace UWPSettingsEditor.Controls
9 | {
10 | ///
11 | /// Interaction logic for BooleanComponent.xaml
12 | ///
13 | public partial class BooleanComponent : UserControl, IValueDataSet
14 | {
15 | private DateTimeOffset _timestamp;
16 |
17 | public BooleanComponent()
18 | {
19 | InitializeComponent();
20 | cmBox.SelectedIndex = 0;
21 | _timestamp = DateTimeOffset.Now;
22 | }
23 |
24 | public bool IsDataValid => true;
25 |
26 | public event PropertyChangedEventHandler PropertyChanged;
27 |
28 | public byte[] GetValueData() => FromBoolean(bool.Parse((cmBox.SelectedItem as ComboBoxItem).Tag.ToString()), _timestamp);
29 |
30 | public void SetValueData(byte[] dataRaw)
31 | {
32 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
33 |
34 | _timestamp = GetDateTimeOffset(tmp.Key);
35 | var @bool = GetBoolean(tmp.Value);
36 |
37 | if (@bool)
38 | cmBox.SelectedIndex = 0;
39 | else
40 | cmBox.SelectedIndex = 1;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Util/Sizes.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | namespace DiscUtils.Streams
24 | {
25 | public static class Sizes
26 | {
27 | public const long OneKiB = 1024;
28 | public const long OneMiB = 1024 * OneKiB;
29 | public const long OneGiB = 1024 * OneMiB;
30 |
31 | public const int Sector = 512;
32 | }
33 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/DateTimeOffsetComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using UWPSettingsEditor.Interfaces;
4 | using static UWPSettingsEditor.UWPDeserializer;
5 | using static UWPSettingsEditor.UWPSerializer;
6 |
7 | // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
8 |
9 | namespace UWPSettingsEditor.Controls
10 | {
11 | ///
12 | /// An empty page that can be used on its own or navigated to within a Frame.
13 | ///
14 | public sealed partial class DateTimeOffsetComponent : IValueDataSet
15 | {
16 | private DateTimeOffset _timestamp;
17 | private DateTimeOffset _dateTimeOffset;
18 |
19 | public DateTimeOffsetComponent()
20 | {
21 | this.InitializeComponent();
22 | dateBox.SelectedDate = DateTime.Now;
23 | _timestamp = DateTimeOffset.Now;
24 | }
25 |
26 | public bool IsDataValid => throw new NotImplementedException();
27 |
28 | public event PropertyChangedEventHandler PropertyChanged;
29 |
30 | public byte[] GetValueData()
31 | => FromDateTimeOffset(new DateTimeOffset(dateBox.SelectedDate, _dateTimeOffset.Offset), _timestamp);
32 |
33 | public void SetValueData(byte[] dataRaw)
34 | {
35 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
36 |
37 | _timestamp = GetDateTimeOffset(tmp.Key);
38 | _dateTimeOffset = GetDateTimeOffset(tmp.Value);
39 |
40 | dateBox.SelectedDate = _dateTimeOffset.DateTime;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Classes/PrimitiveStructs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace UWPSettingsEditor
8 | {
9 | public struct Point
10 | {
11 | public double X { get; set; }
12 | public double Y { get; set; }
13 |
14 | public Point(double x, double y)
15 | {
16 | X = x;
17 | Y = y;
18 | }
19 |
20 | public override string ToString()
21 | {
22 | return $"X: {X}, Y: {Y}";
23 | }
24 | }
25 | public struct Size
26 | {
27 | public double Width { get; set; }
28 | public double Height { get; set; }
29 |
30 | public Size(double width, double height)
31 | {
32 | Width = width;
33 | Height = height;
34 | }
35 |
36 | public override string ToString()
37 | {
38 | return $"Width: {Width}, Height: {Height}";
39 | }
40 | }
41 |
42 | public struct Rect
43 | {
44 | public double X { get; set; }
45 | public double Y { get; set; }
46 | public double Width { get; set; }
47 | public double Height { get; set; }
48 |
49 | public Rect(double x, double y, double width, double height)
50 | {
51 | X = x;
52 | Y = y;
53 | Width = width;
54 | Height = height;
55 | }
56 |
57 | public override string ToString()
58 | {
59 | return $"X: {X}, Y: {Y}, Width: {Width}, Height: {Height}";
60 | }
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/CharComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Ownership.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | namespace DiscUtils.Streams
24 | {
25 | ///
26 | /// Enumeration used to indicate transfer of disposable objects.
27 | ///
28 | public enum Ownership
29 | {
30 | ///
31 | /// Indicates there is no transfer of ownership.
32 | ///
33 | None,
34 |
35 | ///
36 | /// Indicates ownership of the stream is transfered, the owner should dispose of the stream when appropriate.
37 | ///
38 | Dispose
39 | }
40 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/GuidComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/ValueFlags.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 |
25 | namespace DiscUtils.Registry
26 | {
27 | [Flags]
28 | internal enum ValueFlags : ushort
29 | {
30 | Named = 0x0001,
31 | Unknown0002 = 0x0002,
32 | Unknown0004 = 0x0004,
33 | Unknown0008 = 0x0008,
34 | Unknown0010 = 0x0010,
35 | Unknown0020 = 0x0020,
36 | Unknown0040 = 0x0040,
37 | Unknown0080 = 0x0080,
38 | Unknown0100 = 0x0100,
39 | Unknown0200 = 0x0200,
40 | Unknown0400 = 0x0400,
41 | Unknown0800 = 0x0800,
42 | Unknown1000 = 0x1000,
43 | Unknown2000 = 0x2000,
44 | Unknown4000 = 0x4000,
45 | Unknown8000 = 0x8000
46 | }
47 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Internal/SetupHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | //using DiscUtils.CoreCompat;
5 |
6 | namespace DiscUtils.Setup
7 | {
8 | ///
9 | /// Helps setup new DiscUtils dependencies, when loaded into target programs
10 | ///
11 | public static class SetupHelper
12 | {
13 | //private static readonly HashSet _alreadyLoaded;
14 |
15 | //static SetupHelper()
16 | //{
17 | // _alreadyLoaded = new HashSet();
18 |
19 | // // Register the core DiscUtils lib
20 | // RegisterAssembly(ReflectionHelper.GetAssembly(typeof(SetupHelper)));
21 | //}
22 |
23 | /////
24 | ///// Registers the types provided by an assembly to all relevant DiscUtils managers
25 | /////
26 | /////
27 | //public static void RegisterAssembly(Assembly assembly)
28 | //{
29 | // lock (_alreadyLoaded)
30 | // {
31 | // if (!_alreadyLoaded.Add(assembly.FullName))
32 | // return;
33 |
34 | // FileSystemManager.RegisterFileSystems(assembly);
35 | // VirtualDiskManager.RegisterVirtualDiskTypes(assembly);
36 | // VolumeManager.RegisterLogicalVolumeFactory(assembly);
37 | // }
38 | //}
39 |
40 | ///
41 | /// Allows intercepting any file open operation
42 | ///
43 | ///
44 | /// Can be used to wrap the opened file for special use cases,
45 | /// modify the parameters for opening files, validate file names
46 | /// and many more.
47 | ///
48 | public static event EventHandler OpeningFile;
49 |
50 | internal static void OnOpeningFile(object sender, FileOpenEventArgs e)
51 | {
52 | OpeningFile?.Invoke(sender, e);
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 | UWPSettingsEditor
16 | ADX
17 | Images\StoreLogo.png
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/PointSizeComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Enums/DataTypeEnum.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace UWPSettingsEditor
8 | {
9 | public enum DataTypeEnum
10 | {
11 | RegNone = 0,
12 | RegSz = 1,
13 | RegExpandSz = 2,
14 | RegBinary = 3,
15 | RegDword = 4,
16 | RegDwordBigEndian = 5,
17 | RegLink = 6,
18 | RegMultiSz = 7,
19 | RegResourceList = 8,
20 | RegFullResourceDescription = 9,
21 | RegResourceRequirementsList = 0xA,
22 | RegQword = 0xB,
23 | RegFileTime = 0x10,
24 |
25 | RegUwpByte = 0x5f5e_101,
26 | RegUwpInt16 = 0x5f5e_102,
27 | RegUwpUint16 = 0x5f5e_103,
28 | RegUwpInt32 = 0x5f5e_104,
29 | RegUwpUint32 = 0x5f5e_105,
30 | RegUwpInt64 = 0x5f5e_106,
31 | RegUwpUint64 = 0x5f5e_107,
32 | RegUwpSingle = 0x5f5e_108,
33 | RegUwpDouble = 0x5f5e_109,
34 | RegUwpChar = 0x5f5e_10A,
35 | RegUwpBoolean = 0x5f5e_10B,
36 | RegUwpString = 0x5f5e_10C,
37 | RegUwpCompositeValue = 0x5f5e_10D,
38 | RegUwpDateTimeOffset = 0x5f5e_10E,
39 | RegUwpTimeSpan = 0x5f5e_10F,
40 | RegUwpGuid = 0x5f5e_110,
41 | RegUwpPoint = 0x5f5e_111,
42 | RegUwpSize = 0x5f5e_112,
43 | RegUwpRect = 0x5f5e_113,
44 | RegUwpArrayByte = 0x5f5e_114,
45 | RegUwpArrayInt16 = 0x5f5e_115,
46 | RegUwpArrayUint16 = 0x5f5e_116,
47 | RegUwpArrayInt32 = 0x5f5e_117,
48 | RegUwpArrayUint32 = 0x5f5e_118,
49 | RegUwpArrayInt64 = 0x5f5e_119,
50 | RegUwpArrayUint64 = 0x5f5e_11A,
51 | RegUwpArraySingle = 0x5f5e_11B,
52 | RegUwpArrayDouble = 0x5f5e_11C,
53 | RegUwpArrayChar16 = 0x5f5e_11D,
54 | RegUwpArrayBoolean = 0x5f5e_11E,
55 | RegUwpArrayString = 0x5f5e_11F,
56 | RegUwpArrayDateTimeOffset = 0x5f5e_120,
57 | RegUwpArrayTimeSpan = 0x5f5e_121,
58 | RegUwpArrayGuid = 0x5f5e_122,
59 | RegUwpArrayPoint = 0x5f5e_123,
60 | RegUwpArraySize = 0x5f5e_124,
61 | RegUwpArrayRect = 0x5f5e_125,
62 |
63 | RegUnknown = 999
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Interfaces/IByteArraySerializable.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | namespace DiscUtils.Streams
24 | {
25 | ///
26 | /// Common interface for reading structures to/from byte arrays.
27 | ///
28 | public interface IByteArraySerializable
29 | {
30 | ///
31 | /// Gets the total number of bytes the structure occupies.
32 | ///
33 | int Size { get; }
34 |
35 | ///
36 | /// Reads the structure from a byte array.
37 | ///
38 | /// The buffer to read from.
39 | /// The buffer offset to start reading from.
40 | /// The number of bytes read.
41 | int ReadFrom(byte[] buffer, int offset);
42 |
43 | ///
44 | /// Writes a structure to a byte array.
45 | ///
46 | /// The buffer to write to.
47 | /// The buffer offset to start writing at.
48 | void WriteTo(byte[] buffer, int offset);
49 | }
50 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Internal/UnixFileType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | namespace DiscUtils
24 | {
25 | ///
26 | /// Standard Unix-style file type.
27 | ///
28 | public enum UnixFileType
29 | {
30 | ///
31 | /// No type specified.
32 | ///
33 | None = 0,
34 |
35 | ///
36 | /// A FIFO / Named Pipe.
37 | ///
38 | Fifo = 0x1,
39 |
40 | ///
41 | /// A character device.
42 | ///
43 | Character = 0x2,
44 |
45 | ///
46 | /// A normal directory.
47 | ///
48 | Directory = 0x4,
49 |
50 | ///
51 | /// A block device.
52 | ///
53 | Block = 0x6,
54 |
55 | ///
56 | /// A regular file.
57 | ///
58 | Regular = 0x8,
59 |
60 | ///
61 | /// A soft link.
62 | ///
63 | Link = 0xA,
64 |
65 | ///
66 | /// A unix socket.
67 | ///
68 | Socket = 0xC
69 | }
70 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Windows/EditValueWindow.xaml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
33 |
34 |
36 |
37 |
38 |
39 |
41 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("UWPSettingsEditor")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("UWPSettingsEditor")]
15 | [assembly: AssemblyCopyright("Copyright © 2020")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Classes/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using System.Windows;
4 | using System.Windows.Interop;
5 | using System.Windows.Media.Imaging;
6 |
7 | namespace UWPSettingsEditor
8 | {
9 | public static class NativeMethods
10 | {
11 | [DllImport("uxtheme.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
12 | public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, IntPtr pszSubIdList);
13 |
14 | [DllImport("dwmapi.dll", PreserveSig = true)]
15 | public static extern int DwmSetWindowAttribute(IntPtr hwnd, uint attr, ref int attrValue, int attrSize);
16 |
17 | [DllImport("user32.dll")]
18 | static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
19 |
20 | [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
21 | public static extern int GetWindowLongPtr(IntPtr hWnd, int nIndex);
22 |
23 | public static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
24 | {
25 | if (IntPtr.Size > 4)
26 | return SetClassLongPtr64(hWnd, nIndex, dwNewLong);
27 | else
28 | return new IntPtr(SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
29 | }
30 |
31 | [DllImport("user32.dll", EntryPoint = "SetClassLong")]
32 | public static extern uint SetClassLongPtr32(IntPtr hWnd, int nIndex, uint dwNewLong);
33 |
34 | [DllImport("user32.dll", EntryPoint = "SetClassLongPtr")]
35 | public static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
36 |
37 | [DllImport("gdi32.dll")]
38 | public static extern IntPtr CreateSolidBrush(uint crColor);
39 |
40 | [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
41 | private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
42 |
43 | public static BitmapSource ExtractIcon(string file, int number, bool largeIcon)
44 | {
45 | ExtractIconEx(file, number, out IntPtr large, out IntPtr small, 1);
46 | try
47 | {
48 | return Imaging.CreateBitmapSourceFromHIcon(
49 | largeIcon ? large : small,
50 | Int32Rect.Empty,
51 | BitmapSizeOptions.FromEmptyOptions());
52 | }
53 | catch
54 | {
55 | return null;
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/BinHeader.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System.IO;
24 | using DiscUtils.Streams;
25 |
26 | namespace DiscUtils.Registry
27 | {
28 | internal sealed class BinHeader : IByteArraySerializable
29 | {
30 | public const int HeaderSize = 0x20;
31 |
32 | private const uint Signature = 0x6E696268;
33 | public int BinSize;
34 |
35 | public int FileOffset;
36 |
37 | public int Size
38 | {
39 | get { return HeaderSize; }
40 | }
41 |
42 | public int ReadFrom(byte[] buffer, int offset)
43 | {
44 | uint sig = EndianUtilities.ToUInt32LittleEndian(buffer, offset + 0);
45 | if (sig != Signature)
46 | {
47 | throw new IOException("Invalid signature for registry bin");
48 | }
49 |
50 | FileOffset = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x04);
51 | BinSize = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x08);
52 | long unknown = EndianUtilities.ToInt64LittleEndian(buffer, offset + 0x0C);
53 | long unknown1 = EndianUtilities.ToInt64LittleEndian(buffer, offset + 0x14);
54 | int unknown2 = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x1C);
55 | return HeaderSize;
56 | }
57 |
58 | public void WriteTo(byte[] buffer, int offset)
59 | {
60 | EndianUtilities.WriteBytesLittleEndian(Signature, buffer, offset + 0x00);
61 | EndianUtilities.WriteBytesLittleEndian(FileOffset, buffer, offset + 0x04);
62 | EndianUtilities.WriteBytesLittleEndian(BinSize, buffer, offset + 0x08);
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/Basic/DateTimePicker.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
29 |
30 |
37 |
38 |
39 |
46 |
47 |
48 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/RegistryValueType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | namespace DiscUtils.Registry
24 | {
25 | ///
26 | /// The types of registry values.
27 | ///
28 | public enum RegistryValueType
29 | {
30 | ///
31 | /// Unknown type.
32 | ///
33 | None = 0x00,
34 |
35 | ///
36 | /// A unicode string.
37 | ///
38 | String = 0x01,
39 |
40 | ///
41 | /// A string containing environment variables.
42 | ///
43 | ExpandString = 0x02,
44 |
45 | ///
46 | /// Binary data.
47 | ///
48 | Binary = 0x03,
49 |
50 | ///
51 | /// A 32-bit integer.
52 | ///
53 | Dword = 0x04,
54 |
55 | ///
56 | /// A 32-bit integer.
57 | ///
58 | DwordBigEndian = 0x05,
59 |
60 | ///
61 | /// A registry link.
62 | ///
63 | Link = 0x06,
64 |
65 | ///
66 | /// A multistring.
67 | ///
68 | MultiString = 0x07,
69 |
70 | ///
71 | /// An unknown binary format.
72 | ///
73 | ResourceList = 0x08,
74 |
75 | ///
76 | /// An unknown binary format.
77 | ///
78 | FullResourceDescriptor = 0x09,
79 |
80 | ///
81 | /// An unknown binary format.
82 | ///
83 | ResourceRequirementsList = 0x0A,
84 |
85 | ///
86 | /// A 64-bit integer.
87 | ///
88 | QWord = 0x0B
89 | }
90 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/RegistryCorruptException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 |
25 | namespace DiscUtils.Registry
26 | {
27 | #if !NETSTANDARD1_5
28 | using System.Runtime.Serialization;
29 | #endif
30 |
31 | ///
32 | /// Exception thrown when some corruption is found in the registry hive.
33 | ///
34 | #if !NETSTANDARD1_5
35 | [Serializable]
36 | #endif
37 | public class RegistryCorruptException : Exception
38 | {
39 | ///
40 | /// Initializes a new instance of the RegistryCorruptException class.
41 | ///
42 | public RegistryCorruptException() {}
43 |
44 | ///
45 | /// Initializes a new instance of the RegistryCorruptException class.
46 | ///
47 | /// The exception message.
48 | public RegistryCorruptException(string message)
49 | : base(message) {}
50 |
51 | ///
52 | /// Initializes a new instance of the RegistryCorruptException class.
53 | ///
54 | /// The exception message.
55 | /// The inner exception.
56 | public RegistryCorruptException(string message, Exception innerException)
57 | : base(message, innerException) {}
58 |
59 | #if !NETSTANDARD1_5
60 | ///
61 | /// Initializes a new instance of the RegistryCorruptException class.
62 | ///
63 | /// The serialization info.
64 | /// The streaming context.
65 | protected RegistryCorruptException(SerializationInfo info, StreamingContext context)
66 | : base(info, context)
67 | {
68 | }
69 | #endif
70 | }
71 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Internal/FileLocator.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using System.IO;
25 | using DiscUtils.Internal;
26 | using DiscUtils.Setup;
27 |
28 | namespace DiscUtils
29 | {
30 | internal abstract class FileLocator
31 | {
32 | public abstract bool Exists(string fileName);
33 |
34 | public Stream Open(string fileName, FileMode mode, FileAccess access, FileShare share)
35 | {
36 | var args = new FileOpenEventArgs(fileName, mode, access, share, OpenFile);
37 | SetupHelper.OnOpeningFile(this, args);
38 | if (args.Result != null)
39 | return args.Result;
40 | return OpenFile(args.FileName, args.FileMode, args.FileAccess, args.FileShare);
41 | }
42 |
43 | protected abstract Stream OpenFile(string fileName, FileMode mode, FileAccess access, FileShare share);
44 |
45 | public abstract FileLocator GetRelativeLocator(string path);
46 |
47 | public abstract string GetFullPath(string path);
48 |
49 | public abstract string GetDirectoryFromPath(string path);
50 |
51 | public abstract string GetFileFromPath(string path);
52 |
53 | public abstract DateTime GetLastWriteTimeUtc(string path);
54 |
55 | public abstract bool HasCommonRoot(FileLocator other);
56 |
57 | public abstract string ResolveRelativePath(string path);
58 |
59 | internal string MakeRelativePath(FileLocator fileLocator, string path)
60 | {
61 | if (!HasCommonRoot(fileLocator))
62 | {
63 | return null;
64 | }
65 |
66 | string ourFullPath = GetFullPath(string.Empty) + @"\";
67 | string otherFullPath = fileLocator.GetFullPath(path);
68 |
69 | return Utilities.MakeRelativePath(otherFullPath, ourFullPath);
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UWPSettingsEditor.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UWPSettingsEditor.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Cell.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using DiscUtils.Streams;
24 |
25 | namespace DiscUtils.Registry
26 | {
27 | ///
28 | /// Base class for the different kinds of cell present in a hive.
29 | ///
30 | internal abstract class Cell : IByteArraySerializable
31 | {
32 | public Cell(int index)
33 | {
34 | Index = index;
35 | }
36 |
37 | public int Index { get; set; }
38 |
39 | public abstract int Size { get; }
40 |
41 | public abstract int ReadFrom(byte[] buffer, int offset);
42 |
43 | public abstract void WriteTo(byte[] buffer, int offset);
44 |
45 | internal static Cell Parse(RegistryHive hive, int index, byte[] buffer, int pos)
46 | {
47 | string type = EndianUtilities.BytesToString(buffer, pos, 2);
48 |
49 | Cell result = null;
50 |
51 | switch (type)
52 | {
53 | case "nk":
54 | result = new KeyNodeCell(index);
55 | break;
56 |
57 | case "sk":
58 | result = new SecurityCell(index);
59 | break;
60 |
61 | case "vk":
62 | result = new ValueCell(index);
63 | break;
64 |
65 | case "lh":
66 | case "lf":
67 | result = new SubKeyHashedListCell(hive, index);
68 | break;
69 |
70 | case "li":
71 | case "ri":
72 | result = new SubKeyIndirectListCell(hive, index);
73 | break;
74 |
75 | default:
76 | throw new RegistryCorruptException("Unknown cell type '" + type + "'");
77 | }
78 |
79 | result.ReadFrom(buffer, pos);
80 | return result;
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Windows/CreateValueWindow.xaml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
50 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Classes/Models.cs:
--------------------------------------------------------------------------------
1 | using DiscUtils.Registry;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Collections.ObjectModel;
5 | using System.ComponentModel;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Media.Imaging;
10 |
11 | namespace UWPSettingsEditor
12 | {
13 |
14 | public class RootTreeView
15 | {
16 | public RootTreeView()
17 | {
18 | RegistryHiveTreeViews = new ObservableCollection();
19 | }
20 | public bool IsExpanded { get; set; }
21 | public BitmapSource ImageSource { get; set; }
22 | public string Name { get; set; }
23 | public ObservableCollection RegistryHiveTreeViews { get; set; }
24 | }
25 |
26 | public class RegistryHiveTreeView
27 | {
28 | public RegistryHiveTreeView(RegistryHive registryHive)
29 | {
30 | AttachedHive = registryHive;
31 | Children = new ObservableCollection();
32 | }
33 |
34 | public void LoadDummyChild()
35 | {
36 | Children.Add(new RegistryKeyTreeView());
37 | IsDummy = true;
38 | }
39 | public void RemoveDummyChild()
40 | {
41 | Children.Clear();
42 | IsDummy = false;
43 | }
44 |
45 | public BitmapSource ImageSource { get; set; }
46 | public bool IsDummy { get; set; }
47 | public string Name { get; set; }
48 | public string FilePath { get; set; }
49 | public RegistryHive AttachedHive { get; set; }
50 | public ObservableCollection Children { get; set; }
51 | }
52 |
53 | public class RegistryKeyTreeView
54 | {
55 | public RegistryKeyTreeView()
56 | {
57 | Children = new ObservableCollection();
58 | }
59 |
60 | public void LoadDummyChild()
61 | {
62 | Children.Add(new RegistryKeyTreeView());
63 | IsDummy = true;
64 | }
65 | public void RemoveDummyChild()
66 | {
67 | Children.Clear();
68 | IsDummy = false;
69 | }
70 |
71 | public BitmapSource ImageSource { get; set; }
72 | public string Path { get; set; }
73 | public string Name { get; set; }
74 | public bool IsDummy { get; set; }
75 | public RegistryHiveTreeView Root { get; set; }
76 | public RegistryHive AttachedHive { get; set; }
77 | public ObservableCollection Children { get; set; }
78 | }
79 |
80 | public class KeyVal : INotifyPropertyChanged
81 | {
82 | private byte[] data;
83 |
84 | public string Path { get; set; }
85 | public string Name { get; set; }
86 | public DataTypeEnum DataTypeEnum { get; set; }
87 | public RegistryHive Hive { get; set; }
88 | public byte[] Data { get => data; set { data = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Data")); } }
89 |
90 | public event PropertyChangedEventHandler PropertyChanged;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/ListCell.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System.Collections.Generic;
24 |
25 | namespace DiscUtils.Registry
26 | {
27 | internal abstract class ListCell : Cell
28 | {
29 | public ListCell(int index)
30 | : base(index) {}
31 |
32 | ///
33 | /// Gets the number of subkeys in this list.
34 | ///
35 | internal abstract int Count { get; }
36 |
37 | ///
38 | /// Searches for a key with a given name.
39 | ///
40 | /// The name to search for.
41 | /// The index of the cell, if found.
42 | /// The search result.
43 | internal abstract int FindKey(string name, out int cellIndex);
44 |
45 | ///
46 | /// Enumerates all of the keys in the list.
47 | ///
48 | /// The list to populate.
49 | internal abstract void EnumerateKeys(List names);
50 |
51 | ///
52 | /// Enumerates all of the keys in the list.
53 | ///
54 | /// Enumeration of key cells.
55 | internal abstract IEnumerable EnumerateKeys();
56 |
57 | ///
58 | /// Adds a subkey to this list.
59 | ///
60 | /// The name of the subkey.
61 | /// The cell index of the subkey.
62 | /// The new cell index of the list, which may have changed.
63 | internal abstract int LinkSubKey(string name, int cellIndex);
64 |
65 | ///
66 | /// Removes a subkey from this list.
67 | ///
68 | /// The name of the subkey.
69 | /// The new cell index of the list, which may have changed.
70 | internal abstract int UnlinkSubKey(string name);
71 | }
72 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Internal/FileOpenEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017, Bianco Veigel
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using System.IO;
25 |
26 | namespace DiscUtils.Setup
27 | {
28 | internal delegate Stream FileOpenDelegate(string fileName, FileMode mode, FileAccess access, FileShare share);
29 |
30 | ///
31 | /// Event arguments for opening a file
32 | ///
33 | public class FileOpenEventArgs:EventArgs
34 | {
35 | private FileOpenDelegate _opener;
36 |
37 | internal FileOpenEventArgs(string fileName, FileMode mode, FileAccess access, FileShare share, FileOpenDelegate opener)
38 | {
39 | FileName = fileName;
40 | FileMode = mode;
41 | FileAccess = access;
42 | FileShare = share;
43 | _opener = opener;
44 | }
45 |
46 | ///
47 | /// Gets or sets the filename to open
48 | ///
49 | public string FileName { get; set; }
50 |
51 | ///
52 | /// Gets or sets the
53 | ///
54 | public FileMode FileMode { get; set; }
55 |
56 | ///
57 | /// Gets or sets the
58 | ///
59 | public FileAccess FileAccess { get; set; }
60 |
61 | ///
62 | /// Gets or sets the
63 | ///
64 | public FileShare FileShare { get; set; }
65 |
66 | ///
67 | /// The resulting stream.
68 | ///
69 | ///
70 | /// If this is set to a non null value, this stream is used instead of opening the supplied
71 | ///
72 | public Stream Result { get; set; }
73 |
74 | ///
75 | /// returns the result from the builtin FileLocator
76 | ///
77 | ///
78 | public Stream GetFileStream()
79 | {
80 | return _opener(FileName, FileMode, FileAccess, FileShare);
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/GuidComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Globalization;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Windows;
9 | using System.Windows.Controls;
10 | using System.Windows.Data;
11 | using System.Windows.Documents;
12 | using System.Windows.Input;
13 | using System.Windows.Media;
14 | using System.Windows.Media.Imaging;
15 | using System.Windows.Navigation;
16 | using System.Windows.Shapes;
17 | using UWPSettingsEditor.Interfaces;
18 | using static UWPSettingsEditor.UWPDeserializer;
19 | using static UWPSettingsEditor.UWPSerializer;
20 |
21 | namespace UWPSettingsEditor.Controls
22 | {
23 | ///
24 | /// Interaction logic for GuidComponent.xaml
25 | ///
26 | public partial class GuidComponent : IValueDataSet
27 | {
28 | private DateTimeOffset _timestamp;
29 | private Guid _guid;
30 |
31 | private string _guidString;
32 | public string GuidString
33 | {
34 | get
35 | {
36 | return _guidString;
37 | }
38 | set
39 | {
40 | FlagDataAsValid();
41 | _guidString = value;
42 | }
43 | }
44 |
45 | public bool IsDataValid { get; private set; } = true;
46 |
47 | public GuidComponent()
48 | {
49 | DataContext = this;
50 | InitializeComponent();
51 | guidBox.Text = Guid.NewGuid().ToString();
52 | _timestamp = DateTimeOffset.Now;
53 | }
54 |
55 | public event PropertyChangedEventHandler PropertyChanged;
56 |
57 | private void guidBox_Error(object sender, ValidationErrorEventArgs e)
58 | {
59 | FlagDataAsInvalid();
60 | }
61 |
62 | private void Button_Click(object sender, RoutedEventArgs e)
63 | {
64 | guidBox.Text = Guid.NewGuid().ToString();
65 | }
66 |
67 | private void FlagDataAsValid()
68 | {
69 | IsDataValid = true;
70 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
71 | }
72 |
73 | private void FlagDataAsInvalid()
74 | {
75 | IsDataValid = false;
76 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
77 | }
78 |
79 | public void SetValueData(byte[] dataRaw)
80 | {
81 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
82 |
83 | _timestamp = GetDateTimeOffset(tmp.Key);
84 | _guid = GetGuid(tmp.Value);
85 |
86 | guidBox.Text = _guid.ToString();
87 | }
88 |
89 | public byte[] GetValueData()
90 | => FromGuid(Guid.Parse(guidBox.Text), _timestamp);
91 | }
92 |
93 | class GuidValidationRule : ValidationRule
94 | {
95 | public override ValidationResult Validate(object value, CultureInfo cultureInfo)
96 | {
97 | if (Guid.TryParse((string)value, out _))
98 | return ValidationResult.ValidResult;
99 | else
100 | return new ValidationResult(false, "Not a valid guid");
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/RectComponent.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
52 |
53 |
54 |
55 | true
56 | PerMonitorV2, PerMonitor
57 |
58 |
59 |
60 |
61 |
62 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/RegistryKeyFlags.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 |
25 | namespace DiscUtils.Registry
26 | {
27 | ///
28 | /// The per-key flags present on registry keys.
29 | ///
30 | [Flags]
31 | public enum RegistryKeyFlags
32 | {
33 | ///
34 | /// Unknown purpose.
35 | ///
36 | Unknown0001 = 0x0001,
37 |
38 | ///
39 | /// Unknown purpose.
40 | ///
41 | Unknown0002 = 0x0002,
42 |
43 | ///
44 | /// The key is the root key in the registry hive.
45 | ///
46 | Root = 0x0004,
47 |
48 | ///
49 | /// Unknown purpose.
50 | ///
51 | Unknown0008 = 0x0008,
52 |
53 | ///
54 | /// The key is a link to another key.
55 | ///
56 | Link = 0x0010,
57 |
58 | ///
59 | /// This is a normal key.
60 | ///
61 | Normal = 0x0020,
62 |
63 | ///
64 | /// Unknown purpose.
65 | ///
66 | Unknown0040 = 0x0040,
67 |
68 | ///
69 | /// Unknown purpose.
70 | ///
71 | Unknown0080 = 0x0080,
72 |
73 | ///
74 | /// Unknown purpose.
75 | ///
76 | Unknown0100 = 0x0100,
77 |
78 | ///
79 | /// Unknown purpose.
80 | ///
81 | Unknown0200 = 0x0200,
82 |
83 | ///
84 | /// Unknown purpose.
85 | ///
86 | Unknown0400 = 0x0400,
87 |
88 | ///
89 | /// Unknown purpose.
90 | ///
91 | Unknown0800 = 0x0800,
92 |
93 | ///
94 | /// Unknown purpose.
95 | ///
96 | Unknown1000 = 0x1000,
97 |
98 | ///
99 | /// Unknown purpose.
100 | ///
101 | Unknown2000 = 0x2000,
102 |
103 | ///
104 | /// Unknown purpose.
105 | ///
106 | Unknown4000 = 0x4000,
107 |
108 | ///
109 | /// Unknown purpose.
110 | ///
111 | Unknown8000 = 0x8000
112 | }
113 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/CharComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Globalization;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Windows;
9 | using System.Windows.Controls;
10 | using System.Windows.Data;
11 | using System.Windows.Documents;
12 | using System.Windows.Input;
13 | using System.Windows.Media;
14 | using System.Windows.Media.Imaging;
15 | using System.Windows.Navigation;
16 | using System.Windows.Shapes;
17 | using UWPSettingsEditor.Interfaces;
18 | using static UWPSettingsEditor.UWPDeserializer;
19 | using static UWPSettingsEditor.UWPSerializer;
20 |
21 | namespace UWPSettingsEditor.Controls
22 | {
23 | ///
24 | /// Interaction logic for CharComponent.xaml
25 | ///
26 | public partial class CharComponent : IValueDataSet
27 | {
28 | private DateTimeOffset _timestamp;
29 | private char _char;
30 | private string _charString;
31 | public string CharString
32 | {
33 | get
34 | {
35 | return _charString;
36 | }
37 | set
38 | {
39 | FlagDataAsValid();
40 | charBox.Text = ((char)ushort.Parse(value)).ToString();
41 | _charString = value;
42 | }
43 | }
44 |
45 | public CharComponent()
46 | {
47 | DataContext = this;
48 | InitializeComponent();
49 | charBox.Text = "A";
50 | _timestamp = DateTimeOffset.Now;
51 | }
52 |
53 | public bool IsDataValid { get; private set; } = true;
54 |
55 | public event PropertyChangedEventHandler PropertyChanged;
56 |
57 | public byte[] GetValueData()
58 | {
59 | return FromChar(charBox.Text[0], _timestamp);
60 | }
61 |
62 | public void SetValueData(byte[] dataRaw)
63 | {
64 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
65 |
66 | _timestamp = GetDateTimeOffset(tmp.Key);
67 | _char = GetChar(tmp.Value);
68 |
69 | charBox.Text = _char.ToString();
70 | numberBox.Text = ((ushort)_char).ToString();
71 | }
72 |
73 | private void FlagDataAsValid()
74 | {
75 | IsDataValid = true;
76 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
77 | }
78 |
79 | private void FlagDataAsInvalid()
80 | {
81 | IsDataValid = false;
82 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
83 | }
84 |
85 | private void numberBox_Error(object sender, ValidationErrorEventArgs e)
86 | {
87 | FlagDataAsInvalid();
88 | }
89 |
90 | private void charBox_TextChanged(object sender, TextChangedEventArgs e)
91 | {
92 | if (charBox.Text.Length > 0)
93 | numberBox.Text = ((int)charBox.Text[0]).ToString();
94 | else
95 | {
96 | numberBox.Text = "";
97 | FlagDataAsInvalid();
98 | }
99 | }
100 | }
101 |
102 | class UshortRule : ValidationRule
103 | {
104 | public override ValidationResult Validate(object value, CultureInfo cultureInfo)
105 | {
106 | if (ushort.TryParse((string)value, out _))
107 | return ValidationResult.ValidResult;
108 | else
109 | return new ValidationResult(false, "Not a valid ushort number");
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/SecurityCell.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using System.Security.AccessControl;
25 | using DiscUtils.Streams;
26 |
27 | namespace DiscUtils.Registry
28 | {
29 | internal sealed class SecurityCell : Cell
30 | {
31 | public SecurityCell(RegistrySecurity secDesc)
32 | : this(-1)
33 | {
34 | SecurityDescriptor = secDesc;
35 | }
36 |
37 | public SecurityCell(int index)
38 | : base(index)
39 | {
40 | PreviousIndex = -1;
41 | NextIndex = -1;
42 | }
43 |
44 | public int NextIndex { get; set; }
45 |
46 | public int PreviousIndex { get; set; }
47 |
48 | public RegistrySecurity SecurityDescriptor { get; private set; }
49 |
50 | public override int Size
51 | {
52 | get
53 | {
54 | int sdLen = SecurityDescriptor.GetSecurityDescriptorBinaryForm().Length;
55 | return 0x14 + sdLen;
56 | }
57 | }
58 |
59 | public int UsageCount { get; set; }
60 |
61 | public override int ReadFrom(byte[] buffer, int offset)
62 | {
63 | PreviousIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x04);
64 | NextIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x08);
65 | UsageCount = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x0C);
66 | int secDescSize = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x10);
67 |
68 | byte[] secDesc = new byte[secDescSize];
69 | Array.Copy(buffer, offset + 0x14, secDesc, 0, secDescSize);
70 | SecurityDescriptor = new RegistrySecurity();
71 | SecurityDescriptor.SetSecurityDescriptorBinaryForm(secDesc);
72 |
73 | return 0x14 + secDescSize;
74 | }
75 |
76 | public override void WriteTo(byte[] buffer, int offset)
77 | {
78 | byte[] sd = SecurityDescriptor.GetSecurityDescriptorBinaryForm();
79 |
80 | EndianUtilities.StringToBytes("sk", buffer, offset, 2);
81 | EndianUtilities.WriteBytesLittleEndian(PreviousIndex, buffer, offset + 0x04);
82 | EndianUtilities.WriteBytesLittleEndian(NextIndex, buffer, offset + 0x08);
83 | EndianUtilities.WriteBytesLittleEndian(UsageCount, buffer, offset + 0x0C);
84 | EndianUtilities.WriteBytesLittleEndian(sd.Length, buffer, offset + 0x10);
85 | Array.Copy(sd, 0, buffer, offset + 0x14, sd.Length);
86 | }
87 |
88 | public override string ToString()
89 | {
90 | return "SecDesc:" + SecurityDescriptor.GetSecurityDescriptorSddlForm(AccessControlSections.All) + " (refCount:" +
91 | UsageCount + ")";
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/ValueCell.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using DiscUtils.Streams;
24 |
25 | namespace DiscUtils.Registry
26 | {
27 | internal sealed class ValueCell : Cell
28 | {
29 | private ValueFlags _flags;
30 |
31 | public ValueCell(string name)
32 | : this(-1)
33 | {
34 | Name = name;
35 | }
36 |
37 | public ValueCell(int index)
38 | : base(index)
39 | {
40 | DataIndex = -1;
41 | }
42 |
43 | public int DataIndex { get; set; }
44 |
45 | public int DataLength { get; set; }
46 |
47 | public RegistryValueType DataType { get; set; }
48 |
49 | public string Name { get; private set; }
50 |
51 | public override int Size
52 | {
53 | get { return 0x14 + (string.IsNullOrEmpty(Name) ? 0 : Name.Length); }
54 | }
55 |
56 | public override int ReadFrom(byte[] buffer, int offset)
57 | {
58 | int nameLen = EndianUtilities.ToUInt16LittleEndian(buffer, offset + 0x02);
59 | DataLength = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x04);
60 | DataIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x08);
61 | DataType = (RegistryValueType)EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x0C);
62 | _flags = (ValueFlags)EndianUtilities.ToUInt16LittleEndian(buffer, offset + 0x10);
63 |
64 | if ((_flags & ValueFlags.Named) != 0)
65 | {
66 | Name = EndianUtilities.BytesToString(buffer, offset + 0x14, nameLen).Trim('\0');
67 | }
68 |
69 | return 0x14 + nameLen;
70 | }
71 |
72 | public override void WriteTo(byte[] buffer, int offset)
73 | {
74 | int nameLen;
75 |
76 | if (string.IsNullOrEmpty(Name))
77 | {
78 | _flags &= ~ValueFlags.Named;
79 | nameLen = 0;
80 | }
81 | else
82 | {
83 | _flags |= ValueFlags.Named;
84 | nameLen = Name.Length;
85 | }
86 |
87 | EndianUtilities.StringToBytes("vk", buffer, offset, 2);
88 | EndianUtilities.WriteBytesLittleEndian(nameLen, buffer, offset + 0x02);
89 | EndianUtilities.WriteBytesLittleEndian(DataLength, buffer, offset + 0x04);
90 | EndianUtilities.WriteBytesLittleEndian(DataIndex, buffer, offset + 0x08);
91 | EndianUtilities.WriteBytesLittleEndian((int)DataType, buffer, offset + 0x0C);
92 | EndianUtilities.WriteBytesLittleEndian((ushort)_flags, buffer, offset + 0x10);
93 | if (nameLen != 0)
94 | {
95 | EndianUtilities.StringToBytes(Name, buffer, offset + 0x14, nameLen);
96 | }
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Internal/LocalFileLocator.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using System.IO;
25 |
26 | namespace DiscUtils.Internal
27 | {
28 | internal sealed class LocalFileLocator : FileLocator
29 | {
30 | private readonly string _dir;
31 |
32 | public LocalFileLocator(string dir)
33 | {
34 | _dir = dir;
35 | }
36 |
37 | public override bool Exists(string fileName)
38 | {
39 | return File.Exists(Path.Combine(_dir, fileName));
40 | }
41 |
42 | protected override Stream OpenFile(string fileName, FileMode mode, FileAccess access, FileShare share)
43 | {
44 | return new FileStream(Path.Combine(_dir, fileName), mode, access, share);
45 | }
46 |
47 | public override FileLocator GetRelativeLocator(string path)
48 | {
49 | return new LocalFileLocator(Path.Combine(_dir, path));
50 | }
51 |
52 | public override string GetFullPath(string path)
53 | {
54 | string combinedPath = Path.Combine(_dir, path);
55 | if (string.IsNullOrEmpty(combinedPath))
56 | {
57 | #if NETSTANDARD1_5
58 | return Directory.GetCurrentDirectory();
59 | #else
60 | return Environment.CurrentDirectory;
61 | #endif
62 | }
63 | return Path.GetFullPath(combinedPath);
64 | }
65 |
66 | public override string GetDirectoryFromPath(string path)
67 | {
68 | return Path.GetDirectoryName(path);
69 | }
70 |
71 | public override string GetFileFromPath(string path)
72 | {
73 | return Path.GetFileName(path);
74 | }
75 |
76 | public override DateTime GetLastWriteTimeUtc(string path)
77 | {
78 | return File.GetLastWriteTimeUtc(Path.Combine(_dir, path));
79 | }
80 |
81 | public override bool HasCommonRoot(FileLocator other)
82 | {
83 | LocalFileLocator otherLocal = other as LocalFileLocator;
84 | if (otherLocal == null)
85 | {
86 | return false;
87 | }
88 |
89 | // If the paths have drive specifiers, then common root depends on them having a common
90 | // drive letter.
91 | string otherDir = otherLocal._dir;
92 | if (otherDir.Length >= 2 && _dir.Length >= 2)
93 | {
94 | if (otherDir[1] == ':' && _dir[1] == ':')
95 | {
96 | return char.ToUpperInvariant(otherDir[0]) == char.ToUpperInvariant(_dir[0]);
97 | }
98 | }
99 |
100 | return true;
101 | }
102 |
103 | public override string ResolveRelativePath(string path)
104 | {
105 | return Utilities.ResolveRelativePath(_dir, path);
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Classes/MethodHelpers.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Windows;
4 | using System.Windows.Media;
5 |
6 | namespace UWPSettingsEditor
7 | {
8 | public static class MethodHelpers
9 | {
10 | private const int SUBSTRING_ELLIPSIS_LENGTH = 128;
11 |
12 | public static IEnumerable SkipLast(this IEnumerable source, int count)
13 | {
14 | var e = source.GetEnumerator();
15 | var cache = new Queue(count + 1);
16 |
17 | using (e = source.GetEnumerator())
18 | {
19 | bool hasRemainingItems;
20 | do
21 | {
22 | if (hasRemainingItems = e.MoveNext())
23 | {
24 | cache.Enqueue(e.Current);
25 | if (cache.Count > count)
26 | yield return cache.Dequeue();
27 | }
28 | } while (hasRemainingItems);
29 | }
30 | }
31 |
32 | public static T VisualUpwardSearch(this DependencyObject source) where T : class
33 | {
34 | while (source != null && !(source is T))
35 | source = VisualTreeHelper.GetParent(source);
36 |
37 | return source as T;
38 | }
39 |
40 | //ToDo: find a better name for this pls
41 | ///
42 | /// Method for splitting the raw data into the actual timestamp + data
43 | ///
44 | /// Complete data raw
45 | /// KeyValuePair timestamp and data
46 | public static KeyValuePair SplitDataRaw(byte[] dataRaw)
47 | {
48 | byte[] data = dataRaw.SkipLast(8).ToArray();
49 | byte[] timestamp = dataRaw.Skip(data.Length).ToArray();
50 |
51 | return new KeyValuePair(timestamp, data);
52 | }
53 |
54 | public static string ReplaceMultilineWithSymbols(this string str)
55 | {
56 | var repStr = str.Replace("\r\n", "\\r\\n").Replace("\r", "\\r").Replace("\n", "\\n");
57 |
58 | if (repStr.Length + 3 > SUBSTRING_ELLIPSIS_LENGTH)
59 | repStr = repStr.Substring(0, SUBSTRING_ELLIPSIS_LENGTH - 3) + "...";
60 |
61 | return repStr;
62 | }
63 |
64 | //From here: https://stackoverflow.com/a/33307903
65 | public static unsafe bool EqualBytesLongUnrolled(byte[] data1, byte[] data2)
66 | {
67 | if (data1 == data2)
68 | return true;
69 |
70 | if (data1.Length != data2.Length)
71 | return false;
72 |
73 | fixed (byte* bytes1 = data1, bytes2 = data2)
74 | {
75 | int len = data1.Length;
76 | int rem = len % (sizeof(long) * 16);
77 | long* b1 = (long*)bytes1;
78 | long* b2 = (long*)bytes2;
79 | long* e1 = (long*)(bytes1 + len - rem);
80 |
81 | while (b1 < e1)
82 | {
83 | if (*(b1) != *(b2) || *(b1 + 1) != *(b2 + 1) ||
84 | *(b1 + 2) != *(b2 + 2) || *(b1 + 3) != *(b2 + 3) ||
85 | *(b1 + 4) != *(b2 + 4) || *(b1 + 5) != *(b2 + 5) ||
86 | *(b1 + 6) != *(b2 + 6) || *(b1 + 7) != *(b2 + 7) ||
87 | *(b1 + 8) != *(b2 + 8) || *(b1 + 9) != *(b2 + 9) ||
88 | *(b1 + 10) != *(b2 + 10) || *(b1 + 11) != *(b2 + 11) ||
89 | *(b1 + 12) != *(b2 + 12) || *(b1 + 13) != *(b2 + 13) ||
90 | *(b1 + 14) != *(b2 + 14) || *(b1 + 15) != *(b2 + 15))
91 | return false;
92 | b1 += 16;
93 | b2 += 16;
94 | }
95 |
96 | for (int i = 0; i < rem; i++)
97 | if (data1[len - 1 - i] != data2[len - 1 - i])
98 | return false;
99 |
100 | return true;
101 | }
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/RectComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 | using UWPSettingsEditor.Interfaces;
17 | using static UWPSettingsEditor.UWPDeserializer;
18 | using static UWPSettingsEditor.UWPSerializer;
19 |
20 | namespace UWPSettingsEditor.Controls
21 | {
22 | ///
23 | /// Interaction logic for RectComponent.xaml
24 | ///
25 | public partial class RectComponent : IValueDataSet
26 | {
27 | private DateTimeOffset _timestamp;
28 | private string _xDouble;
29 | private string _yDouble;
30 | private string _widthDouble;
31 | private string _heightDouble;
32 |
33 | public RectComponent()
34 | {
35 | DataContext = this;
36 | InitializeComponent();
37 | _timestamp = DateTimeOffset.Now;
38 | xBox.Text = "0";
39 | yBox.Text = "0";
40 | widthBox.Text = "0";
41 | heightBox.Text = "0";
42 | }
43 |
44 | public bool IsDataValid { get; private set; } = true;
45 |
46 | public string XDouble
47 | {
48 | get { return _xDouble; }
49 | set
50 | {
51 | if (IsAllValid())
52 | FlagDataAsValid();
53 |
54 | _xDouble = value;
55 | }
56 | }
57 |
58 | public string YDouble
59 | {
60 | get { return _yDouble; }
61 | set
62 | {
63 | if (IsAllValid())
64 | FlagDataAsValid();
65 |
66 | _yDouble = value;
67 | }
68 | }
69 | public string WidthDouble
70 | {
71 | get { return _widthDouble; }
72 | set
73 | {
74 | if (IsAllValid())
75 | FlagDataAsValid();
76 |
77 | _widthDouble = value;
78 | }
79 | }
80 | public string HeightDouble
81 | {
82 | get { return _heightDouble; }
83 | set
84 | {
85 | if (IsAllValid())
86 | FlagDataAsValid();
87 |
88 | _heightDouble = value;
89 | }
90 | }
91 |
92 | private bool IsAllValid()
93 | => !Validation.GetHasError(xBox) && !Validation.GetHasError(yBox)
94 | && !Validation.GetHasError(widthBox) && !Validation.GetHasError(heightBox);
95 |
96 | private void FlagDataAsValid()
97 | {
98 | IsDataValid = true;
99 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
100 | }
101 |
102 | private void FlagDataAsInvalid()
103 | {
104 | IsDataValid = false;
105 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
106 | }
107 |
108 | public event PropertyChangedEventHandler PropertyChanged;
109 |
110 | public byte[] GetValueData()
111 | => FromRect(new Rect(double.Parse(_xDouble), double.Parse(_yDouble), double.Parse(_widthDouble), double.Parse(_heightDouble)), _timestamp);
112 |
113 | public void SetValueData(byte[] dataRaw)
114 | {
115 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
116 |
117 | _timestamp = GetDateTimeOffset(tmp.Key);
118 | var rect = GetRect(tmp.Value);
119 | xBox.Text = rect.X.ToString("G17");
120 | yBox.Text = rect.Y.ToString("G17");
121 | widthBox.Text = rect.Width.ToString("G17");
122 | heightBox.Text = rect.Height.ToString("G17");
123 | }
124 |
125 | private void Valid_Error(object sender, ValidationErrorEventArgs e)
126 | {
127 | FlagDataAsInvalid();
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/PointSizeComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Globalization;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Windows;
9 | using System.Windows.Controls;
10 | using System.Windows.Data;
11 | using System.Windows.Documents;
12 | using System.Windows.Input;
13 | using System.Windows.Media;
14 | using System.Windows.Media.Imaging;
15 | using System.Windows.Navigation;
16 | using System.Windows.Shapes;
17 | using UWPSettingsEditor.Interfaces;
18 | using static UWPSettingsEditor.UWPDeserializer;
19 | using static UWPSettingsEditor.UWPSerializer;
20 |
21 | namespace UWPSettingsEditor.Controls
22 | {
23 | ///
24 | /// Interaction logic for PointRectComponent.xaml
25 | ///
26 | public partial class PointSizeComponent : IValueDataSet
27 | {
28 | private DataTypeEnum _dataType;
29 | private DateTimeOffset _timestamp;
30 | private string _firstDouble;
31 | private string _secondDouble;
32 |
33 | public string FirstDouble
34 | {
35 | get => _firstDouble;
36 | set
37 | {
38 | if (!Validation.GetHasError(secondBox))
39 | FlagDataAsValid();
40 |
41 | _firstDouble = value;
42 | }
43 | }
44 | public string SecondDouble
45 | {
46 | get => _secondDouble;
47 | set
48 | {
49 | if (!Validation.GetHasError(firstBox))
50 | FlagDataAsValid();
51 |
52 | _secondDouble = value;
53 | }
54 | }
55 |
56 | public PointSizeComponent(DataTypeEnum dataType)
57 | {
58 | DataContext = this;
59 | _dataType = dataType;
60 | InitializeComponent();
61 | _timestamp = DateTimeOffset.Now;
62 |
63 | firstBox.Text = "0";
64 | secondBox.Text = "0";
65 |
66 | if (_dataType == DataTypeEnum.RegUwpPoint)
67 | {
68 | firstBlock.Text = "X: ";
69 | secondBlock.Text = "Y: ";
70 | }
71 | else
72 | {
73 | firstBlock.Text = "Width: ";
74 | secondBlock.Text = "Height: ";
75 | }
76 | }
77 |
78 | public bool IsDataValid { get; private set; } = true;
79 |
80 | public event PropertyChangedEventHandler PropertyChanged;
81 |
82 | public byte[] GetValueData()
83 | {
84 | if (_dataType == DataTypeEnum.RegUwpPoint)
85 | {
86 | return FromPoint(new Point(double.Parse(_firstDouble), double.Parse(_secondDouble)), _timestamp);
87 | }
88 | else
89 | {
90 | return FromSize(new Size(double.Parse(_firstDouble), double.Parse(_secondDouble)), _timestamp);
91 | }
92 | }
93 |
94 | private void FlagDataAsValid()
95 | {
96 | IsDataValid = true;
97 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
98 | }
99 |
100 | private void FlagDataAsInvalid()
101 | {
102 | IsDataValid = false;
103 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
104 | }
105 |
106 | public void SetValueData(byte[] dataRaw)
107 | {
108 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
109 |
110 | _timestamp = GetDateTimeOffset(tmp.Key);
111 | if (_dataType == DataTypeEnum.RegUwpPoint)
112 | {
113 | var point = GetPoint(tmp.Value);
114 | firstBox.Text = point.X.ToString("G17");
115 | secondBox.Text = point.Y.ToString("G17");
116 | }
117 | else
118 | {
119 | var size = GetSize(tmp.Value);
120 | firstBox.Text = size.Width.ToString("G17");
121 | secondBox.Text = size.Height.ToString("G17");
122 | }
123 | }
124 |
125 | private void firstBox_Error(object sender, ValidationErrorEventArgs e)
126 | {
127 | FlagDataAsInvalid();
128 | }
129 |
130 | private void secondBox_Error(object sender, ValidationErrorEventArgs e)
131 | {
132 | FlagDataAsInvalid();
133 | }
134 | }
135 | class DoubleRule : ValidationRule
136 | {
137 | public override ValidationResult Validate(object value, CultureInfo cultureInfo)
138 | {
139 | if (double.TryParse((string)value, out _))
140 | return ValidationResult.ValidResult;
141 | else
142 | return new ValidationResult(false, "Not a valid double number");
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29709.97
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UWPSettingsEditor", "UWPSettingsEditor\UWPSettingsEditor.csproj", "{F51328FF-ECD3-46A5-B77E-4834ABD878E9}"
7 | EndProject
8 | Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "UWPSettingsEditorPkg", "UWPSettingsEditorPkg\UWPSettingsEditorPkg.wapproj", "{5E120AAC-B932-44C9-8190-ADD60081FB4A}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|ARM = Debug|ARM
14 | Debug|ARM64 = Debug|ARM64
15 | Debug|x64 = Debug|x64
16 | Debug|x86 = Debug|x86
17 | Release|Any CPU = Release|Any CPU
18 | Release|ARM = Release|ARM
19 | Release|ARM64 = Release|ARM64
20 | Release|x64 = Release|x64
21 | Release|x86 = Release|x86
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|ARM.ActiveCfg = Debug|Any CPU
27 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|ARM.Build.0 = Debug|Any CPU
28 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|ARM64.ActiveCfg = Debug|Any CPU
29 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|ARM64.Build.0 = Debug|Any CPU
30 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|x64.ActiveCfg = Debug|x64
31 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|x64.Build.0 = Debug|x64
32 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|x86.ActiveCfg = Debug|Any CPU
33 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Debug|x86.Build.0 = Debug|Any CPU
34 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|ARM.ActiveCfg = Release|Any CPU
37 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|ARM.Build.0 = Release|Any CPU
38 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|ARM64.ActiveCfg = Release|Any CPU
39 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|ARM64.Build.0 = Release|Any CPU
40 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|x64.ActiveCfg = Release|x64
41 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|x64.Build.0 = Release|x64
42 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|x86.ActiveCfg = Release|Any CPU
43 | {F51328FF-ECD3-46A5-B77E-4834ABD878E9}.Release|x86.Build.0 = Release|Any CPU
44 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
47 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|ARM.ActiveCfg = Debug|ARM
48 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|ARM.Build.0 = Debug|ARM
49 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|ARM.Deploy.0 = Debug|ARM
50 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|ARM64.ActiveCfg = Debug|ARM64
51 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|ARM64.Build.0 = Debug|ARM64
52 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|ARM64.Deploy.0 = Debug|ARM64
53 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|x64.ActiveCfg = Debug|x64
54 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|x64.Build.0 = Debug|x64
55 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|x64.Deploy.0 = Debug|x64
56 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|x86.ActiveCfg = Debug|x86
57 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|x86.Build.0 = Debug|x86
58 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Debug|x86.Deploy.0 = Debug|x86
59 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
60 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|Any CPU.Build.0 = Release|Any CPU
61 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|Any CPU.Deploy.0 = Release|Any CPU
62 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|ARM.ActiveCfg = Release|ARM
63 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|ARM.Build.0 = Release|ARM
64 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|ARM.Deploy.0 = Release|ARM
65 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|ARM64.ActiveCfg = Release|ARM64
66 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|ARM64.Build.0 = Release|ARM64
67 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|ARM64.Deploy.0 = Release|ARM64
68 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|x64.ActiveCfg = Release|x64
69 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|x64.Build.0 = Release|x64
70 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|x64.Deploy.0 = Release|x64
71 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|x86.ActiveCfg = Release|x86
72 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|x86.Build.0 = Release|x86
73 | {5E120AAC-B932-44C9-8190-ADD60081FB4A}.Release|x86.Deploy.0 = Release|x86
74 | EndGlobalSection
75 | GlobalSection(SolutionProperties) = preSolution
76 | HideSolutionNode = FALSE
77 | EndGlobalSection
78 | GlobalSection(ExtensibilityGlobals) = postSolution
79 | SolutionGuid = {95EBCB63-471C-4F6D-A0DD-0DA9677CC9CF}
80 | EndGlobalSection
81 | EndGlobal
82 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Interfaces/IBuffer.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System.Collections.Generic;
24 |
25 | namespace DiscUtils.Streams
26 | {
27 | ///
28 | /// Interface shared by all buffers.
29 | ///
30 | ///
31 | /// Buffers are very similar to streams, except the buffer has no notion of
32 | /// 'current position'. All I/O operations instead specify the position, as
33 | /// needed. Buffers also support sparse behaviour.
34 | ///
35 | public interface IBuffer
36 | {
37 | ///
38 | /// Gets a value indicating whether this buffer can be read.
39 | ///
40 | bool CanRead { get; }
41 |
42 | ///
43 | /// Gets a value indicating whether this buffer can be modified.
44 | ///
45 | bool CanWrite { get; }
46 |
47 | ///
48 | /// Gets the current capacity of the buffer, in bytes.
49 | ///
50 | long Capacity { get; }
51 |
52 | ///
53 | /// Gets the parts of the buffer that are stored.
54 | ///
55 | /// This may be an empty enumeration if all bytes are zero.
56 | IEnumerable Extents { get; }
57 |
58 | ///
59 | /// Reads from the buffer into a byte array.
60 | ///
61 | /// The offset within the buffer to start reading.
62 | /// The destination byte array.
63 | /// The start offset within the destination buffer.
64 | /// The number of bytes to read.
65 | /// The actual number of bytes read.
66 | int Read(long pos, byte[] buffer, int offset, int count);
67 |
68 | ///
69 | /// Writes a byte array into the buffer.
70 | ///
71 | /// The start offset within the buffer.
72 | /// The source byte array.
73 | /// The start offset within the source byte array.
74 | /// The number of bytes to write.
75 | void Write(long pos, byte[] buffer, int offset, int count);
76 |
77 | ///
78 | /// Clears bytes from the buffer.
79 | ///
80 | /// The start offset within the buffer.
81 | /// The number of bytes to clear.
82 | ///
83 | /// Logically equivalent to writing count null/zero bytes to the buffer, some
84 | /// implementations determine that some (or all) of the range indicated is not actually
85 | /// stored. There is no direct, automatic, correspondence to clearing bytes and them
86 | /// not being represented as an 'extent' - for example, the implementation of the underlying
87 | /// stream may not permit fine-grained extent storage.
88 | /// It is always safe to call this method to 'zero-out' a section of a buffer, regardless of
89 | /// the underlying buffer implementation.
90 | ///
91 | void Clear(long pos, int count);
92 |
93 | ///
94 | /// Flushes all data to the underlying storage.
95 | ///
96 | void Flush();
97 |
98 | ///
99 | /// Sets the capacity of the buffer, truncating if appropriate.
100 | ///
101 | /// The desired capacity of the buffer.
102 | void SetCapacity(long value);
103 |
104 | ///
105 | /// Gets the parts of a buffer that are stored, within a specified range.
106 | ///
107 | /// The offset of the first byte of interest.
108 | /// The number of bytes of interest.
109 | /// An enumeration of stream extents, indicating stored bytes.
110 | IEnumerable GetExtentsInRange(long start, long count);
111 | }
112 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Util/MathUtilities.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 |
25 | namespace DiscUtils.Streams
26 | {
27 | public static class MathUtilities
28 | {
29 | ///
30 | /// Round up a value to a multiple of a unit size.
31 | ///
32 | /// The value to round up.
33 | /// The unit (the returned value will be a multiple of this number).
34 | /// The rounded-up value.
35 | public static long RoundUp(long value, long unit)
36 | {
37 | return (value + (unit - 1)) / unit * unit;
38 | }
39 |
40 | ///
41 | /// Round up a value to a multiple of a unit size.
42 | ///
43 | /// The value to round up.
44 | /// The unit (the returned value will be a multiple of this number).
45 | /// The rounded-up value.
46 | public static int RoundUp(int value, int unit)
47 | {
48 | return (value + (unit - 1)) / unit * unit;
49 | }
50 |
51 | ///
52 | /// Round down a value to a multiple of a unit size.
53 | ///
54 | /// The value to round down.
55 | /// The unit (the returned value will be a multiple of this number).
56 | /// The rounded-down value.
57 | public static long RoundDown(long value, long unit)
58 | {
59 | return value / unit * unit;
60 | }
61 |
62 | ///
63 | /// Calculates the CEIL function.
64 | ///
65 | /// The value to divide.
66 | /// The value to divide by.
67 | /// The value of CEIL(numerator/denominator).
68 | public static int Ceil(int numerator, int denominator)
69 | {
70 | return (numerator + (denominator - 1)) / denominator;
71 | }
72 |
73 | ///
74 | /// Calculates the CEIL function.
75 | ///
76 | /// The value to divide.
77 | /// The value to divide by.
78 | /// The value of CEIL(numerator/denominator).
79 | public static uint Ceil(uint numerator, uint denominator)
80 | {
81 | return (numerator + (denominator - 1)) / denominator;
82 | }
83 |
84 | ///
85 | /// Calculates the CEIL function.
86 | ///
87 | /// The value to divide.
88 | /// The value to divide by.
89 | /// The value of CEIL(numerator/denominator).
90 | public static long Ceil(long numerator, long denominator)
91 | {
92 | return (numerator + (denominator - 1)) / denominator;
93 | }
94 |
95 | public static int Log2(uint val)
96 | {
97 | if (val == 0)
98 | {
99 | throw new ArgumentException("Cannot calculate log of Zero", nameof(val));
100 | }
101 |
102 | int result = 0;
103 | while ((val & 1) != 1)
104 | {
105 | val >>= 1;
106 | ++result;
107 | }
108 |
109 | if (val == 1)
110 | {
111 | return result;
112 | }
113 | throw new ArgumentException("Input is not a power of Two", nameof(val));
114 | }
115 |
116 | public static int Log2(int val)
117 | {
118 | if (val == 0)
119 | {
120 | throw new ArgumentException("Cannot calculate log of Zero", nameof(val));
121 | }
122 |
123 | int result = 0;
124 | while ((val & 1) != 1)
125 | {
126 | val >>= 1;
127 | ++result;
128 | }
129 |
130 | if (val == 1)
131 | {
132 | return result;
133 | }
134 | throw new ArgumentException("Input is not a power of Two", nameof(val));
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditorPkg/UWPSettingsEditorPkg.wapproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 15.0
5 |
6 |
7 |
8 | Debug
9 | x86
10 |
11 |
12 | Release
13 | x86
14 |
15 |
16 | Debug
17 | x64
18 |
19 |
20 | Release
21 | x64
22 |
23 |
24 | Debug
25 | ARM
26 |
27 |
28 | Release
29 | ARM
30 |
31 |
32 | Debug
33 | ARM64
34 |
35 |
36 | Release
37 | ARM64
38 |
39 |
40 | Debug
41 | AnyCPU
42 |
43 |
44 | Release
45 | AnyCPU
46 |
47 |
48 |
49 | $(MSBuildExtensionsPath)\Microsoft\DesktopBridge\
50 |
51 |
52 |
53 | 5e120aac-b932-44c9-8190-add60081fb4a
54 | 10.0.17763.0
55 | 10.0.17763.0
56 | en-US
57 | True
58 | ..\UWPSettingsEditor\UWPSettingsEditor.csproj
59 | False
60 | E714182BE3AE834C1C5FF57E1AD4086C69559BAF
61 | SHA256
62 | False
63 | False
64 | True
65 | neutral
66 | 0
67 |
68 |
69 | Always
70 |
71 |
72 | Always
73 |
74 |
75 | Always
76 |
77 |
78 | Always
79 |
80 |
81 | Always
82 |
83 |
84 | Always
85 |
86 |
87 | Always
88 |
89 |
90 | Always
91 |
92 |
93 | Always
94 |
95 |
96 | Always
97 |
98 |
99 |
100 | Designer
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Util/Range.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using System.Collections.Generic;
25 |
26 | namespace DiscUtils.Streams
27 | {
28 | ///
29 | /// Represents a range of values.
30 | ///
31 | /// The type of the offset element.
32 | /// The type of the size element.
33 | public class Range : IEquatable>
34 | where TOffset : IEquatable
35 | where TCount : IEquatable
36 | {
37 | ///
38 | /// Initializes a new instance of the Range class.
39 | ///
40 | /// The offset (i.e. start) of the range.
41 | /// The size of the range.
42 | public Range(TOffset offset, TCount count)
43 | {
44 | Offset = offset;
45 | Count = count;
46 | }
47 |
48 | ///
49 | /// Gets the size of the range.
50 | ///
51 | public TCount Count { get; }
52 |
53 | ///
54 | /// Gets the offset (i.e. start) of the range.
55 | ///
56 | public TOffset Offset { get; }
57 |
58 | #region IEquatable> Members
59 |
60 | ///
61 | /// Compares this range to another.
62 | ///
63 | /// The range to compare.
64 | /// true if the ranges are equivalent, else false.
65 | public bool Equals(Range other)
66 | {
67 | if (other == null)
68 | {
69 | return false;
70 | }
71 |
72 | return Offset.Equals(other.Offset) && Count.Equals(other.Count);
73 | }
74 |
75 | #endregion
76 |
77 | ///
78 | /// Merges sets of ranges into chunks.
79 | ///
80 | /// The ranges to merge.
81 | /// The size of each chunk.
82 | /// Ranges combined into larger chunks.
83 | /// The type of the offset and count in the ranges.
84 | public static IEnumerable> Chunked(IEnumerable> ranges, T chunkSize)
85 | where T : struct, IEquatable, IComparable
86 | {
87 | T? chunkStart = Numbers.Zero;
88 | T chunkLength = Numbers.Zero;
89 |
90 | foreach (Range range in ranges)
91 | {
92 | if (Numbers.NotEqual(range.Count, Numbers.Zero))
93 | {
94 | T rangeStart = Numbers.RoundDown(range.Offset, chunkSize);
95 | T rangeNext = Numbers.RoundUp(Numbers.Add(range.Offset, range.Count), chunkSize);
96 |
97 | if (chunkStart.HasValue &&
98 | Numbers.GreaterThan(rangeStart, Numbers.Add(chunkStart.Value, chunkLength)))
99 | {
100 | // This extent is non-contiguous (in terms of blocks), so write out the last range and start new
101 | yield return new Range(chunkStart.Value, chunkLength);
102 | chunkStart = rangeStart;
103 | }
104 | else if (!chunkStart.HasValue)
105 | {
106 | // First extent, so start first range
107 | chunkStart = rangeStart;
108 | }
109 |
110 | // Set the length of the current range, based on the end of this extent
111 | chunkLength = Numbers.Subtract(rangeNext, chunkStart.Value);
112 | }
113 | }
114 |
115 | // Final range (if any ranges at all) hasn't been returned yet, so do that now
116 | if (chunkStart.HasValue)
117 | {
118 | yield return new Range(chunkStart.Value, chunkLength);
119 | }
120 | }
121 |
122 | ///
123 | /// Returns a string representation of the extent as [start:+length].
124 | ///
125 | /// The string representation.
126 | public override string ToString()
127 | {
128 | return "[" + Offset + ":+" + Count + "]";
129 | }
130 | }
131 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/HiveHeader.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using System.IO;
25 | using System.Text;
26 | using DiscUtils.Streams;
27 |
28 | namespace DiscUtils.Registry
29 | {
30 | internal sealed class HiveHeader : IByteArraySerializable
31 | {
32 | public const int HeaderSize = 512;
33 |
34 | private const uint Signature = 0x66676572;
35 | public uint Checksum;
36 | public Guid Guid1;
37 | public Guid Guid2;
38 | public int Length;
39 | public int MajorVersion;
40 | public int MinorVersion;
41 | public string Path;
42 | public int RootCell;
43 |
44 | public int Sequence1;
45 | public int Sequence2;
46 | public DateTime Timestamp;
47 |
48 | public HiveHeader()
49 | {
50 | Sequence1 = 1;
51 | Sequence2 = 1;
52 | Timestamp = DateTime.UtcNow;
53 | MajorVersion = 1;
54 | MinorVersion = 3;
55 | RootCell = -1;
56 | Path = string.Empty;
57 | Guid1 = Guid.NewGuid();
58 | Guid2 = Guid.NewGuid();
59 | }
60 |
61 | public int Size
62 | {
63 | get { return HeaderSize; }
64 | }
65 |
66 | public int ReadFrom(byte[] buffer, int offset)
67 | {
68 | uint sig = EndianUtilities.ToUInt32LittleEndian(buffer, offset + 0);
69 | if (sig != Signature)
70 | {
71 | throw new IOException("Invalid signature for registry hive");
72 | }
73 |
74 | Sequence1 = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x0004);
75 | Sequence2 = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x0008);
76 |
77 | Timestamp = DateTime.FromFileTimeUtc(EndianUtilities.ToInt64LittleEndian(buffer, offset + 0x000C));
78 |
79 | MajorVersion = EndianUtilities.ToInt32LittleEndian(buffer, 0x0014);
80 | MinorVersion = EndianUtilities.ToInt32LittleEndian(buffer, 0x0018);
81 |
82 | int isLog = EndianUtilities.ToInt32LittleEndian(buffer, 0x001C);
83 |
84 | RootCell = EndianUtilities.ToInt32LittleEndian(buffer, 0x0024);
85 | Length = EndianUtilities.ToInt32LittleEndian(buffer, 0x0028);
86 |
87 | Path = Encoding.Unicode.GetString(buffer, 0x0030, 0x0040).Trim('\0');
88 |
89 | Guid1 = EndianUtilities.ToGuidLittleEndian(buffer, 0x0070);
90 | Guid2 = EndianUtilities.ToGuidLittleEndian(buffer, 0x0094);
91 |
92 | Checksum = EndianUtilities.ToUInt32LittleEndian(buffer, 0x01FC);
93 |
94 | if (Sequence1 != Sequence2)
95 | {
96 | throw new NotImplementedException("Support for replaying registry log file");
97 | }
98 |
99 | if (Checksum != CalcChecksum(buffer, offset))
100 | {
101 | throw new IOException("Invalid checksum on registry file");
102 | }
103 |
104 | return HeaderSize;
105 | }
106 |
107 | public void WriteTo(byte[] buffer, int offset)
108 | {
109 | EndianUtilities.WriteBytesLittleEndian(Signature, buffer, offset);
110 | EndianUtilities.WriteBytesLittleEndian(Sequence1, buffer, offset + 0x0004);
111 | EndianUtilities.WriteBytesLittleEndian(Sequence2, buffer, offset + 0x0008);
112 | EndianUtilities.WriteBytesLittleEndian(Timestamp.ToFileTimeUtc(), buffer, offset + 0x000C);
113 | EndianUtilities.WriteBytesLittleEndian(MajorVersion, buffer, offset + 0x0014);
114 | EndianUtilities.WriteBytesLittleEndian(MinorVersion, buffer, offset + 0x0018);
115 |
116 | EndianUtilities.WriteBytesLittleEndian((uint)1, buffer, offset + 0x0020); // Unknown - seems to be '1'
117 |
118 | EndianUtilities.WriteBytesLittleEndian(RootCell, buffer, offset + 0x0024);
119 | EndianUtilities.WriteBytesLittleEndian(Length, buffer, offset + 0x0028);
120 |
121 | Encoding.Unicode.GetBytes(Path, 0, Path.Length, buffer, offset + 0x0030);
122 | EndianUtilities.WriteBytesLittleEndian((ushort)0, buffer, offset + 0x0030 + Path.Length * 2);
123 |
124 | EndianUtilities.WriteBytesLittleEndian(Guid1, buffer, offset + 0x0070);
125 | EndianUtilities.WriteBytesLittleEndian(Guid2, buffer, offset + 0x0094);
126 |
127 | EndianUtilities.WriteBytesLittleEndian(CalcChecksum(buffer, offset), buffer, offset + 0x01FC);
128 | }
129 |
130 | private static uint CalcChecksum(byte[] buffer, int offset)
131 | {
132 | uint sum = 0;
133 |
134 | for (int i = 0; i < 0x01FC; i += 4)
135 | {
136 | sum = sum ^ EndianUtilities.ToUInt32LittleEndian(buffer, offset + i);
137 | }
138 |
139 | return sum;
140 | }
141 | }
142 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Converters/DataTypeEnumToStringConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows.Data;
4 |
5 | namespace UWPSettingsEditor.Converters
6 | {
7 | public class DataTypeEnumToStringConverter : IValueConverter
8 | {
9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | var dataType = (DataTypeEnum)value;
12 | return GetStringNameFromDataType(dataType);
13 | }
14 |
15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16 | {
17 | throw new NotImplementedException();
18 | }
19 |
20 | private string GetStringNameFromDataType(DataTypeEnum dataType)
21 | {
22 | switch (dataType)
23 | {
24 | case DataTypeEnum.RegNone:
25 | return "REG_NONE";
26 | case DataTypeEnum.RegSz:
27 | return "REG_SZ";
28 | case DataTypeEnum.RegExpandSz:
29 | return "REG_EXPAND_SZ";
30 | case DataTypeEnum.RegBinary:
31 | return "REG_BINARY";
32 | case DataTypeEnum.RegDword:
33 | return "REG_DWORD";
34 | case DataTypeEnum.RegDwordBigEndian:
35 | return "REG_DWORD_BIG_ENDIAN";
36 | case DataTypeEnum.RegLink:
37 | return "REG_LINK";
38 | case DataTypeEnum.RegMultiSz:
39 | return "REG_MULTI_SZ";
40 | case DataTypeEnum.RegResourceList:
41 | return "REG_RESOURCE_LIST";
42 | case DataTypeEnum.RegFullResourceDescription:
43 | return "REG_FULL_RES_DESC";
44 | case DataTypeEnum.RegResourceRequirementsList:
45 | return "REG_RES_REQ_LIST";
46 | case DataTypeEnum.RegQword:
47 | return "REG_QWORD";
48 | case DataTypeEnum.RegFileTime:
49 | return "REG_FILETIME";
50 | case DataTypeEnum.RegUwpByte:
51 | return "REG_UWP_BYTE";
52 | case DataTypeEnum.RegUwpInt16:
53 | return "REG_UWP_INT16";
54 | case DataTypeEnum.RegUwpUint16:
55 | return "REG_UWP_UINT16";
56 | case DataTypeEnum.RegUwpInt32:
57 | return "REG_UWP_INT32";
58 | case DataTypeEnum.RegUwpUint32:
59 | return "REG_UWP_UINT32";
60 | case DataTypeEnum.RegUwpInt64:
61 | return "REG_UWP_INT64";
62 | case DataTypeEnum.RegUwpUint64:
63 | return "REG_UWP_UINT64";
64 | case DataTypeEnum.RegUwpSingle:
65 | return "REG_UWP_SINGLE";
66 | case DataTypeEnum.RegUwpDouble:
67 | return "REG_UWP_DOUBLE";
68 | case DataTypeEnum.RegUwpChar:
69 | return "REG_UWP_CHAR";
70 | case DataTypeEnum.RegUwpBoolean:
71 | return "REG_UWP_BOOLEAN";
72 | case DataTypeEnum.RegUwpString:
73 | return "REG_UWP_STRING";
74 | case DataTypeEnum.RegUwpCompositeValue:
75 | return "REG_UWP_COMPOSITE";
76 | case DataTypeEnum.RegUwpDateTimeOffset:
77 | return "REG_UWP_DATETIMEOFFSET";
78 | case DataTypeEnum.RegUwpTimeSpan:
79 | return "REG_UWP_TIMESPAN";
80 | case DataTypeEnum.RegUwpGuid:
81 | return "REG_UWP_GUID";
82 | case DataTypeEnum.RegUwpPoint:
83 | return "REG_UWP_POINT";
84 | case DataTypeEnum.RegUwpSize:
85 | return "REG_UWP_SIZE";
86 | case DataTypeEnum.RegUwpRect:
87 | return "REG_UWP_RECT";
88 | case DataTypeEnum.RegUwpArrayByte:
89 | return "REG_UWP_ARRAY_BYTE";
90 | case DataTypeEnum.RegUwpArrayInt16:
91 | return "REG_UWP_ARRAY_INT16";
92 | case DataTypeEnum.RegUwpArrayUint16:
93 | return "REG_UWP_ARRAY_UINT16";
94 | case DataTypeEnum.RegUwpArrayInt32:
95 | return "REG_UWP_ARRAY_INT32";
96 | case DataTypeEnum.RegUwpArrayUint32:
97 | return "REG_UWP_ARRAY_UINT32";
98 | case DataTypeEnum.RegUwpArrayInt64:
99 | return "REG_UWP_ARRAY_INT64";
100 | case DataTypeEnum.RegUwpArrayUint64:
101 | return "REG_UWP_ARRAY_UINT64";
102 | case DataTypeEnum.RegUwpArraySingle:
103 | return "REG_UWP_ARRAY_SINGLE";
104 | case DataTypeEnum.RegUwpArrayDouble:
105 | return "REG_UWP_ARRAY_DOUBLE";
106 | case DataTypeEnum.RegUwpArrayChar16:
107 | return "REG_UWP_ARRAY_CHAR16";
108 | case DataTypeEnum.RegUwpArrayBoolean:
109 | return "REG_UWP_ARRAY_BOOLEAN";
110 | case DataTypeEnum.RegUwpArrayString:
111 | return "REG_UWP_ARRAY_STRING";
112 | case DataTypeEnum.RegUwpArrayDateTimeOffset:
113 | return "REG_UWP_ARRAY_DATETIMEOFFSET";
114 | case DataTypeEnum.RegUwpArrayTimeSpan:
115 | return "REG_UWP_ARRAY_TIMESPAN";
116 | case DataTypeEnum.RegUwpArrayGuid:
117 | return "REG_UWP_ARRAY_GUID";
118 | case DataTypeEnum.RegUwpArrayPoint:
119 | return "REG_UWP_ARRAY_POINT";
120 | case DataTypeEnum.RegUwpArraySize:
121 | return "REG_UWP_ARRAY_SIZE";
122 | case DataTypeEnum.RegUwpArrayRect:
123 | return "REG_UWP_ARRAY_RECT";
124 | case DataTypeEnum.RegUnknown:
125 | default:
126 | return "UNKNOWN (" + dataType + ")";
127 | }
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/KeyNodeCell.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 | using DiscUtils.Streams;
25 |
26 | namespace DiscUtils.Registry
27 | {
28 | internal sealed class KeyNodeCell : Cell
29 | {
30 | public int ClassNameIndex;
31 | public int ClassNameLength;
32 | public RegistryKeyFlags Flags;
33 |
34 | public int IndexInParent;
35 |
36 | ///
37 | /// Number of bytes to represent largest subkey name in Unicode - no null terminator.
38 | ///
39 | public int MaxSubKeyNameBytes;
40 |
41 | ///
42 | /// Number of bytes to represent largest value content (strings in Unicode, with null terminator - if stored).
43 | ///
44 | public int MaxValDataBytes;
45 |
46 | ///
47 | /// Number of bytes to represent largest value name in Unicode - no null terminator.
48 | ///
49 | public int MaxValNameBytes;
50 |
51 | public string Name;
52 | public int NumSubKeys;
53 | public int NumValues;
54 | public int ParentIndex;
55 | public int SecurityIndex;
56 | public int SubKeysIndex;
57 | public DateTime Timestamp;
58 | public int ValueListIndex;
59 |
60 | public KeyNodeCell(string name, int parentCellIndex)
61 | : this(-1)
62 | {
63 | Flags = RegistryKeyFlags.Normal;
64 | Timestamp = DateTime.UtcNow;
65 | ParentIndex = parentCellIndex;
66 | SubKeysIndex = -1;
67 | ValueListIndex = -1;
68 | SecurityIndex = -1;
69 | ClassNameIndex = -1;
70 | Name = name;
71 | }
72 |
73 | public KeyNodeCell(int index)
74 | : base(index) {}
75 |
76 | public override int Size
77 | {
78 | get { return 0x4C + Name.Length; }
79 | }
80 |
81 | public override int ReadFrom(byte[] buffer, int offset)
82 | {
83 | Flags = (RegistryKeyFlags)EndianUtilities.ToUInt16LittleEndian(buffer, offset + 0x02);
84 | Timestamp = DateTime.FromFileTimeUtc(EndianUtilities.ToInt64LittleEndian(buffer, offset + 0x04));
85 | ParentIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x10);
86 | NumSubKeys = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x14);
87 | SubKeysIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x1C);
88 | NumValues = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x24);
89 | ValueListIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x28);
90 | SecurityIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x2C);
91 | ClassNameIndex = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x30);
92 | MaxSubKeyNameBytes = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x34);
93 | MaxValNameBytes = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x3C);
94 | MaxValDataBytes = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x40);
95 | IndexInParent = EndianUtilities.ToInt32LittleEndian(buffer, offset + 0x44);
96 | int nameLength = EndianUtilities.ToInt16LittleEndian(buffer, offset + 0x48);
97 | ClassNameLength = EndianUtilities.ToInt16LittleEndian(buffer, offset + 0x4A);
98 | Name = EndianUtilities.BytesToString(buffer, offset + 0x4C, nameLength);
99 |
100 | return 0x4C + nameLength;
101 | }
102 |
103 | public override void WriteTo(byte[] buffer, int offset)
104 | {
105 | EndianUtilities.StringToBytes("nk", buffer, offset, 2);
106 | EndianUtilities.WriteBytesLittleEndian((ushort)Flags, buffer, offset + 0x02);
107 | EndianUtilities.WriteBytesLittleEndian(Timestamp.ToFileTimeUtc(), buffer, offset + 0x04);
108 | EndianUtilities.WriteBytesLittleEndian(ParentIndex, buffer, offset + 0x10);
109 | EndianUtilities.WriteBytesLittleEndian(NumSubKeys, buffer, offset + 0x14);
110 | EndianUtilities.WriteBytesLittleEndian(SubKeysIndex, buffer, offset + 0x1C);
111 | EndianUtilities.WriteBytesLittleEndian(NumValues, buffer, offset + 0x24);
112 | EndianUtilities.WriteBytesLittleEndian(ValueListIndex, buffer, offset + 0x28);
113 | EndianUtilities.WriteBytesLittleEndian(SecurityIndex, buffer, offset + 0x2C);
114 | EndianUtilities.WriteBytesLittleEndian(ClassNameIndex, buffer, offset + 0x30);
115 | EndianUtilities.WriteBytesLittleEndian(IndexInParent, buffer, offset + 0x44);
116 | EndianUtilities.WriteBytesLittleEndian((ushort)Name.Length, buffer, offset + 0x48);
117 | EndianUtilities.WriteBytesLittleEndian(ClassNameLength, buffer, offset + 0x4A);
118 | EndianUtilities.StringToBytes(Name, buffer, offset + 0x4C, Name.Length);
119 | }
120 |
121 | public override string ToString()
122 | {
123 | return "Key:" + Name + "[" + Flags + "] <" + Timestamp + ">";
124 | }
125 | }
126 | }
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Windows/EditValueWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using UWPSettingsEditor.Interfaces;
2 | using UWPSettingsEditor.Controls;
3 | using static UWPSettingsEditor.UWPDeserializer;
4 | using System.Windows.Interop;
5 | using static UWPSettingsEditor.NativeMethods;
6 | using System;
7 | using System.Runtime.InteropServices;
8 |
9 | namespace UWPSettingsEditor
10 | {
11 | ///
12 | /// Interaction logic for EditValueWindow.xaml
13 | ///
14 | public partial class EditValueWindow
15 | {
16 | public bool IsKeyValueEdited { get; private set; }
17 | public bool IsKeyNameEdited { get; private set; }
18 |
19 | readonly IValueDataSet valueDataSet;
20 | readonly KeyVal currentKeyVal;
21 |
22 | public EditValueWindow(KeyVal val)
23 | {
24 | var hndl = new WindowInteropHelper(this).EnsureHandle();
25 | IntPtr brush = CreateSolidBrush(uint.MinValue);
26 | SetClassLong(hndl, -10, brush);
27 |
28 | SetWindowTheme(hndl, "DarkMode_Explorer", IntPtr.Zero);
29 |
30 | int attrValue = 1; //TRUE
31 | DwmSetWindowAttribute(hndl, 20, ref attrValue, Marshal.SizeOf(typeof(int)));
32 |
33 | //DARK THEME ^
34 |
35 | currentKeyVal = val;
36 |
37 | InitializeComponent();
38 | ValueNameTextBox.Text = val.Name;
39 |
40 | if (val.DataTypeEnum == DataTypeEnum.RegUwpString)
41 | {
42 | var componentControl = new StringComponent();
43 | ContainerGrid.Children.Add(componentControl);
44 | valueDataSet = componentControl;
45 | SetMinHeightAndHeight(250);
46 | ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip;
47 | }
48 | else if (val.DataTypeEnum == DataTypeEnum.RegUwpBoolean)
49 | {
50 | var componentControl = new BooleanComponent();
51 | ContainerGrid.Children.Add(componentControl);
52 | valueDataSet = componentControl;
53 | SetMinHeightAndHeight(154);
54 | }
55 | else if ((int)val.DataTypeEnum >= (int)DataTypeEnum.RegUwpByte &&
56 | (int)val.DataTypeEnum <= (int)DataTypeEnum.RegUwpDouble) //byte, int16, uint16, int32, uint32, int64, uint64, double, single
57 | {
58 | var componentControl = new IntComponent(val.DataTypeEnum);
59 | ContainerGrid.Children.Add(componentControl);
60 | valueDataSet = componentControl;
61 | SetMinHeightAndHeight(154);
62 | }
63 | else if (val.DataTypeEnum == DataTypeEnum.RegUwpDateTimeOffset)
64 | {
65 | var componentControl = new DateTimeOffsetComponent();
66 | ContainerGrid.Children.Add(componentControl);
67 | valueDataSet = componentControl;
68 | SetMinHeightAndHeight(154);
69 | }
70 | else if (val.DataTypeEnum == DataTypeEnum.RegUwpChar)
71 | {
72 | var componentControl = new CharComponent();
73 | ContainerGrid.Children.Add(componentControl);
74 | valueDataSet = componentControl;
75 | SetMinHeightAndHeight(154);
76 | }
77 | else if (val.DataTypeEnum == DataTypeEnum.RegUwpGuid)
78 | {
79 | var componentControl = new GuidComponent();
80 | ContainerGrid.Children.Add(componentControl);
81 | valueDataSet = componentControl;
82 | SetMinHeightAndHeight(154);
83 | }
84 | else if (val.DataTypeEnum == DataTypeEnum.RegUwpRect)
85 | {
86 | var componentControl = new RectComponent();
87 | ContainerGrid.Children.Add(componentControl);
88 | valueDataSet = componentControl;
89 | SetMinHeightAndHeight(154);
90 | }
91 | else if (val.DataTypeEnum == DataTypeEnum.RegUwpPoint || val.DataTypeEnum == DataTypeEnum.RegUwpSize)
92 | {
93 | var componentControl = new PointSizeComponent(val.DataTypeEnum);
94 | ContainerGrid.Children.Add(componentControl);
95 | valueDataSet = componentControl;
96 | SetMinHeightAndHeight(154);
97 | }
98 | else
99 | {
100 | unimplementedTxt.Visibility = System.Windows.Visibility.Visible;
101 | }
102 |
103 | Title = $"Edit value [type: {val.DataTypeEnum}]";
104 |
105 | valueDataSet?.SetValueData(val.Data);
106 | if (valueDataSet != null)
107 | valueDataSet.PropertyChanged += ValueDataSet_PropertyChanged;
108 | }
109 |
110 | private void ValueDataSet_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
111 | {
112 | if (e.PropertyName == "IsDataValid")
113 | {
114 | if (valueDataSet.IsDataValid)
115 | OkButton.IsEnabled = true;
116 | else
117 | OkButton.IsEnabled = false;
118 | }
119 | }
120 |
121 | private void SetMinHeightAndHeight(double targetHeight)
122 | {
123 | MinHeight = targetHeight;
124 | Height = targetHeight;
125 | }
126 |
127 | private void CancelButton_Click(object sender, System.Windows.RoutedEventArgs e)
128 | {
129 | DialogResult = false;
130 | }
131 |
132 | public byte[] GetValueData() => valueDataSet?.GetValueData();
133 | public string GetValueName() => ValueNameTextBox.Text;
134 |
135 | private void OKButton_Click(object sender, System.Windows.RoutedEventArgs e)
136 | {
137 | //if edited, return true otherwise false
138 |
139 | if (valueDataSet == null)
140 | {
141 | DialogResult = false;
142 | return;
143 | }
144 |
145 | var val = valueDataSet.GetValueData();
146 | IsKeyValueEdited = !MethodHelpers.EqualBytesLongUnrolled(val, currentKeyVal.Data);
147 | IsKeyNameEdited = ValueNameTextBox.Text != currentKeyVal.Name;
148 |
149 | DialogResult = (IsKeyNameEdited || IsKeyValueEdited);
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Classes/Serializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace UWPSettingsEditor
8 | {
9 | public static class UWPSerializer
10 | {
11 | public static byte[] FromByte(byte data, DateTimeOffset? timestamp = null)
12 | => new byte[] { data }.AppendTimestamp(timestamp);
13 | public static byte[] FromInt16(short data, DateTimeOffset? timestamp = null)
14 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
15 | public static byte[] FromUInt16(ushort data, DateTimeOffset? timestamp = null)
16 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
17 | public static byte[] FromInt32(int data, DateTimeOffset? timestamp = null)
18 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
19 | public static byte[] FromUInt32(uint data, DateTimeOffset? timestamp = null)
20 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
21 | public static byte[] FromInt64(long data, DateTimeOffset? timestamp = null)
22 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
23 | public static byte[] FromUInt64(ulong data, DateTimeOffset? timestamp = null)
24 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
25 |
26 |
27 | public static byte[] FromSingle(float data, DateTimeOffset? timestamp = null)
28 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
29 | public static byte[] FromDouble(double data, DateTimeOffset? timestamp = null)
30 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
31 |
32 | public static byte[] FromChar(char data, DateTimeOffset? timestamp = null)
33 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
34 | public static byte[] FromBoolean(bool data, DateTimeOffset? timestamp = null)
35 | => BitConverter.GetBytes(data).AppendTimestamp(timestamp);
36 |
37 |
38 | public static byte[] FromString(string data, DateTimeOffset? timestamp = null)
39 | => Encoding.Unicode.GetBytes(data).AppendTimestamp(timestamp);
40 |
41 | public static byte[] FromDateTimeOffset(DateTimeOffset data, DateTimeOffset? timestamp = null)
42 | => BitConverter.GetBytes(data.ToFileTime()).AppendTimestamp(timestamp);
43 | public static byte[] FromTimeSpan(TimeSpan data, DateTimeOffset? timestamp = null)
44 | => BitConverter.GetBytes(data.Ticks).AppendTimestamp(timestamp);
45 |
46 | public static byte[] FromGuid(Guid data, DateTimeOffset? timestamp = null)
47 | => data.ToByteArray().AppendTimestamp(timestamp);
48 |
49 | public static byte[] FromPoint(Point data, DateTimeOffset? timestamp = null)
50 | {
51 | byte[] x = BitConverter.GetBytes((float)data.X);
52 | byte[] y = BitConverter.GetBytes((float)data.Y);
53 |
54 | byte[] array = new byte[8];
55 | Array.Copy(x, 0, array, 0, x.Length);
56 | Array.Copy(y, 0, array, x.Length, y.Length);
57 |
58 | return array.AppendTimestamp(timestamp);
59 | }
60 |
61 | public static byte[] FromSize(Size data, DateTimeOffset? timestamp = null)
62 | {
63 | byte[] width = BitConverter.GetBytes((float)data.Width);
64 | byte[] height = BitConverter.GetBytes((float)data.Height);
65 |
66 | byte[] array = new byte[8];
67 | Array.Copy(width, 0, array, 0, width.Length);
68 | Array.Copy(height, 0, array, width.Length, height.Length);
69 |
70 | return array.AppendTimestamp(timestamp);
71 | }
72 |
73 | public static byte[] FromRect(Rect data, DateTimeOffset? timestamp = null)
74 | {
75 | byte[] x = BitConverter.GetBytes((float)data.X);
76 | byte[] y = BitConverter.GetBytes((float)data.Y);
77 | byte[] width = BitConverter.GetBytes((float)data.Width);
78 | byte[] height = BitConverter.GetBytes((float)data.Height);
79 |
80 | byte[] array = new byte[16];
81 | Array.Copy(x, 0, array, 0, x.Length);
82 | Array.Copy(y, 0, array, 4, y.Length);
83 | Array.Copy(width, 0, array, 8, width.Length);
84 | Array.Copy(height, 0, array, 12, height.Length);
85 |
86 | return array.AppendTimestamp(timestamp);
87 | }
88 |
89 | public static byte[] FromStringArray(string[] data, DateTimeOffset? timestamp = null)
90 | {
91 | var totalLength = 0;
92 | for (int i = 0; i < data.Length; i++)
93 | totalLength += (data[i].Length * 2) + 2;
94 |
95 | byte[] nullTerminator = new byte[] { 0x0, 0x0 };
96 | byte[] array = new byte[totalLength];
97 |
98 | var curLengthPosition = 0;
99 |
100 | for (int i = 0; i < data.Length; i++)
101 | {
102 | byte[] coded = Encoding.Unicode.GetBytes(data[i]);
103 | Array.Copy(coded, 0, array, curLengthPosition, coded.Length);
104 | curLengthPosition += coded.Length;
105 | Array.Copy(nullTerminator, 0, array, curLengthPosition, 2);
106 | curLengthPosition += 2;
107 | }
108 |
109 | FromArray(new float[0], 2, uwu => { return new byte[0]; }, null);
110 |
111 | return array.AppendTimestamp(timestamp);
112 | }
113 |
114 | public static byte[] FromArray(T[] data, int sizeOfPrimitiveType, Func arr, DateTimeOffset? timestamp = null)
115 | {
116 | byte[] array = new byte[data.Length * sizeOfPrimitiveType];
117 |
118 | for (int i = 0; i < data.Length; i++)
119 | {
120 | var res = arr(data[i]);
121 | Array.Copy(res, 0, array, sizeOfPrimitiveType * i, sizeOfPrimitiveType);
122 | }
123 |
124 | return array.AppendTimestamp(timestamp);
125 | }
126 |
127 | private static byte[] FromDateTimeOffset(DateTimeOffset data)
128 | => BitConverter.GetBytes(data.ToFileTime());
129 |
130 | private static byte[] AppendTimestamp(this byte[] data, DateTimeOffset? timestamp)
131 | {
132 | //No timestamp? don't continue
133 | if (!timestamp.HasValue)
134 | return data;
135 |
136 | byte[] timestampSerialized = FromDateTimeOffset(timestamp.Value);
137 |
138 | byte[] prependedArray = new byte[data.Length + timestampSerialized.Length];
139 | Array.Copy(data, 0, prependedArray, 0, data.Length);
140 | Array.Copy(timestampSerialized, 0, prependedArray, data.Length, timestampSerialized.Length);
141 |
142 | return prependedArray;
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Windows/CreateValueWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 | using UWPSettingsEditor.Controls;
5 | using UWPSettingsEditor.Interfaces;
6 | using System.Windows.Interop;
7 | using static UWPSettingsEditor.NativeMethods;
8 | using System;
9 | using System.Runtime.InteropServices;
10 |
11 | namespace UWPSettingsEditor.Windows
12 | {
13 | ///
14 | /// Interaction logic for CreateValueWindow.xaml
15 | ///
16 | public partial class CreateValueWindow : Window
17 | {
18 | IValueDataSet valueDataSet;
19 | readonly string _path;
20 |
21 | List registryValueTypes = new List()
22 | {
23 | DataTypeEnum.RegUwpBoolean,
24 | DataTypeEnum.RegUwpByte,
25 | DataTypeEnum.RegUwpChar,
26 | DataTypeEnum.RegUwpDateTimeOffset,
27 | DataTypeEnum.RegUwpDouble,
28 | DataTypeEnum.RegUwpGuid,
29 | DataTypeEnum.RegUwpInt16,
30 | DataTypeEnum.RegUwpInt32,
31 | DataTypeEnum.RegUwpInt64,
32 | DataTypeEnum.RegUwpPoint,
33 | DataTypeEnum.RegUwpRect,
34 | DataTypeEnum.RegUwpSingle,
35 | DataTypeEnum.RegUwpSize,
36 | DataTypeEnum.RegUwpString,
37 | DataTypeEnum.RegUwpUint16,
38 | DataTypeEnum.RegUwpUint32,
39 | DataTypeEnum.RegUwpUint64
40 | };
41 |
42 | public CreateValueWindow(string path)
43 | {
44 | _path = path;
45 | InitializeComponent();
46 | ValueTypeComboBox.ItemsSource = registryValueTypes;
47 | ValueTypeComboBox.SelectedIndex = 0;
48 | }
49 |
50 | private void ValueTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
51 | {
52 | var hndl = new WindowInteropHelper(this).EnsureHandle();
53 | IntPtr brush = CreateSolidBrush(uint.MinValue);
54 | SetClassLong(hndl, -10, brush);
55 |
56 | SetWindowTheme(hndl, "DarkMode_Explorer", IntPtr.Zero);
57 |
58 | int attrValue = 1; //TRUE
59 | DwmSetWindowAttribute(hndl, 20, ref attrValue, Marshal.SizeOf(typeof(int)));
60 |
61 | //DARK THEME ^
62 |
63 | var val = (DataTypeEnum)ValueTypeComboBox.SelectedItem;
64 |
65 | if (valueDataSet != null)
66 | {
67 | valueDataSet.PropertyChanged -= ValueDataSet_PropertyChanged;
68 | valueDataSet = null;
69 | ContainerGrid.Children.Clear();
70 |
71 | //TODO: additional check when "if key !exists" is implemented
72 | OkButton.IsEnabled = true;
73 | }
74 |
75 | if (val == DataTypeEnum.RegUwpString)
76 | {
77 | var componentControl = new StringComponent();
78 | ContainerGrid.Children.Add(componentControl);
79 | valueDataSet = componentControl;
80 | SetMinHeightAndHeight(250);
81 | ResizeMode = ResizeMode.CanResizeWithGrip;
82 | }
83 | else if (val == DataTypeEnum.RegUwpBoolean)
84 | {
85 | var componentControl = new BooleanComponent();
86 | ContainerGrid.Children.Add(componentControl);
87 | valueDataSet = componentControl;
88 | SetMinHeightAndHeight(210);
89 | ResizeMode = ResizeMode.NoResize;
90 | }
91 | else if ((int)val >= (int)DataTypeEnum.RegUwpByte &&
92 | (int)val <= (int)DataTypeEnum.RegUwpDouble) //byte, int16, uint16, int32, uint32, int64, uint64, double, single
93 | {
94 | var componentControl = new IntComponent(val);
95 | ContainerGrid.Children.Add(componentControl);
96 | valueDataSet = componentControl;
97 | SetMinHeightAndHeight(210);
98 | ResizeMode = ResizeMode.NoResize;
99 | }
100 | else if (val == DataTypeEnum.RegUwpDateTimeOffset)
101 | {
102 | var componentControl = new DateTimeOffsetComponent();
103 | ContainerGrid.Children.Add(componentControl);
104 | valueDataSet = componentControl;
105 | SetMinHeightAndHeight(210);
106 | ResizeMode = ResizeMode.NoResize;
107 | }
108 | else if (val == DataTypeEnum.RegUwpChar)
109 | {
110 | var componentControl = new CharComponent();
111 | ContainerGrid.Children.Add(componentControl);
112 | valueDataSet = componentControl;
113 | SetMinHeightAndHeight(210);
114 | ResizeMode = ResizeMode.NoResize;
115 | }
116 | else if (val == DataTypeEnum.RegUwpGuid)
117 | {
118 | var componentControl = new GuidComponent();
119 | ContainerGrid.Children.Add(componentControl);
120 | valueDataSet = componentControl;
121 | SetMinHeightAndHeight(210);
122 | ResizeMode = ResizeMode.NoResize;
123 | }
124 | else if (val == DataTypeEnum.RegUwpRect)
125 | {
126 | var componentControl = new RectComponent();
127 | ContainerGrid.Children.Add(componentControl);
128 | valueDataSet = componentControl;
129 | SetMinHeightAndHeight(210);
130 | ResizeMode = ResizeMode.NoResize;
131 | }
132 | else if (val == DataTypeEnum.RegUwpPoint || val == DataTypeEnum.RegUwpSize)
133 | {
134 | var componentControl = new PointSizeComponent(val);
135 | ContainerGrid.Children.Add(componentControl);
136 | valueDataSet = componentControl;
137 | SetMinHeightAndHeight(210);
138 | ResizeMode = ResizeMode.NoResize;
139 | }
140 |
141 | valueDataSet.PropertyChanged += ValueDataSet_PropertyChanged;
142 | }
143 |
144 | public DataTypeEnum GetValueType() => (DataTypeEnum)ValueTypeComboBox.SelectedItem;
145 | public byte[] GetValueData() => valueDataSet?.GetValueData();
146 | public string GetValueName() => ValueNameTextBox.Text;
147 |
148 | private void ValueDataSet_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
149 | {
150 | //throw new NotImplementedException();
151 | if (e.PropertyName == "IsDataValid")
152 | {
153 | OkButton.IsEnabled = valueDataSet.IsDataValid;
154 | }
155 | }
156 |
157 | private void SetMinHeightAndHeight(double targetHeight)
158 | {
159 | MinHeight = targetHeight;
160 | Height = targetHeight;
161 | }
162 |
163 | private void OkButton_Click(object sender, RoutedEventArgs e)
164 | {
165 | //TODO: check if the value name isn't actually used
166 | DialogResult = true;
167 | }
168 |
169 | private void CancelButton_Click(object sender, RoutedEventArgs e)
170 | {
171 | DialogResult = false;
172 | }
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Controls/IntComponent.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Windows.Controls;
4 | using System.Windows.Media;
5 | using System.Windows.Navigation;
6 | using UWPSettingsEditor.Interfaces;
7 | using static UWPSettingsEditor.UWPDeserializer;
8 | using static UWPSettingsEditor.UWPSerializer;
9 |
10 | namespace UWPSettingsEditor.Controls
11 | {
12 | ///
13 | /// Interaction logic for IntComponent.xaml
14 | ///
15 | public partial class IntComponent : UserControl, IValueDataSet
16 | {
17 | readonly SolidColorBrush valid = new SolidColorBrush(Color.FromRgb(0xFF, 0xFF, 0xFF));
18 | readonly SolidColorBrush invalid = new SolidColorBrush(Color.FromRgb(0xFF, 0x00, 0x00));
19 |
20 | private DateTimeOffset _timestamp;
21 | private DataTypeEnum _dataType;
22 |
23 | private bool _isDataValid;
24 | public bool IsDataValid => _isDataValid;
25 |
26 | public IntComponent(DataTypeEnum dataType)
27 | {
28 | _dataType = dataType;
29 | InitializeComponent();
30 | _timestamp = DateTimeOffset.Now;
31 |
32 | txBox.Text = "0";
33 | txBox.TextChanged += TxBox_TextChanged;
34 | }
35 |
36 | public event PropertyChangedEventHandler PropertyChanged;
37 |
38 | public byte[] GetValueData()
39 | {
40 | switch (_dataType)
41 | {
42 | case DataTypeEnum.RegUwpByte:
43 | return FromByte(byte.Parse(txBox.Text), _timestamp);
44 | case DataTypeEnum.RegUwpInt16:
45 | return FromInt16(short.Parse(txBox.Text), _timestamp);
46 | case DataTypeEnum.RegUwpUint16:
47 | return FromUInt16(ushort.Parse(txBox.Text), _timestamp);
48 | case DataTypeEnum.RegUwpInt32:
49 | return FromInt32(int.Parse(txBox.Text), _timestamp);
50 | case DataTypeEnum.RegUwpUint32:
51 | return FromUInt32(uint.Parse(txBox.Text), _timestamp);
52 | case DataTypeEnum.RegUwpInt64:
53 | return FromInt64(long.Parse(txBox.Text), _timestamp);
54 | case DataTypeEnum.RegUwpUint64:
55 | return FromUInt64(ulong.Parse(txBox.Text), _timestamp);
56 | case DataTypeEnum.RegUwpSingle:
57 | return FromSingle(float.Parse(txBox.Text), _timestamp);
58 | case DataTypeEnum.RegUwpDouble:
59 | return FromDouble(double.Parse(txBox.Text), _timestamp);
60 | default:
61 | return null;
62 | }
63 | }
64 |
65 | public void SetValueData(byte[] dataRaw)
66 | {
67 | var tmp = MethodHelpers.SplitDataRaw(dataRaw);
68 |
69 | _timestamp = GetDateTimeOffset(tmp.Key);
70 |
71 | switch (_dataType)
72 | {
73 | case DataTypeEnum.RegUwpByte:
74 | txBox.Text = GetByte(tmp.Value).ToString();
75 | break;
76 | case DataTypeEnum.RegUwpInt16:
77 | txBox.Text = GetInt16(tmp.Value).ToString();
78 | break;
79 | case DataTypeEnum.RegUwpUint16:
80 | txBox.Text = GetUInt16(tmp.Value).ToString();
81 | break;
82 | case DataTypeEnum.RegUwpInt32:
83 | txBox.Text = GetInt32(tmp.Value).ToString();
84 | break;
85 | case DataTypeEnum.RegUwpUint32:
86 | txBox.Text = GetUInt32(tmp.Value).ToString();
87 | break;
88 | case DataTypeEnum.RegUwpInt64:
89 | txBox.Text = GetInt64(tmp.Value).ToString();
90 | break;
91 | case DataTypeEnum.RegUwpUint64:
92 | txBox.Text = GetUInt64(tmp.Value).ToString();
93 | break;
94 | case DataTypeEnum.RegUwpSingle:
95 | txBox.Text = GetSingle(tmp.Value).ToString("G9");
96 | break;
97 | case DataTypeEnum.RegUwpDouble:
98 | txBox.Text = GetDouble(tmp.Value).ToString("G17");
99 | break;
100 | default:
101 | break;
102 | }
103 | }
104 |
105 | private void FlagDataAsValid()
106 | {
107 | _isDataValid = true;
108 | txBox.Foreground = valid;
109 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
110 | }
111 |
112 | private void FlagDataAsInvalid()
113 | {
114 | _isDataValid = false;
115 | txBox.Foreground = invalid;
116 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDataValid"));
117 | }
118 |
119 | private void TxBox_TextChanged(object sender, TextChangedEventArgs e)
120 | {
121 | switch (_dataType)
122 | {
123 | case DataTypeEnum.RegUwpByte:
124 | if (byte.TryParse(txBox.Text, out _))
125 | FlagDataAsValid();
126 | else
127 | FlagDataAsInvalid();
128 | break;
129 | case DataTypeEnum.RegUwpInt16:
130 | if (Int16.TryParse(txBox.Text, out _))
131 | FlagDataAsValid();
132 | else
133 | FlagDataAsInvalid();
134 | break;
135 | case DataTypeEnum.RegUwpUint16:
136 | if (UInt16.TryParse(txBox.Text, out _))
137 | FlagDataAsValid();
138 | else
139 | FlagDataAsInvalid();
140 | break;
141 | case DataTypeEnum.RegUwpInt32:
142 | if (Int32.TryParse(txBox.Text, out _))
143 | FlagDataAsValid();
144 | else
145 | FlagDataAsInvalid();
146 | break;
147 | case DataTypeEnum.RegUwpUint32:
148 | if (UInt32.TryParse(txBox.Text, out _))
149 | FlagDataAsValid();
150 | else
151 | FlagDataAsInvalid();
152 | break;
153 | case DataTypeEnum.RegUwpInt64:
154 | if (Int64.TryParse(txBox.Text, out _))
155 | FlagDataAsValid();
156 | else
157 | FlagDataAsInvalid();
158 | break;
159 | case DataTypeEnum.RegUwpUint64:
160 | if (UInt64.TryParse(txBox.Text, out _))
161 | FlagDataAsValid();
162 | else
163 | FlagDataAsInvalid();
164 | break;
165 | case DataTypeEnum.RegUwpSingle:
166 | if (Single.TryParse(txBox.Text, out _))
167 | FlagDataAsValid();
168 | else
169 | FlagDataAsInvalid();
170 | break;
171 | case DataTypeEnum.RegUwpDouble:
172 | if (Double.TryParse(txBox.Text, out _))
173 | FlagDataAsValid();
174 | else
175 | FlagDataAsInvalid();
176 | break;
177 | default:
178 | break;
179 | }
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
--------------------------------------------------------------------------------
/src/UWPSettingsEditor/Registry/Util/Numbers.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2008-2011, Kenneth Bell
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a
5 | // copy of this software and associated documentation files (the "Software"),
6 | // to deal in the Software without restriction, including without limitation
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | // and/or sell copies of the Software, and to permit persons to whom the
9 | // Software is furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | // DEALINGS IN THE SOFTWARE.
21 | //
22 |
23 | using System;
24 |
25 | namespace DiscUtils.Streams
26 | {
27 | internal static class Numbers
28 | where T : struct, IComparable, IEquatable
29 | {
30 | public delegate bool ComparisonFn(T a, T b);
31 |
32 | public delegate T ConvertIntFn(int a);
33 |
34 | public delegate T ConvertLongFn(long a);
35 |
36 | public delegate T DualParamFn(T a, T b);
37 |
38 | public delegate T NoParamFn();
39 |
40 | public static readonly T Zero = default(T);
41 | public static readonly T One = GetOne();
42 | public static readonly DualParamFn Add = GetAdd();
43 | public static readonly DualParamFn Subtract = GetSubtract();
44 | public static readonly DualParamFn Multiply = GetMultiply();
45 | public static readonly DualParamFn Divide = GetDivide();
46 | public static readonly DualParamFn RoundUp = GetRoundUp();
47 | public static readonly DualParamFn RoundDown = GetRoundDown();
48 | public static readonly DualParamFn Ceil = GetCeil();
49 | public static readonly ConvertLongFn ConvertLong = GetConvertLong();
50 | public static readonly ConvertIntFn ConvertInt = GetConvertInt();
51 |
52 | public static bool GreaterThan(T a, T b)
53 | {
54 | return a.CompareTo(b) > 0;
55 | }
56 |
57 | public static bool GreaterThanOrEqual(T a, T b)
58 | {
59 | return a.CompareTo(b) >= 0;
60 | }
61 |
62 | public static bool LessThan(T a, T b)
63 | {
64 | return a.CompareTo(b) < 0;
65 | }
66 |
67 | public static bool LessThanOrEqual(T a, T b)
68 | {
69 | return a.CompareTo(b) <= 0;
70 | }
71 |
72 | public static bool Equal(T a, T b)
73 | {
74 | return a.CompareTo(b) == 0;
75 | }
76 |
77 | public static bool NotEqual(T a, T b)
78 | {
79 | return a.CompareTo(b) != 0;
80 | }
81 |
82 | private static T GetOne()
83 | {
84 | if (typeof(T) == typeof(long))
85 | {
86 | return ((NoParamFn)(object)new LongNoParamFn(() => { return 1; }))();
87 | }
88 | if (typeof(T) == typeof(int))
89 | {
90 | return ((NoParamFn)(object)new IntNoParamFn(() => { return 1; }))();
91 | }
92 | throw new NotSupportedException();
93 | }
94 |
95 | private static ConvertLongFn GetConvertLong()
96 | {
97 | if (typeof(T) == typeof(long))
98 | {
99 | return (ConvertLongFn)(object)new LongConvertLongFn(x => { return x; });
100 | }
101 | if (typeof(T) == typeof(int))
102 | {
103 | return (ConvertLongFn)(object)new IntConvertLongFn(x => { return (int)x; });
104 | }
105 | throw new NotSupportedException();
106 | }
107 |
108 | private static ConvertIntFn GetConvertInt()
109 | {
110 | if (typeof(T) == typeof(long))
111 | {
112 | return (ConvertIntFn)(object)new LongConvertIntFn(x => { return x; });
113 | }
114 | if (typeof(T) == typeof(int))
115 | {
116 | return (ConvertIntFn)(object)new IntConvertIntFn(x => { return x; });
117 | }
118 | throw new NotSupportedException();
119 | }
120 |
121 | private static DualParamFn GetAdd()
122 | {
123 | if (typeof(T) == typeof(long))
124 | {
125 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return a + b; });
126 | }
127 | if (typeof(T) == typeof(int))
128 | {
129 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return a + b; });
130 | }
131 | throw new NotSupportedException();
132 | }
133 |
134 | private static DualParamFn GetSubtract()
135 | {
136 | if (typeof(T) == typeof(long))
137 | {
138 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return a - b; });
139 | }
140 | if (typeof(T) == typeof(int))
141 | {
142 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return a - b; });
143 | }
144 | throw new NotSupportedException();
145 | }
146 |
147 | private static DualParamFn GetMultiply()
148 | {
149 | if (typeof(T) == typeof(long))
150 | {
151 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return a * b; });
152 | }
153 | if (typeof(T) == typeof(int))
154 | {
155 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return a * b; });
156 | }
157 | throw new NotSupportedException();
158 | }
159 |
160 | private static DualParamFn GetDivide()
161 | {
162 | if (typeof(T) == typeof(long))
163 | {
164 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return a / b; });
165 | }
166 | if (typeof(T) == typeof(int))
167 | {
168 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return a / b; });
169 | }
170 | throw new NotSupportedException();
171 | }
172 |
173 | private static DualParamFn GetRoundUp()
174 | {
175 | if (typeof(T) == typeof(long))
176 | {
177 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return (a + b - 1) / b * b; });
178 | }
179 | if (typeof(T) == typeof(int))
180 | {
181 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return (a + b - 1) / b * b; });
182 | }
183 | throw new NotSupportedException();
184 | }
185 |
186 | private static DualParamFn GetRoundDown()
187 | {
188 | if (typeof(T) == typeof(long))
189 | {
190 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return a / b * b; });
191 | }
192 | if (typeof(T) == typeof(int))
193 | {
194 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return a / b * b; });
195 | }
196 | throw new NotSupportedException();
197 | }
198 |
199 | private static DualParamFn GetCeil()
200 | {
201 | if (typeof(T) == typeof(long))
202 | {
203 | return (DualParamFn)(object)new LongDualParamFn((a, b) => { return (a + b - 1) / b; });
204 | }
205 | if (typeof(T) == typeof(int))
206 | {
207 | return (DualParamFn)(object)new IntDualParamFn((a, b) => { return (a + b - 1) / b; });
208 | }
209 | throw new NotSupportedException();
210 | }
211 |
212 | private delegate long LongNoParamFn();
213 |
214 | private delegate long LongDualParamFn(long a, long b);
215 |
216 | private delegate long LongConvertLongFn(long x);
217 |
218 | private delegate long LongConvertIntFn(int x);
219 |
220 | private delegate int IntNoParamFn();
221 |
222 | private delegate int IntDualParamFn(int a, int b);
223 |
224 | private delegate int IntConvertLongFn(long x);
225 |
226 | private delegate int IntConvertIntFn(int x);
227 | }
228 | }
--------------------------------------------------------------------------------