Giter Site home page Giter Site logo

reloaded-project / reloaded.injector Goto Github PK

View Code? Open in Web Editor NEW
145.0 8.0 32.0 6.39 MB

C# DLL Injection Library capable of injecting x86 DLLs to x86 process from x64 processes.

License: GNU Lesser General Public License v3.0

C# 100.00%
dll-injector inject-dlls csharp x64 x86 x86-64

reloaded.injector's People

Contributors

drobor avatar sewer56 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reloaded.injector's Issues

Allow to set bigger size for circular buffer

At the moment the circular buffer size is hardcoded to 4096:
https://github.com/Reloaded-Project/Reloaded.Injector/blob/master/Source/Reloaded.Injector/Injector.cs#L40

Would it be possible to make that an optional parameter for the Injector constructor?
I want to use a struct as a remote call argument that is too big for the current circular buffer.

EDIT:
And maybe it would be good to check parameterPtr after this line:
https://github.com/Reloaded-Project/Reloaded.Injector/blob/master/Source/Reloaded.Injector/Injector.cs#L115
If it is zero then the parameter struct couldn't be fit into the circular buffer and an exception should be thrown.

What about run x64 code in the x86 process?

Wait! I'm not crazy, maybe...
Take a look into this: http://blog.rewolf.pl/blog/?p=102
I thought in try implement this in C# by me self one day then it's saved in my favorite a good time, but I don't readed yet, then give a try if you like it~
My real objective is load x64 dll in x86 process, but looks like is hard do this only with this, to my problem I need kernel-level permission, then I don't have much meaning into me implementing this.

[Suggestion] Provide Docs on Injecting DLLs

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.

Shellcode is imploding on wine/lutris.

var shellcode = new Reloaded.Injector.Shellcode(thisProcess); <- kaboom.

I've got really no idea why this is happening. I was troubleshooting why our Linux folk couldn't run my .NET 5 test builds. I can allocate just fine with ExternalMemory.

Linux rlpc 5.8.0-59-generic #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

2021-07-04 20:21:40.016 -04:00 [ERR] A fatal error has occurred.
System.Exception: Failed to allocate memory using VirtualAlloc/VirtualAllocEx
   at Reloaded.Memory.Buffers.MemoryBufferHelper.Run[T](Int32 retries, Func`1 function)
   at Reloaded.Memory.Buffers.MemoryBufferHelper.Allocate(Int32 size, Int32 minimumAddress, Int32 maximumAddress, Int32 retryCount)
   at Reloaded.Assembler.Assembler.AllocateResult(Int32 resultSize, Int32 retryCount)
   at Reloaded.Assembler.Assembler..ctor(Int32 textSize, Int32 resultSize)
   at Reloaded.Injector.Shellcode..ctor(Process targetProcess)
   at Dalamud.Injector.EntryPoint.Inject(Process process, DalamudStartInfo startInfo)
   at Dalamud.Injector.EntryPoint.Main(Int32 argc, IntPtr argvPtr)

Allow creating process with injected DLL

I am trying to hook Vulkan in an application, and due to how the Vulkan loader works, it doesn't seem possible to hook after the application calls vkCreateInstance.

[X64.Function(X64.CallingConventions.Microsoft)]
[X86.Function(X86.CallingConventions.Stdcall)]
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate Result vkQueuePresentKHR(Queue queue, PresentInfoKHR* pPresentInfo);```

...

var handle = Kernel32.GetModuleHandle("vulkan-1");

// QueuePresentKHRFn is never called.
this.VkQueuePresentKHRHook  = ReloadedHooks.Instance.CreateHook<vkQueuePresentKHR>(QueuePresentKHRFn, (long)handle.GetProcAddress("vkQueuePresentKHR")).Activate();

I realize that the canonical way of doing Vulkan hooking is via layers, but doing it via a validation layer complicates .NET interop, so if possible it would be nice to do it the 'traditional' way.

To be able to hook Vulkan properly, I need to be able to obtain a handle to the created VkInstance, and thereafter I can use vkGetInstanceProcAddr. vkCreateInstance is called directly via vulkan-1.dll exports, so if I can hook the process before the target application creates its instance, I can obtain a handle to the VkInstance and resolve the other functions via vkInstanceGetProcAddr.

Detours provides DetourCreateProcessWithDllEx which does injection before the process is fully loaded, so I can hook vkCreateInstance as early as possible. I was wondering if this functionality could also be provided in Reloaded.Injector.

Alternatively maybe I'm doing things completely wrong and there's a much easier way to hook Vulkan calls without needing early-hooking, in which case I would be happy to do instead.

System.MissingMethodException: Method not found on injector initialisation

Reloaded.Hooks 4.0.1
Reloaded.Injector 1.2.4
.NET version = .net5-windows

Project using:
Omega.zip

I'm trying to inject a .NET library into a unmanaged process (x86) and spawn a console. Everything including DllExport should be setup correctly but when I try to construct the injector:

var p = Process.Start(@"C:\Development\Tools\PE-bear_0.5.5.2_x86_win_vs17\PE-bear.exe"); var inject = new Injector(p);

An error occures:

System.MissingMethodException: Method not found: 'Reloaded.Memory.Buffers.PrivateMemoryBuffer Reloaded.Memory.Buffers.MemoryBufferHelper.CreatePrivateMemoryBuffer(Int32, Int64, Int64, Int32)'. at Reloaded.Injector.Shellcode..ctor(Process targetProcess) at Reloaded.Injector.Injector..ctor(Process process) at <Program>$.<Main>$(String[] args) in *****:line 19

When I'm using version 3.0.0 it does inject...

WaitHandleCannotBeOpenedException "No handle of the given name exists"

Not sure under which repo this issue should be (related to Reloaded.Memory.Buffers). I am running the following code in a new .NET framework Console App project (4.8) set to x64:

Process process = Process.Start("notepad.exe")
Injector injector = new Injector(process)

And in the output window are the following errors:

Exception thrown: 'System.Threading.WaitHandleCannotBeOpenedException' in mscorlib.dll
No handle of the given name exists.

Exception thrown: 'System.Exception' in PeNet.dll
Cannot find corresponding section.

Each exception is thrown multiple times. Despite this, continuing to injected a DLL and calling a function still seems to work though. The DLL I am testing with is making a CreateFileA hook using the example code in the Reloaded.Hooks documentation, and the existence of the following line seems to crash the host program:

_createFileAHook = ReloadedHooks.Instance.CreateHook<CreateFileA>(CreateFileAImpl, (long)createFileAPointer);

I have verified that the createFileAPointer is valid and accurate, and also attempted to run the injector in administrator mode but notepad (or any other app) still crash.

Unsure if the two issues are related, but at any rate the PeNet exception seems to be legitimate so I am curious if it is indeed an issue.

EDIT: The crash is due to the DLL's dependencies (e.x. Reloaded.Hook.Dll) not being present at the same directory as the executable being injected to (like notepad), so unrelated I guess(?)

Injecting into.Net 6.0

There is an app I work with that used to run on .Net 4.x. I needed to tweak it a bit so I created an app.config file which loaded a dummy TraceWriter which allowed me to get my own code running inside the .net 4.x process.

The app has recently upgraded to .net 6.x and the above method seems to not work anymore (I suspect because App.configs aren't used anymore).

Do you have any suggestions on how to continue running .net code in another .net process?

Eject doesn't unload injected dll from target process.

The injected DLL is present in loaded DLLs for the target process after calling Eject() and Dispose()

In my case injector app is using the same DLL to access the shared classes. Without removing the DLL when work is done, my app is blocked for any file upgrades since the target app locks the DLL.

Error when injecting into CREATE_SUSPENDED process

I get the following exception when I create an Injector for a suspended process:

System.ComponentModel.Win32Exception: 'Only part of a ReadProcessMemory or WriteProcessMemory request was completed'

This is the code I use to create the process and inject.

if (CreateProcess(location, new StringBuilder($@"""{location}"" {arguments}"), null, null, false, CREATE_PROCESS.CREATE_SUSPENDED, null, null, new STARTUPINFO(), out var processInformation))
{
    var process = Process.GetProcessById((int)processInformation.dwProcessId);
    var injector = new Injector(process);
}

If I create the process without the CREATE_SUSPENDED flag, it launches without any errors.

For context, I'm coming from EasyHook and was looking for a more updated alternative and found Reloaded.Injector/Reloaded.Hooks.
In EasyHook, injecting into a suspended thread works as expected, where I then resume the thread from inside when I'm ready.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.