Skip to content

Commit

Permalink
flag grouping and Debugger image value
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed Apr 3, 2017
1 parent d6c1efd commit c629072
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 44 deletions.
27 changes: 27 additions & 0 deletions GflagsX/Converters/CategoryToStringConverter.cs
@@ -0,0 +1,27 @@
using GflagsX.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace GflagsX.Converters {
class CategoryToStringConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
switch((string)value) {
case "KernelModeOnly":
return "Kernel Mode";
case "UserModeOnly":
return "User Mode";
default:
return "General";
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions GflagsX/GflagsX.csproj
Expand Up @@ -78,6 +78,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Constants.cs" />
<Compile Include="Converters\CategoryToStringConverter.cs" />
<Compile Include="Models\GlobalFlag.cs" />
<Compile Include="Models\GlobalFlags.cs" />
<Compile Include="NativeMethods.cs" />
Expand Down
2 changes: 1 addition & 1 deletion GflagsX/Models/GlobalFlag.cs
Expand Up @@ -15,7 +15,7 @@ enum GlobalFlagUsage {

enum GlobalFlagCategory {
None,
KernelOnly,
KernelModeOnly,
UserModeOnly,
UserModeAndKernelMode
}
Expand Down
46 changes: 23 additions & 23 deletions GflagsX/Models/GlobalFlags.cs
Expand Up @@ -11,29 +11,29 @@ static class GlobalFlags {
new GlobalFlag("Show Loader Snaps", 2, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Debug Initial Command", 4, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Stop on Hung GUI", 8, GlobalFlagUsage.Kernel) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Heap Tail Checking", 0x10, GlobalFlagUsage.All),
new GlobalFlag("Enable Heap Free Checking", 0x20, GlobalFlagUsage.All),
new GlobalFlag("Enable Heap Parameter Checking", 0x40, GlobalFlagUsage.All),
new GlobalFlag("Enable Heap Validation on Call", 0x80, GlobalFlagUsage.All),
new GlobalFlag("Enable Application Verifier", 0x100, GlobalFlagUsage.All),
new GlobalFlag("Enable Pool Tagging", 0x400, GlobalFlagUsage.Registry),
new GlobalFlag("Enable Heap Tagging", 0x800, GlobalFlagUsage.All),
new GlobalFlag("Create User Mode Stack Trace Database", 0x1000, GlobalFlagUsage.All),
new GlobalFlag("Create Kernel Mode Stack Trace Database", 0x2000, GlobalFlagUsage.Registry),
new GlobalFlag("Maintain a List of Objects for Each Type", 0x4000, GlobalFlagUsage.Registry),
new GlobalFlag("Enable Heap Tagging by DLL", 0x8000, GlobalFlagUsage.All),
new GlobalFlag("Enable Debugging of the Windows Subsystem", 0x20000, GlobalFlagUsage.Registry),
new GlobalFlag("Disable Paging of Kernel Stacks", 0x80000, GlobalFlagUsage.Registry),
new GlobalFlag("Enable System Critical Breaks", 0x100000, GlobalFlagUsage.All),
new GlobalFlag("Disable Heap Coalesce on Free", 0x200000, GlobalFlagUsage.All),
new GlobalFlag("Enable Object Handle Type Tagging", 0x01000000, GlobalFlagUsage.Kernel | GlobalFlagUsage.Registry),
new GlobalFlag("Enable Page Heap", 0x02000000, GlobalFlagUsage.All),
new GlobalFlag("Debug WinLogon", 0x04000000, GlobalFlagUsage.Registry),
new GlobalFlag("Buffer DbgPrint Output", 0x08000000, GlobalFlagUsage.Registry | GlobalFlagUsage.Kernel),
new GlobalFlag("Early Critical Section Event Creation", 0x10000000, GlobalFlagUsage.All),
new GlobalFlag("Stop on Unhandled User Mode Exception", 0x20000000, GlobalFlagUsage.All),
new GlobalFlag("Enable Bad Handles Detection", 0x40000000, GlobalFlagUsage.Kernel | GlobalFlagUsage.Registry),
new GlobalFlag("Disable Protected DLL Verification", 0x80000000, GlobalFlagUsage.All)
new GlobalFlag("Enable Heap Tail Checking", 0x10, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Heap Free Checking", 0x20, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Heap Parameter Checking", 0x40, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Heap Validation on Call", 0x80, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Application Verifier", 0x100, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Pool Tagging", 0x400, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.KernelModeOnly },
new GlobalFlag("Enable Heap Tagging", 0x800, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Create User Mode Stack Trace Database", 0x1000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Create Kernel Mode Stack Trace Database", 0x2000, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.KernelModeOnly },
new GlobalFlag("Maintain a List of Objects for Each Type", 0x4000, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.UserModeAndKernelMode },
new GlobalFlag("Enable Heap Tagging by DLL", 0x8000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Debugging of the Windows Subsystem", 0x20000, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.UserModeAndKernelMode },
new GlobalFlag("Disable Paging of Kernel Stacks", 0x80000, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.KernelModeOnly },
new GlobalFlag("Enable System Critical Breaks", 0x100000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeAndKernelMode },
new GlobalFlag("Disable Heap Coalesce on Free", 0x200000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Object Handle Type Tagging", 0x01000000, GlobalFlagUsage.Kernel | GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.UserModeAndKernelMode },
new GlobalFlag("Enable Page Heap", 0x02000000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Debug WinLogon", 0x04000000, GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.UserModeAndKernelMode },
new GlobalFlag("Buffer DbgPrint Output", 0x08000000, GlobalFlagUsage.Registry | GlobalFlagUsage.Kernel) { Category = GlobalFlagCategory.KernelModeOnly },
new GlobalFlag("Early Critical Section Event Creation", 0x10000000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Stop on Unhandled User Mode Exception", 0x20000000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly },
new GlobalFlag("Enable Bad Handles Detection", 0x40000000, GlobalFlagUsage.Kernel | GlobalFlagUsage.Registry) { Category = GlobalFlagCategory.UserModeAndKernelMode },
new GlobalFlag("Disable Protected DLL Verification", 0x80000000, GlobalFlagUsage.All) { Category = GlobalFlagCategory.UserModeOnly }
};

public static IReadOnlyList<GlobalFlag> Flags => _flags;
Expand Down
6 changes: 3 additions & 3 deletions GflagsX/Resources/Templates.xaml
Expand Up @@ -3,12 +3,12 @@
xmlns:vm="clr-namespace:GflagsX.ViewModels"
xmlns:view="clr-namespace:GflagsX.Views">
<DataTemplate DataType="{x:Type vm:RegistryTabViewModel}">
<view:RegistryTabView />
<view:RegistryTabView Margin="4"/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:KernelTabViewModel}">
<view:KernelTabView />
<view:KernelTabView Margin="4"/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ImageTabViewModel}">
<view:ImageTabView />
<view:ImageTabView Margin="4" />
</DataTemplate>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions GflagsX/ViewModels/GlobalFlagViewModel.cs
Expand Up @@ -27,6 +27,8 @@ class GlobalFlagViewModel : BindableBase {
}
}

public string Category => Flag.Category.ToString();

public bool IsVisible { get; }
public string Name => Flag.Name;
}
Expand Down
11 changes: 6 additions & 5 deletions GflagsX/ViewModels/GlobalFlagsTabViewModelBase.cs
Expand Up @@ -7,6 +7,8 @@
using GflagsX.Models;
using Prism.Commands;
using Prism.Mvvm;
using System.Windows.Data;
using GflagsX.Converters;

namespace GflagsX.ViewModels {
abstract class GlobalFlagsTabViewModelBase : BindableBase {
Expand All @@ -19,9 +21,10 @@ abstract class GlobalFlagsTabViewModelBase : BindableBase {
public IEnumerable<GlobalFlagViewModel> Flags => _flags;

protected GlobalFlagsTabViewModelBase(GlobalFlagUsage usage) {
_flags = GlobalFlags.Flags.Select(flag => new GlobalFlagViewModel(this, flag, usage)).ToList();
//_flags1 = _flags.Take(_flags.Count / 2).ToArray();
//_flags2 = _flags.Skip(_flags.Count / 2).Take(_flags.Count / 2).ToArray();
_flags = GlobalFlags.Flags.Where(flag => (flag.Usage & usage) == usage)
.Select(flag => new GlobalFlagViewModel(this, flag, usage)).ToList();
CollectionViewSource.GetDefaultView(Flags).GroupDescriptions.Add(
new PropertyGroupDescription("Category"));
CalculateFlags();
}

Expand All @@ -37,8 +40,6 @@ abstract class GlobalFlagsTabViewModelBase : BindableBase {

public ICommand ApplyCommand => new DelegateCommand(() => Apply());

//protected abstract void LoadFlags();

public ICommand ReloadFlagsCommand => new DelegateCommand(() => CalculateFlags());
}
}
33 changes: 31 additions & 2 deletions GflagsX/ViewModels/ImageTabViewModel.cs
Expand Up @@ -35,6 +35,7 @@ class ImageTabViewModel : GlobalFlagsTabViewModelBase {
if(SetProperty(ref _selectedImage, value)) {
CalculateFlags();
OnPropertyChanged(nameof(Flags));
ReloadSettings();
}
}
}
Expand Down Expand Up @@ -63,8 +64,8 @@ class ImageTabViewModel : GlobalFlagsTabViewModelBase {
}

public ICommand NewImageCommand => new DelegateCommand(() => {
var vm = App.MainViewModel.UI.DialogService.CreateDialog<NewImageViewModel, NewImageView>();
if(vm.ShowDialog() == true) {
var vm = App.MainViewModel.UI.DialogService.CreateDialog<NewImageViewModel, NewImageView>();
if(vm.ShowDialog() == true) {
if(Images.Contains(vm.ImageName, StringComparer.InvariantCultureIgnoreCase)) {
App.MainViewModel.UI.MessageBoxService.ShowMessage("Image name already exists.", Constants.AppName);
}
Expand Down Expand Up @@ -102,5 +103,33 @@ class ImageTabViewModel : GlobalFlagsTabViewModelBase {
OnPropertyChanged(nameof(Images));
}
}

private string _debuggerName;

public string DebuggerName {
get { return _debuggerName; }
set { SetProperty(ref _debuggerName, value); }
}

public ICommand ApplySettingsCommand => new DelegateCommand(() => ApplySettings(), () => SelectedImage != null)
.ObservesProperty(() => SelectedImage);

private void ApplySettings() {
using(var key = Registry.LocalMachine.OpenSubKey(IFEOKey + "\\" + SelectedImage, true)) {
if(string.IsNullOrWhiteSpace(DebuggerName))
key.DeleteValue("Debugger");
else
key.SetValue("Debugger", DebuggerName);
}
}

public ICommand ReloadSettingsCommand => new DelegateCommand(() => ReloadSettings(), () => SelectedImage != null)
.ObservesProperty(() => SelectedImage);

private void ReloadSettings() {
using(var key = Registry.LocalMachine.OpenSubKey(IFEOKey + "\\" + SelectedImage)) {
DebuggerName = (key.GetValue("Debugger") as string) ?? string.Empty;
}
}
}
}
7 changes: 1 addition & 6 deletions GflagsX/ViewModels/NewImageViewModel.cs
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
using Zodiacon.WPF;

namespace GflagsX.ViewModels {
Expand Down
21 changes: 19 additions & 2 deletions GflagsX/Views/GflagsView.xaml
Expand Up @@ -4,22 +4,39 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GflagsX.Views"
xmlns:conv="clr-namespace:GflagsX.Converters"
mc:Ignorable="d"
xmlns:z="http://zodiacon.wpf/2016"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.Resources>
<z:BooleanToVisibilityConverter InvisibleAsHidden="True" x:Key="bool2vis" />
<z:BooleanToVisibilityConverter InvisibleAsHidden="False" x:Key="bool2vis" />
<DataTemplate x:Key="flagTemplate">
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsEnabled}" Margin="0,4" Visibility="{Binding IsVisible, Converter={StaticResource bool2vis}}"/>
</DataTemplate>
<conv:CategoryToStringConverter x:Key="cat2string" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ItemsControl Grid.Row="1" ItemsSource="{Binding Flags}" ItemTemplate="{StaticResource flagTemplate}" />
<ScrollViewer VerticalScrollBarVisibility="Auto">

<ItemsControl Grid.Row="1" ItemsSource="{Binding Flags}" ItemTemplate="{StaticResource flagTemplate}">
<ItemsControl.GroupStyle>
<GroupStyle HidesIfEmpty="True">
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontSize="14" Margin="4" HorizontalAlignment="Left">
<Bold><Underline><Run Text="{Binding Items[0].Category, Mode=OneWay,Converter={StaticResource cat2string}}" /></Underline></Bold>
</TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ItemsControl.GroupStyle>
</ItemsControl>
</ScrollViewer>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Width="140" Text="{Binding FlagsValue, StringFormat=Flags Value: 0x\{0:X\}}" VerticalAlignment="Center" />
<Button Margin="12,12" Command="{Binding ApplyCommand}" HorizontalAlignment="Left" >
Expand Down
9 changes: 7 additions & 2 deletions GflagsX/Views/ImageTabView.xaml
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:local="clr-namespace:GflagsX.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
Expand Down Expand Up @@ -47,12 +48,16 @@
</Button>
</StackPanel>
<local:GflagsView Grid.Row="2" />
<GroupBox Header="More Settings" Grid.Row="2" Grid.Column="2">
<GroupBox Header="More Settings" Grid.Row="2" Grid.Column="2" VerticalAlignment="Top">
<StackPanel>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="Debugger:" VerticalAlignment="Center" />
<TextBox Text="{Binding DebuggerName}" Margin="4,0,0,0" Width="200" />
<TextBox Text="{Binding DebuggerName}" Margin="4,0,0,0" Width="220" metro:TextBoxHelper.ClearTextButton="True" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="4,12">
<Button Command="{Binding ApplySettingsCommand}" Content="Apply Settings" metro:ButtonHelper.PreserveTextCase="True" />
<Button Margin="16,0,0,0" Content="Reload Settings" Command="{Binding ReloadSettingsCommand}" metro:ButtonHelper.PreserveTextCase="True"/>
</StackPanel>
</StackPanel>
</GroupBox>
</Grid>
Expand Down

0 comments on commit c629072

Please sign in to comment.