1

So after looking around online, and debugging the code I found out that there are issues with using CreateRemoteThread and CreateRemoteThreadEx on windows 8, 8.1, and 10 (The dll does not inject at all). The code works fine for anyone who is not using windows 8+. I was wondering if anyone could help me debug the code in order for it to work on the newer operating system, and if possible to provide a explanation to why it is not working. This is the first time I looked into c#, I mainly program in Java.

While I was following the stack I know that it is coming from InjectLibrary in 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

I seemed to have surpassed the character limit, so I posted the code on pastebin.

Kendrick Lamar
  • 781
  • 2
  • 8
  • 18

0 Answers0