Dewera / Lunar

A lightweight native DLL mapping library that supports mapping directly from memory
MIT License
584 stars 102 forks source link

Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. #8

Closed NotoriousRebel closed 4 years ago

NotoriousRebel commented 4 years ago

This is an awesome project that I saw months ago and finally have a reason to use now! Just cloned the repo, compiled it, and added it as an assembly reference my project is using .net core 3.1. This is what my code looks like:

var dllstring = base64encoded_dll;
ReadOnlyMemory<byte> data = Convert.FromBase64String(dllstring);
Process process = Process.GetCurrentProcess();
var libraryMapper = new Lunar.LibraryMapper(process, data);
libraryMapper.MapLibrary();

It also crashes with the same error if instead of data I give it a path to my dll on disk. This the stack trace:


Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
   at Lunar.RemoteProcess.ProcessManager.ResolveDllName(String dllName)
   at Lunar.RemoteProcess.ProcessManager.GetFunctionAddress(Module module, ExportedFunction exportedFunction)
   at Lunar.RemoteProcess.ProcessManager.GetFunctionAddress(String moduleName, String functionName)
   at Lunar.LibraryMapper.BuildImportAddressTable()
   at Lunar.LibraryMapper.MapLibrary()
Dewera commented 4 years ago

Hmm based on the stack trace I can see what the issue is. There's an imported DLL that has a api-ms prefix (hence, it is an API set) and the libraries trying to resolve the name of it using the API set map but failing to find the corresponding mapping. This is weird and I've never had this happen before.

Unless you can debug this yourself and provide me with the info, would it be possible to send me a copy of the DLL so that I can check out its import table and run it through a debugging session?

NotoriousRebel commented 4 years ago

I added you on Discord and can give you a copy of the DLL it's a .Net Core 3.1 native library compiled with CoreRT following this guide

Dewera commented 4 years ago

Thanks for reporting this, just pushed through a fix.