Here is my task:
- Inject custom managed code into running managed WPF application (i.e. my code should run in other AppDomain)
- Injected code must be executed on UI thread
When I say 'best' I mean that:
- Injection process must be as stable as possible (no thread deadlocks, etc.)
- Code should run on x86 and x64 platforms without problem (especially on Vista x64)
Minimal use-case
- select running WPF program
- inject custom code
- inject code changes title of the main window of target process to "Code Injected"
Solutions I'm evaluating:
1) Injection via windows hooks (like in Snoop)
pros:
- injected code runs on UI thread
cons:
- requires mixed (c++/cli) external dll
- hard to debug
2) Injection via EasyHook library
pros:
- library looks solid and well-tested
cons:
- didn't find a way to run code on UI thread
- injection library must be signed and installed in GAC
3) Injection via WriteProcessMemory/CreateRemoteThreadEx/LoadLibrary
pros:
- simple
cons:
- very unstable (code must be executed in DllMain, CLR hosting required, etc)
I'm going to use method #1. Can you recommend a better approach?
Are there any decent techniques based on CLR hosting in unmanaged DLLs ?
Note, that I'm aware of these questions: