注入代码的问题

时间:2015-11-16 03:12:51

标签: c# windows-8 windows-10 dll-injection createremotethread

因此,在线查看并调试代码后,我发现在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);

的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 个答案:

没有答案