Exemple #1
0
        public ConsoleWindow(AugmentrexContext context)
        {
            context.Info("Allocating game console window... ");

            if (Kernel32.AllocConsole())
            {
                context.SuccessLine("OK.");

                var asmName = Assembly.GetExecutingAssembly().GetName();

                Console.Title = $"{asmName.Name} {asmName.Version} - Game Process";
            }
            else
            {
                context.WarningLine("{0}.", Win32.GetLastError());
            }
        }
Exemple #2
0
        public DebugListener(AugmentrexContext context)
        {
            context.InfoLine("Starting debug message listener...");

            _cts  = new CancellationTokenSource();
            _task = Task.Factory.StartNew(() =>
            {
                const int BufferSize = 4096;

                using var mmf       = MemoryMappedFile.CreateNew("DBWIN_BUFFER", BufferSize);
                using var bufReady  = new EventWaitHandle(false, EventResetMode.AutoReset, "DBWIN_BUFFER_READY");
                using var dataReady = new EventWaitHandle(false, EventResetMode.AutoReset, "DBWIN_DATA_READY");

                while (true)
                {
                    _cts.Token.ThrowIfCancellationRequested();

                    bufReady.Set();

                    if (!dataReady.WaitOne(context.Configuration.DebugListenerInterval))
                    {
                        continue;
                    }

                    using var stream = mmf.CreateViewStream(0, BufferSize, MemoryMappedFileAccess.Read);
                    using var reader = new BinaryReader(stream);

                    if (reader.ReadUInt32() != context.Game.Id)
                    {
                        continue;
                    }

                    var bytes = reader.ReadBytes(BufferSize - sizeof(int));
                    var str   = Encoding.GetEncoding("euc-kr").GetString(bytes, 0, Array.IndexOf <byte>(bytes, 0));

                    Log.DebugLine("{0}", str.Substring(0, str.Length - 1));
                }
            }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
Exemple #3
0
        public void Run(RemoteHooking.IContext context, string channelName)
        {
            AugmentrexContext ctx = null;

            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                ctx?.Line();
                ctx?.ErrorLine("Injected assembly crashed: {0}", e.ExceptionObject);
            };

            ctx = new AugmentrexContext(false, Process.GetProcessById(context.HostPID), Process.GetCurrentProcess(), channelName, null);

            try
            {
                var mod  = ctx.Game.MainModule;
                var addr = (MemoryAddress)mod.BaseAddress;
                var size = mod.ModuleMemorySize;

                ctx.Info("Making main module ({0}..{1}) writable... ", addr, addr + (MemoryOffset)size);

                if (Kernel32.VirtualProtectEx(ctx.Game.Handle, addr, size, Kernel32.MEM_PROTECTION.PAGE_EXECUTE_READWRITE, out var _))
                {
                    ctx.SuccessLine("OK.");
                }
                else
                {
                    ctx.WarningLine("{0}.", Win32.GetLastError());
                }

                ctx.InfoLine("Waking up process... ");

                RemoteHooking.WakeUpProcess();

                PluginManager.LoadPlugins(ctx);
                CommandInterpreter.LoadCommands(false);

                var rc     = ctx.Configuration.RunCommands;
                var interp = ctx.Interpreter;

                if (rc.Length != 0)
                {
                    ctx.InfoLine("Running startup commands...");

                    foreach (var cmd in rc)
                    {
                        interp.RunCommand(cmd, false);
                    }
                }

                ctx.SuccessLine("Injection completed successfully. Type 'help' for a list of commands.");
                ctx.Line();

                interp.RunLoop();
            }
            finally
            {
                PluginManager.UnloadPlugins();

                if (ctx is IDisposable disp)
                {
                    disp.Dispose();
                }
            }
        }