Reloaded-Project / Reloaded.Injector

C# DLL Injection Library capable of injecting x86 DLLs to x86 process from x64 processes.
GNU Lesser General Public License v3.0
159 stars 32 forks source link

[Suggestion] Provide Docs on Injecting DLLs #4

Closed ghost closed 3 years ago

ghost commented 3 years ago

For a good library like this, I think it would be a good idea to make docs on how to inject DLLs into a process. I didn't find any good way to convert a C++ DLL to bytes and stuff, and using the type "dll" with the code OpenFileDialog open = new OpenFileDialog(); open.InitialDirectory = "c:\\"; open.Filter = "DLL Cheats (*.dll)|*.dll"; open.RestoreDirectory = true; if (open.ShowDialog() == DialogResult.OK) { string fullPath = open.FileName; string fileName = open.SafeFileName; string path = fullPath.Replace(fileName, ""); Process[] proclist = Process.GetProcesses(); foreach (Process pr in proclist) { if (pr.ProcessName.StartsWith("Minecraft")) { Injector inj = new Injector(pr); inj.Inject(fullPath); inj.Dispose(); } } } didn't work. I tried using both Memory.dll and this, nothing from either of them.

Sewer56 commented 3 years ago

Given that you have tried using 2 libraries, have you considered that perhaps your problem may be somewhere else?

image

I copied your code to a new empty .NET 5 Project, replacing Minecraft (not installed on this laptop) with notepad and had no issues.

I injected Reloaded-II because it was the first DLL that came into my head.

ghost commented 3 years ago

Hm, I'm using some try-catch loops (whenever I try to inject it, the catch always triggers). I didn't find a way to remove it otherwise without the program crashing.

Sewer56 commented 3 years ago

When thinking about injection problems; the following things typically come to mind:

I know it's not much of a hint but it's better than nothing :P

The result of GetLastError may possibly also be useful but with how this library's built it's not an option.

ghost commented 3 years ago

My source code is available if you want to take a quick check on it (if you have the time) https://github.com/AcaiBerii/BootJect Otherwise, I do have an admin script in my manifest. (<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />), leftover code from my experiments with Memory.DLL. My antivirus is not running at the moment and not giving me any notifications of the sort.

I do believe that the process I'm trying to inject the DLL into has it's own anticheat, but it may not be true (Minecraft: Windows 10 Edition). I'm making a mod for it and it should work. Otherwise, I will try another app to inject my dlls into. I did hear you tried Notepad, so I will try that next. Thank you for your time!

ghost commented 3 years ago

Ah, never mind, I see now. My program is coded in x64, and the DLL injection is meant for x32/x86. Sorry!

Sewer56 commented 3 years ago

Note: Unlike most libraries, this library does support injecting into x86 processes from an x64 process (but not the other way around).

If you look at the library's Unit Tests, you should see such is the case.

ghost commented 3 years ago

I got an error from the try-catch loop with an exception this time: System.ComponentModel.Win32Exception (0x800004005): A 32 bit processes cannot access modules of a 64 bit process. So that would mean the library is x32? I couldn't find any other way to find this out.

Sewer56 commented 3 years ago

Hint: It means your program is running as 32-bit.

If you're working with the old .NET Framework and compiling under AnyCPU, I suggest googling the term "Prefer 32-bit"; it's on by default.

ghost commented 3 years ago

Ah, thank you. I did update my build config and it worked. I appreciate your answer a lot!