-
Notifications
You must be signed in to change notification settings - Fork 44
Description
I am interested in experimenting with using DNNE to generate proxy libraries in C# using source generators, but I believe there is additional functionality necessary in DNNE to do so. I'm intending for this issue to serve as a discussion into how this functionality could be exposed (or if it's even considered to be within scope for the project.)
As a simple example: imagine that we want to log API calls to a COM library, which has the following exports:
DllGetClassObject
DllCanUnloadNowA proxy library for this can be implemented today with code similar to the example below:
// The Get* methods will perform NativeLibrary.Load/GetExport to retrieve the exports from the real library.
static readonly delegate* unmanaged<Guid*, Guid*, void**, uint> DllGetClassObject = GetDllGetClassObject();
static readonly delegate* unmanaged<uint> DllCanUnloadNow = GetDllCanUnloadNow();
[UnmanagedCallersOnly(EntryPoint = "DllGetClassObject")]
static uint ProxyDllGetClassObject(Guid* rclsid, Guid* riid, void** ppv)
{
// Perform some logging
return DllGetClassObject(rclsid, riid, ppv);
}
[UnmanagedCallersOnly(EntryPoint = "DllCanUnloadNow")]
static uint ProxyDllCanUnloadNow()
{
// Perform some logging
return DllCanUnloadNow();
}The signatures for these functions are well-known, but for the sake of the example let's imagine we either don't know what they are, or that they aren't relevant for what we want to do (in this example, logging API calls.)
Let's say that we only want to log calls to DllGetClassObject, and we don't care about DllCanUnloadNow (or the potentially many other exports in the library). We would need to know the signatures of all of these exports in order to produce a proxy library with the above technique.
The solution typically employed for this is for the body of the proxy method to simply jmp to the address of the real method, but as far as I'm aware there is currently no way to replicate this technique from DNNE.