コード例 #1
0
ファイル: Program.cs プロジェクト: Grafalck/Questor
        private static void Main(string[] args)
        {
            var options = new Options();
            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            // ReadKey() is there for debugging.
            if (parser.ParseArgumentsStrict(args, options, () => { Console.ReadKey();  Environment.Exit(-2); }))
            {
                Console.WriteLine("inject: {0}", options.InputFile);
                Console.WriteLine("function: {0}", options.FuncName);
                Console.WriteLine("args: {0}", options.FuncArgs);
                Console.WriteLine("pid: {0}", options.ProcID);
                Console.WriteLine("name: {0}", options.ProcName);
                Console.WriteLine("launch: {0}", options.ProcLaunch);

                InjectorLib injector = new InjectorLib();
                bool injected = false;
                UInt32 retCode = 0;
                if( !string.IsNullOrWhiteSpace(options.ProcName) )
                {
                    Process[] procs = Process.GetProcessesByName(options.ProcName);
                    foreach (Process proc in procs)
                    {
                        Console.WriteLine("Injecting '{0}' into process {1}", options.InputFile, proc.Id);
                        injected = injector.InjectAndRun((UInt32)proc.Id, options.InputFile, options.FuncName, options.FuncArgs, ref retCode);
                    }
                }
                else if( options.ProcID != 0 )
                {
                    Console.WriteLine("Injecting '{0}' into process {1}", options.InputFile, options.ProcID);
                    injected = injector.InjectAndRun(options.ProcID, options.InputFile, options.FuncName, options.FuncArgs, ref retCode);
                }
                else if( !string.IsNullOrWhiteSpace(options.ProcLaunch) )
                {
                    Console.WriteLine("Launching '{0}' and injecting '{1}'", options.ProcLaunch, options.InputFile);
                    injected = injector.LaunchAndInject(options.ProcLaunch, options.InputFile, options.FuncName, options.FuncArgs, ref retCode);
                }
                Environment.Exit(injected ? 0 : -1);
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Grafalck/Questor
        private void btnLaunch_Click(object sender, RoutedEventArgs e)
        {
            string exe = textBoxProcess.Text.Trim();
            string dll = textBoxDLL.Text.Trim();
            string func = textBoxFunction.Text.Trim();
            string args = textBoxArguments.Text.Trim();

            if (dll == string.Empty || !File.Exists(dll))
            {
                UpdateStatus("You must select a dll to inject");
                return;
            }

            InjectorLib lib = new InjectorLib();
            bool isManaged = lib.IsDllManaged(dll) == 1;
            if (isManaged && func == string.Empty)
            {
                UpdateStatus("You must specify a class method when injecting managed DLLs", false);
                return;
            }

            if (isManaged && !func.Contains('.'))
            {
                UpdateStatus("Class method should be in the form of 'namespace.classname.methodname'");
                return;
            }

            if (exe == string.Empty)
            {
                UpdateStatus("You must select an exe file to launch");
                return;
            }

            UInt32 retCode = 0;
            bool b = lib.LaunchAndInject(exe, dll, func, args, ref retCode);

            if (!b)
            {
                // See InjectorLib sources to understand what the error codes mean..
                UpdateStatus("Injection failed. Error code " + retCode);
            }
            else
            {
                UpdateStatus("Injection successful. Return value: " + retCode, false);
            }
        }