1

因此,在网上查看并调试代码后,我发现在 Windows 8、8.1 和 10 上使用 CreateRemoteThread 和 CreateRemoteThreadEx 存在问题(该 dll 根本不注入)。该代码适用于不使用 Windows 8+ 的任何人。我想知道是否有人可以帮助我调试代码以使其在较新的操作系统上运行,并在可能的情况下解释为什么它不工作。这是我第一次研究c#,我主要用Java编程。

当我关注堆栈时,我知道它来自 Injector.cs 中的 InjectLibrary

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

程序.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上。

4

0 回答 0