-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a sample testing framework-dependent deployment.
Closes #12.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
sealed class InjectedProgram : IInjectedProgram | ||
{ | ||
static readonly TimeSpan _timeout = TimeSpan.FromMinutes(1); | ||
|
||
public static async Task<int> RunAsync(InjectedProgramContext context, ReadOnlyMemory<string> args) | ||
{ | ||
if (context.InjectorProcessId != null) | ||
return 42; | ||
|
||
Console.WriteLine("Starting conhost.exe..."); | ||
|
||
using var proc = new Process() | ||
{ | ||
StartInfo = new() | ||
{ | ||
FileName = "conhost.exe", | ||
}, | ||
}; | ||
|
||
_ = proc.Start(); | ||
|
||
try | ||
{ | ||
if (!proc.WaitForInputIdle(_timeout)) | ||
throw new TimeoutException(); | ||
|
||
Console.WriteLine("Started as {0}. Injecting...", proc.Id); | ||
|
||
using var target = TargetProcess.Open(proc.Id); | ||
using var injector = new AssemblyInjector( | ||
target, | ||
new AssemblyInjectorOptions(typeof(InjectedProgram).Assembly.Location) | ||
.WithInjectionTimeout(_timeout) | ||
.WithCompletionTimeout(_timeout)); | ||
|
||
await injector.InjectAssemblyAsync(); | ||
|
||
Console.WriteLine("Injected."); | ||
|
||
var code = await injector.WaitForCompletionAsync(); | ||
|
||
Console.WriteLine("Returned code {0}.", code); | ||
|
||
return code == 42 ? 0 : 1; | ||
} | ||
finally | ||
{ | ||
proc.Kill(true); | ||
|
||
await proc.WaitForExitAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<SelfContained>false</SelfContained> | ||
</PropertyGroup> | ||
</Project> |