Проблемы с кодом инъекции

Поэтому, посмотрев в Интернете и отладив код, я обнаружил, что существуют проблемы с использованием CreateRemoteThread и CreateRemoteThreadEx в Windows 8, 8.1 и 10 (DLL вообще не вводит). Код прекрасно работает для тех, кто не использует Windows 8+. Мне было интересно, может ли кто-нибудь помочь мне отладить код, чтобы он работал на более новой операционной системе, и, если возможно, дать объяснение, почему он не работает. Это первый раз, когда я посмотрел на C#, я в основном программирую на Java.

Пока я следил за стеком, я знаю, что он исходит из InjectLibrary в Injector.cs

 // load dll via call to LoadLibrary using CreateRemoteThread
            hThread = Imports.CreateRemoteThread(_handle, IntPtr.Zero, 0, hLoadLib, pLibRemote, 0, IntPtr.Zero);

Program.cs:

using System;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Syringe;

namespace GameLauncherEx
{
    class Program
    {
        // Injector code by adaephon on ownedcore
        // www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-bots-programs/wow-memory-editing/265219-c-net-dll-injector.html

        static void Main(string[] args)
        {

                string ip = "127.0.0.1";
                int maxTryCount = 5;
                int waitWindowSleep = 1;
                int failInjectSleep = 500;
                string dll = "IPRedirect.dll";
                string client = string.Format("{0}\\MapleStory.exe", Environment.CurrentDirectory);

                if (!File.Exists(client))
                {
                    MessageBox.Show("Couldn't find MapleStory.exe", "GameLauncherEx");
                    return;
                }

                if (!File.Exists(string.Format("{0}\\{1}", Environment.CurrentDirectory, dll)))
                {
                    MessageBox.Show("Couldn't find IPRedirect.dll", "GameLauncherEx");
                    return;
                }

                IPAddress ipAddress;
            if (args.Length >= 1 && IPAddress.TryParse(args[0], out ipAddress)) {
                ip = args[0];
                MessageBox.Show(args[0]);
            }
                using(Process process = Process.Start(client, "GameLaunching"))
                {
                    while (process.MainWindowHandle == IntPtr.Zero && !process.HasExited)
                        Thread.Sleep(waitWindowSleep);

                    if (process.HasExited)
                        return;

                    for (int i = 0; i < maxTryCount; i++)
                    {
                        try
                        {
                            using (Injector injector = new Injector(process))
                            {   

                                injector.EjectOnDispose = false;
                                injector.InjectLibrary(dll);
                                if (ip != IPAddress.Loopback.ToString())
                                    injector.CallExport<IPInfo>(dll, "SetIP", new IPInfo(ip));

                                // Add any additional IPs you want maped here, you can also unmap them with UnMapIP if needed
                                //injector.CallExport<MapedIPInfo>(dll, "MapIP", new MapedIPInfo("RealGameIP", "YourServerIP"));
                                //injector.CallExport<MapedIPInfo>(dll, "UnMapIP", new MapedIPInfo("RealGameIP", "YourServerIP"));

                                return;
                            }
                        }
                        catch (Exception e)
                        {
                            Thread.Sleep(failInjectSleep);
                            MessageBox.Show(e.ToString());
                        }
                    }
                }

                MessageBox.Show("Failed to initialize GameLauncherEx");
            }

            [StructLayout(LayoutKind.Sequential)]
            struct IPInfo
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)]
                public string IP;

                public IPInfo(string ip)
                {
                    IP = ip;
                }
            }

            [StructLayout(LayoutKind.Sequential)]
            struct MapedIPInfo
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)]
                public string DestIP;

                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)]
                public string IP;

                public MapedIPInfo(string destIP, string ip)
                {
                    DestIP = destIP;
                    IP = ip;
                }
        }
    }
}

Injector.cs: http://pastebin.com/QUVXSTHC

Imports.cs http://pastebin.com/L1CtWYfN

Казалось, я превысил ограничение на количество символов, поэтому я разместил код на pastebin.

0 ответов

Другие вопросы по тегам