From 64ca1a1ba5af1795cbf4c11bb6ea3ae28e46c5e8 Mon Sep 17 00:00:00 2001 From: maniglia Date: Fri, 27 Dec 2024 18:03:57 +0100 Subject: [PATCH] Testing --- .../CubeProgrammerApi.cs | 30 +++++++++---------- .../Native/Utility.cs | 2 ++ src/Directory.csproj.props | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs b/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs index 15768f8..e7de9f1 100644 --- a/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs +++ b/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs @@ -94,7 +94,7 @@ private void LoadStLinkDriver() hasKB2533623 = Native.Utility.GetProcAddress(hModule, "AddDllDirectory") != IntPtr.Zero; } - int dwFlags = 0; + var dwFlags = 0; if (hasKB2533623) { @@ -106,7 +106,7 @@ private void LoadStLinkDriver() if (this._handleSTLinkDriver.IsInvalid) { - int error = Marshal.GetLastWin32Error(); + var error = Marshal.GetLastWin32Error(); this._logger?.LogError("Loading {0} {1} library error: {2} !", target + @"\STLinkUSBDriver.dll", Environment.Is64BitProcess ? "x64" : "x86", error); this._handleSTLinkDriver = null; } @@ -158,22 +158,22 @@ private void LoadProgrammer() hasKB2533623 = Native.Utility.GetProcAddress(hModule, "SetDllDirectoryW") != IntPtr.Zero; } - int dwFlags = 0; + var dwFlags = 0; if (hasKB2533623) { - // If KB2533623 is installed then specify the more secure LOAD_LIBRARY_SEARCH_USER_DIRS in dwFlags - //dwFlags = Native.Utility.LOAD_LIBRARY_SEARCH_USER_DIRS; + // If KB2533623 is installed then specify the more secure LOAD_WITH_ALTERED_SEARCH_PATH in dwFlags + dwFlags = Native.Utility.LOAD_WITH_ALTERED_SEARCH_PATH; - var result = Native.Utility.SetDllDirectoryW(target); + //var result = Native.Utility.SetDllDirectoryW(target); - if (result) - { + //if (result) + //{ this._handleProgrammer = Native.Utility.LoadLibraryEx(target + @"\Programmer.dll", IntPtr.Zero, dwFlags); if (this._handleProgrammer.IsInvalid) { - int error = Marshal.GetLastWin32Error(); + var error = Marshal.GetLastWin32Error(); this._logger?.LogError("Loading {0} {1} library error: {2} !", target + @"\Programmer.dll", Environment.Is64BitProcess ? "x64" : "x86", error); this._handleProgrammer = null; } @@ -181,12 +181,12 @@ private void LoadProgrammer() { this._logger?.LogInformation("Loading {0} - {1} library.", "Programmer.dll", Environment.Is64BitProcess ? "x64" : "x86"); } - } - else - { - int error = Marshal.GetLastWin32Error(); - this._logger?.LogError("SetDllDirectory {0} error: {1} !", target, error); - } + //} + //else + //{ + // var error = Marshal.GetLastWin32Error(); + // this._logger?.LogError("SetDllDirectory {0} error: {1} !", target, error); + //} } #endif } diff --git a/src/01/KSociety.SharpCubeProgrammer/Native/Utility.cs b/src/01/KSociety.SharpCubeProgrammer/Native/Utility.cs index 64f0801..7e42292 100644 --- a/src/01/KSociety.SharpCubeProgrammer/Native/Utility.cs +++ b/src/01/KSociety.SharpCubeProgrammer/Native/Utility.cs @@ -12,6 +12,8 @@ namespace SharpCubeProgrammer.Native /// internal static class Utility { + internal const int LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008; + /// /// This value represents the recommended maximum number of directories an application should include in its DLL search path. /// diff --git a/src/Directory.csproj.props b/src/Directory.csproj.props index f76112d..00b8b04 100644 --- a/src/Directory.csproj.props +++ b/src/Directory.csproj.props @@ -3,7 +3,7 @@ - netstandard2.1;netstandard2.0;net8.0 + netstandard2.1;netstandard2.0 $([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)ksociety.snk)) true