Esempio n. 1
0
 public string LoadScript(string filename)
 {
     try
     {
         using (StreamReader sr = new StreamReader(filename))
         {
             StringBuilder fileContents = new StringBuilder();
             string        curLine;
             while ((curLine = sr.ReadLine()) != null)
             {
                 fileContents.Append(curLine + "\n");
             }
             return(fileContents.ToString());
         }
     }
     catch (Exception e)
     {
         string errorText = e.Message + "\n";
         pp = Process.GetCurrentProcess().Parent();
         PSConsole.stealConsole(pp);
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 2);
         Console.WriteLine(errorText);
         return("error");
     }
 }
Esempio n. 2
0
 public void usage()
 {
     pp = Process.GetCurrentProcess().Parent();
     PSConsole.stealConsole(pp);
     Console.CancelKeyPress += delegate {
         this.cleanup();
     };
     Console.SetCursorPosition(0, Console.CursorTop + 2);
     Console.WriteLine("Usage:");
     Console.WriteLine("rundll32 PowerShdll,main <script>");
     Console.WriteLine("rundll32 PowerShdll,main -f <path>\t Run the script passed as argument");
     Console.WriteLine("rundll32 PowerShdll,main -w\t Start an interactive console in a new window");
     Console.WriteLine("rundll32 PowerShdll,main -i\t Start an interactive console in this console");
 }
Esempio n. 3
0
 public void usage()
 {
     pp = Process.GetCurrentProcess().Parent();
     PSConsole.stealConsole(pp);
     Console.CancelKeyPress += delegate {
         this.cleanup();
     };
     Console.SetCursorPosition(0, Console.CursorTop + 2);
     Console.WriteLine("Usage:");
     Console.WriteLine("rundll32 PowerShdll,main <script>");
     Console.WriteLine("rundll32 PowerShdll,main -h\t Display this message");
     Console.WriteLine("rundll32 PowerShdll,main -f <path>\t Run the script passed as argument");
     Console.WriteLine("rundll32 PowerShdll,main -w\t Start an interactive console in a new window (Default)");
     Console.WriteLine("rundll32 PowerShdll,main -i\t Start an interactive console in this console");
     Console.WriteLine("\nIf you do not have an interractive console, use -n to avoid crashes on output");
 }
Esempio n. 4
0
 public void start(string[] args)
 {
     if (args[0] == "")
     {
         usage(); return;
     }
     else if (args[0] == "-h")
     {
         usage();
     }
     else if (args[0] == "-w")
     {
         PSConsole.getNewConsole();
         this.interact();
     }
     else if (args[0] == "-i")
     {
         pp = Process.GetCurrentProcess().Parent();
         pp.Suspend();
         PSConsole.stealConsole(pp);
         Console.Title           = "PowerShdll";
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 1);
         Console.WriteLine("Press Enter to get started:");
         Console.Write("\n");
         this.interact();
         ps.close();
         pp.Resume();
     }
     else if (args[0] == "-f")
     {
         if (args.Length < 2)
         {
             usage(); return;
         }
         pp = Process.GetCurrentProcess().Parent();
         PSConsole.stealConsole(pp);
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 1);
         string script = PowerShdll.LoadScript(args[1]);
         if (script != "error")
         {
             Console.Write(ps.exe(script));
         }
     }
     else
     {
         pp = Process.GetCurrentProcess().Parent();
         PSConsole.stealConsole(pp);
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 1);
         string script = string.Join(" ", args);
         Console.Write(ps.exe(script));
         ps.close();
     }
     return;
 }
Esempio n. 5
0
        public void start(string[] args)
        {
            int    i          = 0;
            bool   useConsole = true;
            string ret;

            if (args.Length == 0)
            {
                PSConsole.getNewConsole();
                this.interact();
            }
            if (args[i] == "-n")
            {
                i++;
                useConsole = false;
            }
            if (args[i] == "-h")
            {
                usage(); return;
            }
            else if (args[i] == "-w" || args[i] == "")
            {
                PSConsole.getNewConsole();
                this.interact();
            }
            else if (args[i] == "-i")
            {
                pp = Process.GetCurrentProcess().Parent();
                pp.Suspend();
                PSConsole.stealConsole(pp);
                Console.Title           = "PowerShdll";
                Console.CancelKeyPress += delegate
                {
                    this.cleanup();
                };
                Console.SetCursorPosition(0, Console.CursorTop + 1);
                Console.WriteLine("Press Enter to get started:");
                Console.Write("\n");
                this.interact();
                ps.close();
                pp.Resume();
            }
            else if (args[i] == "-f")
            {
                i++;
                if (args.Length < 2)
                {
                    usage(); return;
                }
                if (args[i] == "-n")
                {
                    if (args.Length < 3)
                    {
                        usage(); return;
                    }
                    i++;
                    useConsole = false;
                }
                string script = LoadScript(args[i]);
                if (script != "error")
                {
                    ret = ps.exe(script);
                    if (useConsole)
                    {
                        pp = Process.GetCurrentProcess().Parent();
                        PSConsole.stealConsole(pp);
                        Console.CancelKeyPress += delegate
                        {
                            this.cleanup();
                        };
                        Console.SetCursorPosition(0, Console.CursorTop + 1);
                        Console.WriteLine(ret);
                    }
                }
            }
            else
            {
                string script = string.Join(" ", args, i, args.Length - i);
                if (script[0] == '"' && script[script.Length - 1] == '"')
                {
                    script = script.Substring(1, script.Length - 2);
                }
                ret = ps.exe(script);
                if (useConsole)
                {
                    pp = Process.GetCurrentProcess().Parent();
                    PSConsole.stealConsole(pp);
                    Console.CancelKeyPress += delegate
                    {
                        this.cleanup();
                    };
                    Console.SetCursorPosition(0, Console.CursorTop + 1);
                    Console.WriteLine(ret);
                }
                ps.close();
            }
            return;
        }