Skip to content

Loads a native Windows assembly... right from your .NET embedded resources. Works on all modern .NET platforms.

License

Notifications You must be signed in to change notification settings

gl2007/MemoryModule.NET

 
 

Repository files navigation

MemoryModule.NET

BuildStatus

Package Version
Cross platform CrossPlatformShield
Windows WindowsShield
Linux Coming soon
MacOS Coming soon

Loads unmanaged libraries right from your embedded resources! Works on Windows and Linux only, both on .NET Framework and .NET Core (and of course .NET 5.0)

Features:

  • Load x86 and x64 assemblies, right from the memory. No P/Invoke, no temporary files.
  • Correctly resolves loaded unmanaged libraries, and exposes a AssemblyResolve event for users to manually handle it.
  • Linux x86 (32 and 64 bit) support, through interoperation with glibc.

Sample code:

using MemoryModule;

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        delegate int addNumberProc(int a, int b);

            var asmBytes = File.ReadAllBytes($"SampleDLL.dll");

            var asm = NativeAssembly.Load(asmBytes);

            Console.WriteLine("Successfully loaded library.");
            var addNumberFunc = asm.GetDelegate<addNumberProc>("addNumbers");
            var rand = new Random();
            int num1 = rand.Next(0, 20);
            int num2 = rand.Next(0, 20);
            Console.WriteLine($"{num1}+{num2}={addNumberFunc(num1, num2)}");

            var greetFunc = asm.GetDelegate<GreetProc>("Greet");
            greetFunc();

            asm.Dispose();

See the DemoApp for more details.

Packages

Known issues

  • Windows: Beware of 64-bit dll files compiled using g++: fancycode/MemoryModule#108. These files must be compiled using -static-libgcc and -static-libstdc++ to load properly, in both the original C version and this version.
  • Windows: Resources are not supported.
  • Linux: Support is limited. While basic C/C++ libraries, such as libcurl, can be properly loaded, MemoryModule.NET may not work with other advanced libraries that contain unknown ELF relocations. If that's the case, please open an issue.
  • Linux: As MemoryModule.NET relies on certain glibc data structures, it may fail on systems that use beta/custom glibc version. Please open an issue for support.

About

Loads a native Windows assembly... right from your .NET embedded resources. Works on all modern .NET platforms.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.6%
  • Other 0.4%