Skip to content

Instantly share code, notes, and snippets.

@Manuel-S
Created January 16, 2021 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manuel-S/4508b8291c31ea7caf3719382360cf10 to your computer and use it in GitHub Desktop.
Save Manuel-S/4508b8291c31ea7caf3719382360cf10 to your computer and use it in GitHub Desktop.
How to inject into any .net application (unless AoT compiled)
<configuration>
<runtime>
<appDomainManagerType value="LauncherPatcher" />
<appDomainManagerAssembly value="LauncherPatcher, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</runtime>
</configuration>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
class LauncherPatcher : AppDomainManager {
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
{
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => {
var name = args.LoadedAssembly.GetName().Name;
// wait for relevant assemblies we want to hook into to be loaded
switch(name)
{
case "Application.Library":
//hook here
break;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment