Skip to content

Commit 5f4c4a3

Browse files
authored
Harden System Security v1.0.45.0 (#1063)
# What's New * Added a new feature: The **Service Manager**, a feature integrated into the Harden System Security app, is designed to give you comprehensive visibility and granular control over all Windows services. It goes far beyond the capabilities of the native Windows Services utility or 3rd-party tools, offering deep insights, robust filtering, precise metadata extraction, and direct manipulation of service configurations and underlying executable files. It is capable of display all services with any type, something that's not possible through the OS's Service console, Powershell or System Configuration. You can easily see which services are from Microsoft and which ones are 3rd party. Please read more on this GitHub Wiki page: https://github.com/HotCakeX/Harden-Windows-Security/wiki/Service-Manager * Added a new feature to the Sidebar that allows you to generate a Battery Report for your device (if it has one). It contains detailed information about your battery usage, wattage and performance. * When using the CLI mode to export the system report to a file, if you selected a location that doesn't exist, the app now creates the necessary directories and saves the report there instead of showing an error. * Fixed an error in the CLI mode when applying a preset: #1062
1 parent 38e75f0 commit 5f4c4a3

46 files changed

Lines changed: 7913 additions & 128 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AppControl Manager/MainWindow.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ internal void RefreshLocalizedContent()
697697
AutomationProperties.SetHelpText(EXIFManagerNavigationViewItem, GlobalVars.GetStr("EXIFManagerNavigationViewItem/AutomationProperties/HelpText"));
698698
ToolTipService.SetToolTip(EXIFManagerNavigationViewItem, GlobalVars.GetStr("EXIFManagerNavigationViewItem/ToolTipService/ToolTip"));
699699

700+
ServiceManagerNavItem.Content = GlobalVars.GetStr("ServiceManagerNavItem/Content");
701+
AutomationProperties.SetHelpText(ServiceManagerNavItem, GlobalVars.GetStr("ServiceManagerNavItem/AutomationProperties/HelpText"));
702+
ToolTipService.SetToolTip(ServiceManagerNavItem, GlobalVars.GetStr("ServiceManagerNavItem/ToolTipService/ToolTip"));
703+
700704
#endif
701705

702706
#if APP_CONTROL_MANAGER

AppControl Manager/Others/GetExtendedFileAttrib.cs

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ internal static partial class GetExtendedFileAttrib
3838
/// operations.
3939
/// https://learn.microsoft.com/windows/win32/api/winver/nf-winver-getfileversioninfoexw#parameters
4040
/// </summary>
41-
private const int FILE_VER_GET_NEUTRAL = 2;
42-
43-
/// <summary>
44-
/// Represents an error code indicating that a specified resource type could not be found. The value is 1813 (-2147023083).
45-
/// </summary>
46-
private const int ERROR_RESOURCE_TYPE_NOT_FOUND = 1813;
41+
private const uint FILE_VER_GET_NEUTRAL = 2;
4742

4843
/// <summary>
4944
/// Retrieves extended file information, including version, original file name, internal name, file description, and
@@ -77,16 +72,15 @@ internal static ExFileInfo Get(string filePath)
7772
Span<byte> spanData = new(versionData);
7873

7974
// Extract version from the version data
80-
if (!TryGetVersion(spanData, out Version? version, out int versionErrorCode))
75+
if (!TryGetVersion(spanData, out Version? version))
8176
{
82-
// Throw Win32Exception using captured error code
83-
throw new Win32Exception(versionErrorCode);
77+
return BadCaseReturnVal;
8478
}
8579

8680
// Extract locale and encoding information
87-
if (!TryGetLocaleAndEncoding(spanData, out string? locale, out string? encoding, out int localeErrorCode))
81+
if (!TryGetLocaleAndEncoding(spanData, out string? locale, out string? encoding))
8882
{
89-
throw new Win32Exception(localeErrorCode);
83+
return BadCaseReturnVal;
9084
}
9185

9286
// Retrieve various file information based on locale and encoding and return the result
@@ -112,29 +106,24 @@ internal static ExFileInfo Get(string filePath)
112106
}
113107
}
114108

