Answer the question
In order to leave comments, you need to log in
Code injection in .NET?
The task is this:
There is an assembly in which third-party assemblies are loaded (ClickOnce applications are loaded from a remote server).
Next, I want to find all the windows of the loaded assembly (this is done), find their Activate method (too), and inject my code to intercept the creation of the window.
Moreover, it is required to make the injected code refer to the method of the main assembly.
I found how to do it through Mono.Cecil, but I want to implement it only using Framework'a.
Here is an example code:
private static void InjectWindow(Assembly app)
{
Type[] types = app.GetTypes();
foreach (Type type in types)
{
//Если базовый тип выбранного типа - Окно, инъекцируем
if (type.BaseType.Name.Equals("Window", StringComparison.OrdinalIgnoreCase))
{
MethodInfo activate = type.GetMethod("Activate");
//Теперь надо как-то дописать свой код
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question