Dewera / Lunar

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

Failed to load the dependency KERNEL32.dll into the process #37

Closed AhmedZero closed 2 years ago

AhmedZero commented 2 years ago

when i inject DLL to application, it shows me that

Unhandled exception. System.ApplicationException: Failed to load the dependency KERNEL32.dll into the process
   at Lunar.LibraryMapper.LoadDependencies() in G:\My_Projects\ExSharpBase\Lunar\LibraryMapper.cs:line 723
   at Lunar.LibraryMapper.MapLibrary() in G:\My_Projects\ExSharpBase\Lunar\LibraryMapper.cs:line 107
   at VIP.Program.<>c.<StartTaskGame>b__17_5() in G:\My_Projects\ExSharpBase\Program.cs:line 201
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

My program is X64 The target is x86.

Dewera commented 2 years ago

Almost certainly an issue with the target application and not the library as dependencies are loaded using the Windows loader (LoadLibraryW in this case) and can't really fail unless the target process is blocking the execution method or LoadLibraryW itself. If I had to guess it is likely the latter.

AhmedZero commented 2 years ago

sometimes success and sometimes not.

Dewera commented 2 years ago

Currently dependencies (i.e. kernel32) are loaded (or have their references increased) using the Windows loader, specifically LoadLibraryW as mentioned. This is invoked by creating a standard remote thread (using RtlCreateUserThread,) nothing special.

If you are using a modern version of Windows (i.e. a newer version of 10 or 11) this operation is pretty unlikely to fail or be unstable without some third party interference which could very well be the case with something like a game. Unless you've got a Windows error code returned by the function there's not much I can do to help.

Have a go and see if you can run the tests in the project - If so it's the process that you are injecting into that is the issue.