115-
116109
/// <summary>
117110
/// Extracts version information from a byte array and outputs it as a Version object.
118111
/// </summary>
119112
/// <param name="data">The byte array containing version information to be extracted.</param>
120113
/// <param name="version">Outputs the extracted version information as a Version object.</param>
121-
/// <param name="win32Error">Outputs the Win32 error code when extraction fails.</param>
122114
/// <returns>Returns true if the version was successfully extracted, otherwise false.</returns>
123-
private static unsafe bool TryGetVersion(Span<byte> data, out Version? version, out int win32Error)
115+
private static unsafe bool TryGetVersion(Span<byte> data, out Version? version)
124116
{
125117
version = null;
126-
win32Error = 0;
127118

128119
// pin span directly
129120
fixed (byte* pData = data)
130121
{
131122
IntPtr basePtr = (IntPtr)pData;
132123

133-
// Query the root block for version info
134-
if (!NativeMethods.VerQueryValueW(basePtr, "\\", out nint buffer, out _))
124+
// Query the root block for version info and make sure the returned length is large enough for the struct
125+
if (NativeMethods.VerQueryValueW(basePtr, "\\", out nint buffer, out uint len) == 0 || buffer == IntPtr.Zero || len < sizeof(VS_FIXEDFILEINFO))
135126
{
136-
// Capture Win32 error immediately after failure.
137-
win32Error = Marshal.GetLastPInvokeError();
138127
return false;
139128
}
140129

@@ -152,40 +141,35 @@ private static unsafe bool TryGetVersion(Span<byte> data, out Version? version,
152141
}
153142
}
154143

155-
156144
/// <summary>
157145
/// Extracts locale and encoding information from a byte span.
158146
/// </summary>
159147
/// <param name="data">The byte span containing data from which locale and encoding are extracted.</param>
160148
/// <param name="locale">Outputs the locale information derived from the data.</param>
161149
/// <param name="encoding">Outputs the encoding information derived from the data.</param>
162-
/// <param name="win32Error">Outputs the Win32 error code when extraction fails.</param>
163150
/// <returns>Returns a boolean indicating the success of the extraction process.</returns>
164-
private static unsafe bool TryGetLocaleAndEncoding(Span<byte> data, out string? locale, out string? encoding, out int win32Error)
151+
private static unsafe bool TryGetLocaleAndEncoding(Span<byte> data, out string? locale, out string? encoding)
165152
{
166153
locale = null;
167154
encoding = null;
168-
win32Error = 0;
169155

170156
// pin span instead of allocating a new array each call.
171157
fixed (byte* pData = data)
172158
{
173159
IntPtr basePtr = (IntPtr)pData;
174160

175-
// Query the translation block for locale and encoding
176-
if (!NativeMethods.VerQueryValueW(basePtr, "\\VarFileInfo\\Translation", out nint buffer, out _))
161+
// Query the translation block for locale and encoding, verifying length is at least 4 bytes (2 WORDs)
162+
if (NativeMethods.VerQueryValueW(basePtr, "\\VarFileInfo\\Translation", out nint buffer, out uint len) == 0 || buffer == IntPtr.Zero || len < 4)
177163
{
178-
win32Error = Marshal.GetLastPInvokeError();
179164
return false;
180165
}
181166

182-
// Copy the translation values (two WORDs)
183-
short[] translations = new short[2];
184-
Marshal.Copy(buffer, translations, 0, 2);
167+
// Cast directly to ushort* (WORD)
168+
ushort* pTranslations = (ushort*)buffer;
185169

186170
// Convert the translation values to hex strings
187-
locale = translations[0].ToString("X4", CultureInfo.InvariantCulture);
188-
encoding = translations[1].ToString("X4", CultureInfo.InvariantCulture);
171+
locale = pTranslations[0].ToString("X4", CultureInfo.InvariantCulture);
172+
encoding = pTranslations[1].ToString("X4", CultureInfo.InvariantCulture);
189173
return true;
190174
}
191175
}
@@ -200,7 +184,7 @@ private static unsafe bool TryGetLocaleAndEncoding(Span<byte> data, out string?
200184
/// <returns>Returns the localized resource string or null if not found.</returns>
201185
private static unsafe string? GetLocalizedResource(Span<byte> versionBlock, string encoding, string locale, string resource)
202186
{
203-
string[] encodings = [encoding, Cp1252FallbackCode, UnicodeFallbackCode];
187+
ReadOnlySpan<string> encodings = [encoding, Cp1252FallbackCode, UnicodeFallbackCode];
204188

205189
// pin once, reuse base pointer across attempts.
206190
fixed (byte* pData = versionBlock)
@@ -209,23 +193,22 @@ private static unsafe bool TryGetLocaleAndEncoding(Span<byte> data, out string?
209193

210194
foreach (string enc in encodings)
211195
{
212-
string subBlock = $"StringFileInfo\\{locale}{enc}{resource}";
213-
214-
if (NativeMethods.VerQueryValueW(basePtr, subBlock, out nint buffer, out _))
215-
return Marshal.PtrToStringAuto(buffer);
196+
string subBlock = $"\\StringFileInfo\\{locale}{enc}{resource}";
216197

217-
// Capture the VerQueryValueW's error immediately if it failed above.
218-
int lastError = Marshal.GetLastPInvokeError();
198+
// Grab the length to safely instantiate the string
199+
if (NativeMethods.VerQueryValueW(basePtr, subBlock, out nint buffer, out uint len) != 0 && buffer != IntPtr.Zero && len > 0)
200+
{
201+
ReadOnlySpan<char> valueSpan = new((void*)buffer, (int)len);
202+
valueSpan = valueSpan.TrimEnd('\0');
219203

220-
// If error is not resource type not found, throw the error
221-
if (lastError != ERROR_RESOURCE_TYPE_NOT_FOUND)
222-
throw new Win32Exception(lastError);
204+
// If the resulting string is empty, return the interned string.Empty to avoid allocating a new object on the heap
205+
return valueSpan.IsEmpty ? string.Empty : new string(valueSpan);
206+
}
223207
}
224208
}
225209
return null;
226210
}
227211

228-
229212
/// <summary>
230213
/// Check if a string is null or whitespace and return null if it is
231214
/// </summary>

AppControl Manager/Others/ListViewHelper-Shared.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,25 @@ internal static double MeasureText(string? text, double maxWidth)
239239
private const double InitValueAdded = 20;
240240

241241
/// <summary>
242-
/// Select all of the items in the ListView's ItemsSource
242+
/// Select all of the items in the ListView's ItemsSource.
243243
/// </summary>
244244
/// <param name="lw"></param>
245-
/// <param name="source"></param>
246-
internal static void SelectAll(ListView lw, IList source)
245+
internal static void SelectAll(ListView? lw)
247246
{
248-
// Clear existing selections from the List View
249-
lw.SelectedItems.Clear();
247+
if (lw is null) return;
250248

251-
foreach (var item in source)
249+
switch (lw.SelectionMode)
252250
{
253-
// Select each item
254-
lw.SelectedItems.Add(item);
251+
case ListViewSelectionMode.Multiple:
252+
case ListViewSelectionMode.Extended:
253+
lw.SelectRange(new(0, (uint)lw.Items.Count));
254+
break;
255+
case ListViewSelectionMode.Single:
256+
lw.SelectedItem = lw.Items.FirstOrDefault();
257+
break;
258+
case ListViewSelectionMode.None:
259+
default:
260+
break;
255261
}
256262
}
257263

AppControl Manager/Others/ListViewIncrementalController.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ internal sealed partial class ListViewIncrementalController(
6969
/// <summary>
7070
/// Selects all of the displayed rows on the ListView
7171
/// </summary>
72-
internal void SelectAll_Click()
73-
{
74-
if (ListViewRef is null || ObservableSource is null) return;
75-
ListViewHelper.SelectAll(ListViewRef, ObservableSource);
76-
}
72+
internal void SelectAll_Click() => ListViewHelper.SelectAll(ListViewRef);
7773

7874
/// <summary>
7975
/// Event handler for the Clear Data button

AppControl Manager/ViewModels/CreateSupplementalPolicyVM.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,9 +1606,7 @@ internal void StrictKernel_ClearDataButton_Click()
16061606
internal void StrictKernel_SelectAll_Click()
16071607
{
16081608
ListView? lv = ListViewHelper.GetListViewFromCache(ListViewHelper.ListViewsRegistry.SupplementalPolicy_StrictKernelMode_ScanResults);
1609-
if (lv is null) return;
1610-
1611-
ListViewHelper.SelectAll(lv, StrictKernelModeScanResults);
1609+
ListViewHelper.SelectAll(lv);
16121610
}
16131611

16141612
/// <summary>

AppControl Manager/ViewModels/EventLogsPolicyCreationVM.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ internal void ClearDataButton_Click()
228228
internal void SelectAll_Click()
229229
{
230230
ListView? lv = ListViewHelper.GetListViewFromCache(ListViewHelper.ListViewsRegistry.Event_Logs);
231-
if (lv is null) return;
232-
233-
ListViewHelper.SelectAll(lv, FileIdentities);
231+
ListViewHelper.SelectAll(lv);
234232
}
235233

236234
/// <summary>

AppControl Manager/ViewModels/FirewallSentinelVM.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,7 @@ internal void ClearBlockedPacketsLogs_Click()
16191619
internal void BlockedPacketsListView_SelectAll_Click()
16201620
{
16211621
ListView? lv = ListViewHelper.GetListViewFromCache(ListViewHelper.ListViewsRegistry.FirewallBlockedLogs);
1622-
if (lv is null) return;
1623-
ListViewHelper.SelectAll(lv, BlockedPackets);
1622+
ListViewHelper.SelectAll(lv);
16241623
}
16251624

16261625
internal void BlockedPacketsListView_DeSelectAll_Click()

AppControl Manager/ViewModels/IntuneDeploymentDetailsVM.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal IntuneDeploymentDetailsVM()
4242
() => MainInfoBarIsClosable, value => MainInfoBarIsClosable = value,
4343
Dispatcher, null, null);
4444

45-
CalculateColumnWidths();
45+
_ = Dispatcher.TryEnqueue(CalculateColumnWidths);
4646
}
4747

4848
internal readonly InfoBarSettings MainInfoBar;
@@ -436,12 +436,7 @@ internal void CtrlC_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvok
436436
internal void SelectAll_Click()
437437
{
438438
ListView? lv = ListViewHelper.GetListViewFromCache(ListViewHelper.ListViewsRegistry.Deployment_IntuneGroupsListView);
439-
if (lv is null)
440-
{
441-
return;
442-
}
443-
444-
ListViewHelper.SelectAll(lv, GroupNamesCollection);
439+
ListViewHelper.SelectAll(lv);
445440
}
446441

447442
/// <summary>

AppControl Manager/ViewModels/MDEAHPolicyCreationVM.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,7 @@ private void ApplyFilters() => ListViewHelper.ApplyFilters(
438438
internal void SelectAll_Click()
439439
{
440440
ListView? lv = ListViewHelper.GetListViewFromCache(ListViewHelper.ListViewsRegistry.MDE_AdvancedHunting);
441-
if (lv is null) return;
442-
443-
ListViewHelper.SelectAll(lv, FileIdentities);
441+
ListViewHelper.SelectAll(lv);
444442
}
445443

446444
/// <summary>
@@ -449,9 +447,7 @@ internal void SelectAll_Click()
449447
internal void DeSelectAll_Click()
450448
{
451449
ListView? lv = ListViewHelper.GetListViewFromCache(ListViewHelper.ListViewsRegistry.MDE_AdvancedHunting);
452-
if (lv is null) return;
453-
454-
lv.SelectedItems.Clear(); // Deselect all rows by clearing SelectedItems
450+
lv?.SelectedItems.Clear(); // Deselect all rows by clearing SelectedItems
455451
}
456452

457453
/// <summary>

AppControl Manager/eXclude/CommonCore/CommonCore.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Compile Include="$(MSBuildThisFileDirectory)Power\PowerPlan.cs" />
4949
<Compile Include="$(MSBuildThisFileDirectory)QuantumRelay\BinaryProtocol.cs" />
5050
<Compile Include="$(MSBuildThisFileDirectory)QuantumRelay\Helpers.cs" />
51+
<Compile Include="$(MSBuildThisFileDirectory)ServiceManagement.cs" />
5152
<Compile Include="$(MSBuildThisFileDirectory)ThermalMonitors\StorageTemperature.cs" />
5253
<Compile Include="$(MSBuildThisFileDirectory)ThermalMonitors\TemperatureSampler.cs" />
5354
</ItemGroup>

0 commit comments

Comments
 (0)