Skip to content

A tiny hack of the System.Private.CoreLib to provide an Unmanaged EmitCalli implementation at the .NET Standard 2.0 layer.

License

Notifications You must be signed in to change notification settings

3F/UnmanagedEmitCalli

Repository files navigation

A tiny hack of the System.Private.CoreLib to provide missed Unmanaged EmitCalli implementation at the .NET Standard 2.0 layer.

Build status release-src License NuGet package

Why UnmanagedEmitCalli ?

An Unmanaged EmitCalli is available only with .NET Core 2.1+ [?] That turns into a quest when you need .NET Standard 2.0 targeting.

This, however, does not require a full reimplementing or a huge dependencies like Cecil etc.

Because you can simply use the same techniques as we do 3F/Conari#13 (comment)

UnmanagedEmitCalli provides most common implementation that can be used either through dependencies or copy-paste of a bit of source code. Enjoy!

Where ?

This was used initially for 🧬 Conari - Platform for working with unmanaged memory, pe-modules, related PInvoke features, and more for: Libraries, Executable Modules, enjoying of the unmanaged native C/C++ in .NET world, and other raw binary data. Even accessing to complex types like structures without their declaration at all.

Example

Same for .NET Framework and .NET Core

ILGenerator il = dyn.GetILGenerator();

for(int i = 0; i < mParams.Length; ++i) {
    il.Emit(OpCodes.Ldarg, i);
}

if(IntPtr.Size == sizeof(Int64)) {
    il.Emit(OpCodes.Ldc_I8, ptr.ToInt64());
}
else {
    il.Emit(OpCodes.Ldc_I4, ptr.ToInt32());
}

il.EmitCalliStd(CallingConvention.Cdecl, tret, mParams);
il.Emit(OpCodes.Ret);

🍰 Open and Free

Open Source project; MIT License, Yes! Enjoy!

🗸 License

The MIT License (MIT)

Copyright (c) 2019-2021  Denis Kuzmin <x-3F@outlook.com> github/3F

[ ☕ Donate ]

UnmanagedEmitCalli contributors https://github.com/3F/UnmanagedEmitCalli/graphs/contributors

Make your amazing contribution!