Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            int state = 0;
            string dll = string.Empty;
            string function = string.Empty;
            string args = string.Empty;
            bool silent = false;
            uint pid = 0;

            foreach (string a in e.Args)
            {
                string arg = a.ToLower();
                switch (state)
                {
                    case 0:
                        if (arg[0] != '-')
                            continue;
                        if (arg == "-inject")
                            state = 1;
                        else if (arg == "-function")
                            state = 2;
                        else if (arg == "-args")
                            state = 3;
                        else if (arg == "-pid")
                            state = 4;
                        else if (arg == "-silent")
                            silent = true;
                        break;

                    // DLL name
                    case 1:
                        dll = a; state = 0; break;

                    // function name
                    case 2:
                        function = a; state = 0; break;

                    // arguments
                    case 3:
                        args = a; state = 0; break;

                    case 4:
                        try { pid = uint.Parse(a); }
                        catch { }
                        state = 0;
                        break;

                    default: break;
                }
            }

            if (pid != 0 && dll != string.Empty)
            {
                InjectorLib injector = new InjectorLib();

                // For text output, in case we were launched from a command prompt.
                AttachConsole(0xffffffff);

                Console.WriteLine("Injecting '" + dll + "' into process " + pid);

                UInt32 retCode = 0;
                bool b = injector.InjectAndRun(pid, dll, function, args, ref retCode);

                if (b)
                {
                    Console.WriteLine("Successful!\nReturn value: " + retCode);
                    if (!silent) MessageBox.Show("DLL Injection Successful!\nReturn value: " + retCode);
                }
                else
                {
                    Console.WriteLine("Failed!");
                    if (!silent) MessageBox.Show("DLL Injection failed!");
                }

                this.Shutdown(12);
            }
        }
Exemplo n.º 3
0
        private void btnInject_Click(object sender, RoutedEventArgs e)
        {
            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;
            }

            uint pid = 0;
            try
            {
                ComboBoxItem cbi = (ComboBoxItem)comboBoxProcesses.SelectedItem;
                pid = uint.Parse(cbi.Tag.ToString());
            }
            catch
            {
                UpdateStatus("You must select a process to inject to");
                return;
            }

            UInt32 retCode = 0;
            bool b = lib.InjectAndRun(pid, 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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }