C# Injector Source?

Posts 13 of 3 · Page 1 of 1
C# Injector Source?
Add this to your code in Button1_click (or w/e you want)
Code:
 AttachProcess();
Then add this code anywhere.
Code:
        int processId = 0;
        private void AttachProcess()
        {
            bool newInstanceFound = false;

            while (!newInstanceFound)
            {
                Process[] processes = Process.GetProcessesByName(Engine.exe); // or Engine (I don't know)
                foreach (Process process in processes)
                {
                    // Simply attach to the first one found.

                    // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                    if (process.MainWindowHandle == IntPtr.Zero)
                    {
                        continue;
                    }

                    // Keep track of hooked processes in case more than one need to be hooked
                    HookManager.AddHookedProcess(process.Id);
                    processId = process.Id;

                    // Inject DLL into target process
                    RemoteHooking.Inject(
                        process.Id,
                        InjectionOptions.Default,
                        "FlamesHack32.dll", // 32-bit version (the same because AnyCPU) could use different assembly that links to 32-bit C++ helper dll
                        "FlamesHack64.dll", // 64-bit version (the same because AnyCPU) could use different assembly that links to 64-bit C++ helper dll
    // the optional parameter list...
                        ChannelName // The name of the IPC channel for the injected assembly to connect to
                        );

                    // Ensure the target process is in the foreground,
                    // this prevents issues where the target app appears to be in 
                    // the foreground but does not receive any user inputs.
                    // Note: the first Alt+Tab out of the target application after injection
                    //       may still be an issue - switching between windowed and 
                    //       fullscreen fixes the issue however (see ScreenshotInjection.cs for another option)
                    BringProcessWindowToFront(process);

                    newInstanceFound = true;
                    break;
                }
                Thread.Sleep(10);

            }
        }
Please Test for me and enjoy if it works
Quote Originally Posted by flameswor10 View Post
Add this to your code in Button1_click (or w/e you want)
Code:
 AttachProcess();
Then add this code anywhere.
Code:
        int processId = 0;
        private void AttachProcess()
        {
            bool newInstanceFound = false;

            while (!newInstanceFound)
            {
                Process[] processes = Process.GetProcessesByName(Engine.exe); // or Engine (I don't know)
                foreach (Process process in processes)
                {
                    // Simply attach to the first one found.

                    // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                    if (process.MainWindowHandle == IntPtr.Zero)
                    {
                        continue;
                    }

                    // Keep track of hooked processes in case more than one need to be hooked
                    HookManager.AddHookedProcess(process.Id);
                    processId = process.Id;

                    // Inject DLL into target process
                    RemoteHooking.Inject(
                        process.Id,
                        InjectionOptions.Default,
                        "FlamesHack32.dll", // 32-bit version (the same because AnyCPU) could use different assembly that links to 32-bit C++ helper dll
                        "FlamesHack64.dll", // 64-bit version (the same because AnyCPU) could use different assembly that links to 64-bit C++ helper dll
    // the optional parameter list...
                        ChannelName // The name of the IPC channel for the injected assembly to connect to
                        );

                    // Ensure the target process is in the foreground,
                    // this prevents issues where the target app appears to be in 
                    // the foreground but does not receive any user inputs.
                    // Note: the first Alt+Tab out of the target application after injection
                    //       may still be an issue - switching between windowed and 
                    //       fullscreen fixes the issue however (see ScreenshotInjection.cs for another option)
                    BringProcessWindowToFront(process);

                    newInstanceFound = true;
                    break;
                }
                Thread.Sleep(10);

            }
        }
Please Test for me and enjoy if it works

You do realise you failed at posting this code? /:

What does the WinAPI function "BringProcessWindowToFront(...);" have to do with injection?

The entire namespace "RemoteHooking" does not exist, let alone the "RemoteHooking.Inject(...)" method. Same with the "HookManager" namespace, as is the function "newInstanceFound".
Quote Originally Posted by freedompeace View Post
You do realise you failed at posting this code? /:

What does the WinAPI function "BringProcessWindowToFront(...);" have to do with injection?

The entire namespace "RemoteHooking" does not exist, let alone the "RemoteHooking.Inject(...)" method. Same with the "HookManager" namespace, as is the function "newInstanceFound".

LOL whoopsies. Lemme get the rest
Posts 13 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?