I'm working on a unit testing framework and part of that is intercepting calls to methods. I had a prototype using pointer manipulation on the pointers in MethodBase.MethodHandle
but in some cases it would stop working depending on if the debugger was attached or not and in other cases it wouldn't work with functions (had it working for Actions though).
I suspect pointer manipulation is still a possible option but I don't know the memory layout or anything.
The fallback option I came up with is having the test method call my function with the function they want to call and then I generate a dynamic method, copying the IL and altering call instructions to call my methods instead. But it's not a great solution.
I looked through tens of sources but these are the ones that got me closest:
- https://stackoverflow.com/a/36415711/2350981
- https://github.com/pardeike/Harmony (uses pointer change in source code)
Aucun commentaire:
Enregistrer un commentaire