From edcd26a2f21092371c9169ae56ae85c144a8bfd7 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 24 Feb 2023 18:43:40 +0100 Subject: [PATCH] feat: move to new injection supporting passing in data and returning integer --- .../NosSmooth.Comms.Abstractions.csproj | 6 +-- .../NosSmooth.Comms.Core.csproj | 5 +- src/Local/NosSmooth.Comms.Inject/DllMain.cs | 53 ++++++++++++------- .../NosSmooth.Comms.Inject.csproj | 10 ++-- .../NosSmooth.Comms.Local/CommsInjector.cs | 11 +++- .../NosSmooth.Comms.Local.csproj | 6 +-- 6 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/Core/NosSmooth.Comms.Abstractions/NosSmooth.Comms.Abstractions.csproj b/src/Core/NosSmooth.Comms.Abstractions/NosSmooth.Comms.Abstractions.csproj index f41c901..acb5a2e 100644 --- a/src/Core/NosSmooth.Comms.Abstractions/NosSmooth.Comms.Abstractions.csproj +++ b/src/Core/NosSmooth.Comms.Abstractions/NosSmooth.Comms.Abstractions.csproj @@ -5,13 +5,13 @@ enable enable NosSmooth.Comms.Data - 1.3.0 - Add result to handshake response. + 1.4.0 + Update dependencies. - + diff --git a/src/Core/NosSmooth.Comms.Core/NosSmooth.Comms.Core.csproj b/src/Core/NosSmooth.Comms.Core/NosSmooth.Comms.Core.csproj index b1e2d1b..f213d96 100644 --- a/src/Core/NosSmooth.Comms.Core/NosSmooth.Comms.Core.csproj +++ b/src/Core/NosSmooth.Comms.Core/NosSmooth.Comms.Core.csproj @@ -4,13 +4,14 @@ net7.0 enable enable - 1.1.1 + 1.2.0 + Update dependencies. - + diff --git a/src/Local/NosSmooth.Comms.Inject/DllMain.cs b/src/Local/NosSmooth.Comms.Inject/DllMain.cs index f7f18fe..c846f79 100644 --- a/src/Local/NosSmooth.Comms.Inject/DllMain.cs +++ b/src/Local/NosSmooth.Comms.Inject/DllMain.cs @@ -34,10 +34,11 @@ public class DllMain /// /// Enable named pipes server. /// + /// Should be zero, is not used. + /// The result, 0 success, 1 failure. [UnmanagedCallersOnly(EntryPoint = "EnableNamedPipes")] - public static void EnableNamedPipes() - { - Main + public static int EnableNamedPipes(nuint data) + => Main ( host => { @@ -46,42 +47,56 @@ public class DllMain (host.Services.GetRequiredService().ApplicationStopping); } ); - } /// /// Open a console. /// + /// Should be zero, is not used. + /// The result, 0 success, 1 failure. [UnmanagedCallersOnly(EntryPoint = "OpenConsole")] - public static void OpenConsole() + public static int OpenConsole(nuint data) { WinConsole.Initialize(false); + return 0; } /// /// Close a console. /// + /// Should be zero, is not used. + /// The result, 0 success, 1 failure. [UnmanagedCallersOnly(EntryPoint = "CloseConsole")] - public static void CloseConsole() + public static int CloseConsole(nuint data) { WinConsole.Close(); + return 0; } - private static void Main(Func> host) + private static int Main(Func> host) { - new Thread - ( - () => - { - try - { - MainEntry(host).GetAwaiter().GetResult(); - } - catch (Exception e) + try + { + new Thread + ( + () => { - Console.WriteLine(e.ToString()); + try + { + MainEntry(host).GetAwaiter().GetResult(); + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } } - } - ).Start(); + ).Start(); + + return 0; + } + catch (Exception) + { + return 1; + } } /// diff --git a/src/Local/NosSmooth.Comms.Inject/NosSmooth.Comms.Inject.csproj b/src/Local/NosSmooth.Comms.Inject/NosSmooth.Comms.Inject.csproj index 4c331e2..123e5a6 100644 --- a/src/Local/NosSmooth.Comms.Inject/NosSmooth.Comms.Inject.csproj +++ b/src/Local/NosSmooth.Comms.Inject/NosSmooth.Comms.Inject.csproj @@ -5,8 +5,8 @@ enable enable true - 1.3.0 - Add Costura.Fody support. + 1.4.0 + Update to new injection passing in data and returning an integer. @@ -16,10 +16,10 @@ - - + + - + diff --git a/src/Local/NosSmooth.Comms.Local/CommsInjector.cs b/src/Local/NosSmooth.Comms.Local/CommsInjector.cs index 8dcf648..6c9176b 100644 --- a/src/Local/NosSmooth.Comms.Local/CommsInjector.cs +++ b/src/Local/NosSmooth.Comms.Local/CommsInjector.cs @@ -172,12 +172,21 @@ public class CommsInjector private Result Inject(Process process, string method) { - return _injector.Inject + var injectResult = _injector.Inject ( process, Path.GetFullPath("NosSmooth.Comms.Inject.dll"), "NosSmooth.Comms.Inject.DllMain, NosSmooth.Comms.Inject", method ); + + if (!injectResult.IsDefined(out var result)) + { + return Result.FromError(injectResult); + } + + return result == 0 + ? Result.FromSuccess() + : new GenericError("Unknown injection error has happened."); } } \ No newline at end of file diff --git a/src/Local/NosSmooth.Comms.Local/NosSmooth.Comms.Local.csproj b/src/Local/NosSmooth.Comms.Local/NosSmooth.Comms.Local.csproj index d918abd..cb9f066 100644 --- a/src/Local/NosSmooth.Comms.Local/NosSmooth.Comms.Local.csproj +++ b/src/Local/NosSmooth.Comms.Local/NosSmooth.Comms.Local.csproj @@ -4,8 +4,8 @@ net7.0 enable enable - 1.3.0 - Update Inject version to 1.3.0. + 1.4.0 + Update to new injection passing in data and returning an integer. @@ -17,7 +17,7 @@ - + All None -- 2.48.1