Example #1
0
    private static void InjectProcessHandle(IntPtr pHandle, string path)
    {
        var bytes = Encoding.Default.GetBytes(path);
        var lpNumberOfBytesWritten = 0u;
        var lpThreadId             = 0u;

        IntPtr procAddress = ProcessInjection.GetProcAddrPtr(ProcessInjection.GetModuleHandlePtr("kernel32.dll"), "LoadLibraryA");

        if (procAddress == IntPtr.Zero)
        {
            throw new Exception("GetProcAddress");
        }

        var intPtr = ProcessInjection.VirtualAllocExPtr(pHandle, IntPtr.Zero, (uint)bytes.Length, 12288u, 64u);

        if (intPtr == IntPtr.Zero)
        {
            throw new Exception("VirtualAllocEx");
        }

        if (!ProcessInjection.WriteProcMemory(pHandle, intPtr, bytes, (uint)bytes.Length, ref lpNumberOfBytesWritten))
        {
            throw new Exception("WriteProcessMemory");
        }

        IntPtr intPtr2 = ProcessInjection.CreateRemoteThrdPtr(pHandle, IntPtr.Zero,
                                                              0u, intPtr, intPtr, 0u, ref lpThreadId);

        if (intPtr2 == IntPtr.Zero)
        {
            throw new Exception("CreateRemoteThread");
        }

        ProcessInjection.WaitForObj(intPtr2, uint.MaxValue);
        ProcessInjection.CloseHandle(intPtr2);
        Program.LogInfoMessage("core", $"Injected Successfully: {pHandle} {path}");
    }