Exemple #1
0
            public ReplBackend(ReplProcessor replProcessor, JSession jSession)
            {
                this._replProc = replProcessor;
                this._COMMANDS = new Dictionary <string, Action>()
                {
                    { "run ", this.CmdRun },
                    { "abrt", this.CmdAbrt },
                    { "exit", this.CmdExit },
                    { "mems", this.CmdMems },
                    { "sigs", this.CmdSigs },
                    { "locs", this.CmdLocs },
                    { "setl", this.CmdSetl },
                    { "sett", this.CmdSett },
                    { "inpl", this.CmdInpl },
                    { "excf", this.CmdExcf },
                    { "dbga", this.CmdDebugAttach }
                };
                this._jSession = jSession;
                this._disposed = false;

                this._conn        = null;
                this._stream      = null;
                this._sendLocker  = new object();
                this._inputLocker = new object();
                this._inputEvent  = new InputLock(this); // lock starts acquired (we use it like a manual reset event)

                this._inputString   = null;
                this._exitRequested = false;
            }
Exemple #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         _jSession = new JSession();
         _jSession.SetStringOutput((type, output) =>
         {
             if (null != output)
             {
                 this.textBox2.Text += output.Replace("\n", "\r\n");
                 this.textBox2.SelectionStart = this.textBox2.Text.Length;
                 this.textBox2.ScrollToCaret();
             }
         });
         _jSession.SetInput((p) =>
         {
             this._form2.ShowDialog();
             var result = this._form2.textBox1.Text;
             this.textBox2.Text += result + "\r\n";
             this.textBox2.SelectionStart = this.textBox2.Text.Length;
             this.textBox2.ScrollToCaret();
             return result;
         });
         _jSession.ApplyCallbacks();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #3
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         _jSession = new JSession();
         _jSession.SetStringOutput((type, output) =>
         {
             if (null != output)
             {
                 this.textBox2.Text          += output.Replace("\n", "\r\n");
                 this.textBox2.SelectionStart = this.textBox2.Text.Length;
                 this.textBox2.ScrollToCaret();
             }
         });
         _jSession.SetInput((p) =>
         {
             this._form2.ShowDialog();
             var result                   = this._form2.textBox1.Text;
             this.textBox2.Text          += result + "\r\n";
             this.textBox2.SelectionStart = this.textBox2.Text.Length;
             this.textBox2.ScrollToCaret();
             return(result);
         });
         _jSession.ApplyCallbacks();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #4
0
            internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession, string locale)
                : base(replProcessor, jSession)
            {
                this._executeItemLocker = new object();

                if (null != locale && string.Empty != locale.Trim())
                {
                    this._jSession.Do(string.Format("18!:4 <'{0}'", locale));
                }
                this._executeItemLock = new ExecuteItemLock(this); // lock starts acquired (we use it like manual reset event)
            }
Exemple #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (BaseUi.token == "" || JSession.GetStr("login") == "")
         {
             base.Response.Redirect("/p/login");
             return;
         }
         lnksh1.Href = BaseUi.CoreCssPath + "/style.css";
     }
 }
Exemple #6
0
 internal static void Run(CmdLineOptions cmdLineOptions, JSession jSession)
 {
     try
     {
         new ReplProcessor(cmdLineOptions).RunRepl(jSession);
     }
     catch (Exception ex)
     {
         if (ReplProcessor._isDebug)
         {
             System.Console.WriteLine(ex.ToString());
         }
         throw;
     }
 }
Exemple #7
0
 internal static void Run(CmdLineOptions cmdLineOptions, JSession jSession)
 {
     try
     {
         new ReplProcessor(cmdLineOptions).RunRepl(jSession);
     }
     catch (Exception ex)
     {
         if (ReplProcessor._isDebug)
         {
             System.Console.WriteLine(ex.ToString());
         }
         throw;
     }
 }
Exemple #8
0
        private void RunRepl(JSession jSession)
        {
            BasicReplBackend backendType  = null;
            string           backendError = null;

            if (null != this._cmdLine.Backend && !this._cmdLine.Backend.Equals("standard", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    backendType = (BasicReplBackend)Activator.CreateInstance(Type.GetType(this._cmdLine.Backend), this, jSession);
                }
                catch (UnsupportedReplException ex)
                {
                    backendError = ex.Reason;
                }
                catch (Exception ex)
                {
                    backendError = ex.Message;
                }
            }
            if (null == backendType)
            {
                backendType = new BasicReplBackend(this, jSession);
            }
            using (backendType)
            {
                backendType.Connect();
                if (this._cmdLine.EnableAttach)
                {
                    backendType.InitDebugger();
                }

                if (null != backendError)
                {
                    System.Console.Error.WriteLine("Error using selected REPL back-end:");
                    System.Console.Error.WriteLine(backendError);
                    System.Console.Error.WriteLine("Using standard backend instead.");
                }
                backendType.ExecutionLoop();
            }
        }
Exemple #9
0
        private static int Main(string[] argv)
        {
            try
            {
                System.Console.InputEncoding  = (5 == Environment.OSVersion.Version.Major) ? Encoding.UTF8 : Encoding.Unicode;
                System.Console.OutputEncoding = Encoding.UTF8;
                _programName = JSession.ProgramName;
                _options     = new CmdLineOptions();

                bool showHelp  = false;
                bool isServer  = false;
                var  optionSet = new OptionSet()
                {
                    { "p|port:", "{PORT} to listen to. Multiple ports are supported.", (ushort v) => { _options.Ports.Add(v); isServer = true; } },
                    { "i|interactive", "Interactive session. Use -i- to turn off.", v => _options.Interactive = v != null },
                    { "l|loopback", "Listen on loopback. Use -l- to use network.\n", v => _options.Loopback = v != null },
                    { "h|help", "Show this message and exit.", v => showHelp = v != null }
                };

                try
                {
                    _options.JOptions = optionSet.Parse(argv).ToArray();
                    if (showHelp)
                    {
                        ShowHelp(optionSet);
                        return(0);
                    }
                    if ((!_options.Interactive || !_options.Loopback) && _options.Ports.Count < 1)
                    {
                        throw new Exception(string.Format("Missing PORT for server session."));
                    }
                }
                catch (Exception ex)
                {
                    System.Console.Error.WriteLine();
                    System.Console.Error.Write(string.Format("{0}: ", _programName));
                    System.Console.Error.WriteLine(ex.Message);
                    System.Console.Error.WriteLine(string.Format("Try '{0} --help' for more information.", _programName));
                    return(1);
                }
                using (_jSession = new JSession(_options.JOptions))
                {
                    System.Console.CancelKeyPress += (sender, e) =>
                    {
                        e.Cancel = true;
                        _jSession.IncAdBreak();
                    };
                    _jSession.SetType(JSession.SMCON);
                    if (!isServer) // normal interactive console read/write to standard streams.
                    {
                        _jSession.SetStringOutput((tp, s) =>
                        {
                            if (JSession.MTYOEXIT == tp)
                            {
                                Environment.Exit(tp);
                            }
                            System.Console.Out.Write(s); System.Console.Out.Flush();
                        });
                        _jSession.SetDoWd(Parser.Parse);
                        _jSession.SetInput(JInput);
                        _jSession.ApplyCallbacks();
                    }
                    if (isServer)
                    {
                        var threadCount = _options.Interactive ? _options.Ports.Count : _options.Ports.Count - 1;
                        for (int i = 0; i < threadCount; i++)
                        {
                            ServerProc(_options.Ports[i]);
                        }
                        if (!_options.Interactive) // use main thread
                        {
                            ServerProc(_options.Ports[threadCount]);
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            _jSession.Do(JInput("   "));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.ToString());
                if (!IsConsoleInputRedirected())
                {
                    System.Console.Error.Write("Press any key to continue... ");
                    System.Console.ReadKey();
                }
                return(1);
            }
            return(0);
        }
Exemple #10
0
            public ReplBackend(ReplProcessor replProcessor, JSession jSession)
            {
                this._replProc = replProcessor;
                this._COMMANDS = new Dictionary<string, Action>()
                {
                    { "run ", this.CmdRun },
                    { "abrt", this.CmdAbrt },
                    { "exit", this.CmdExit },
                    { "mems", this.CmdMems },
                    { "sigs", this.CmdSigs },
                    { "locs", this.CmdLocs },
                    { "setl", this.CmdSetl },
                    { "sett", this.CmdSett },
                    { "inpl", this.CmdInpl },
                    { "excf", this.CmdExcf },
                    { "dbga", this.CmdDebugAttach }
                };
                this._jSession = jSession;
                this._disposed = false;

                this._conn = null;
                this._stream = null;
                this._sendLocker = new object();
                this._inputLocker = new object();
                this._inputEvent = new InputLock(this); // lock starts acquired (we use it like a manual reset event)

                this._inputString = null;
                this._exitRequested = false;
            }
Exemple #11
0
            internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession, string locale)
                : base(replProcessor, jSession)
            {
                this._executeItemLocker = new object();

                if (null != locale && string.Empty != locale.Trim())
                {
                    this._jSession.Do(string.Format("18!:4 <'{0}'", locale));
                }
                this._executeItemLock = new ExecuteItemLock(this); // lock starts acquired (we use it like manual reset event)
            }
Exemple #12
0
 internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession)
     : this(replProcessor, jSession, null)
 {
 }
Exemple #13
0
        private void RunRepl(JSession jSession)
        {
            BasicReplBackend backendType = null;
            string backendError = null;
            if (null != this._cmdLine.Backend && !this._cmdLine.Backend.Equals("standard", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    backendType = (BasicReplBackend)Activator.CreateInstance(Type.GetType(this._cmdLine.Backend), this, jSession);
                }
                catch (UnsupportedReplException ex)
                {
                    backendError = ex.Reason;
                }
                catch (Exception ex)
                {
                    backendError = ex.Message;
                }
            }
            if (null == backendType)
            {
                backendType = new BasicReplBackend(this, jSession);
            }
            using (backendType)
            {
                backendType.Connect();
                if (this._cmdLine.EnableAttach)
                {
                    backendType.InitDebugger();
                }

                if (null != backendError)
                {
                    System.Console.Error.WriteLine("Error using selected REPL back-end:");
                    System.Console.Error.WriteLine(backendError);
                    System.Console.Error.WriteLine("Using standard backend instead.");
                }
                backendType.ExecutionLoop();
            }
        }
Exemple #14
0
        static int Main(string[] args)
        {
            _programName = JSession.ProgramName;
            _options = new CmdLineOptions();

            bool showHelp = false;
            var optionSet = new OptionSet()
            {
                { "p|port=", "{PORT} to connect to.", (ushort v) => _options.Port = v },
                { "s|server:", "Repl {SERVER} to connect to. Default is 127.0.0.1.", v => _options.Server = v },
                { "f|launch_file:", "{SCRIPT} file to run on startup.", v => _options.LaunchFile = v },
                { "m|mode:", "Interactive {MODE} to use. Defaults to Standard.", v => _options.Backend = v },
                { "a|enable-attach", "Enable attaching the debugger via )attach.\n", v => _options.EnableAttach = v != null },
                { "h|help",  "Show this message and exit.", v => showHelp = v != null }
            };

            try
            {
                _options.JOptions = optionSet.Parse(args).ToArray();
                if (showHelp)
                {
                    ShowHelp(optionSet);
                    return 0;
                }
                if (_options.Port < 1)
                {
                    throw new Exception(string.Format("Missing PORT for repl processor client session."));
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.Message);
                System.Console.Error.WriteLine(string.Format("Try '{0} --help' for more information.", _programName));
                return 1;
            }

            try
            {
                using (_jSession = new JSession(_options.JOptions))
                {
                    System.Console.CancelKeyPress += (sender, e) =>
                    {
                        e.Cancel = true;
                        _jSession.IncAdBreak();
                    };
                    _jSession.SetType(JSession.SMCON);
                    throw new NotImplementedException();
                    ReplProcessor.Run(_options, _jSession);
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.ToString());
                return 1;
            }
            return 0;
        }
Exemple #15
0
        static int Main(string[] args)
        {
            _programName = JSession.ProgramName;
            _options     = new CmdLineOptions();

            bool showHelp  = false;
            var  optionSet = new OptionSet()
            {
                { "p|port=", "{PORT} to connect to.", (ushort v) => _options.Port = v },
                { "s|server:", "Repl {SERVER} to connect to. Default is 127.0.0.1.", v => _options.Server = v },
                { "f|launch_file:", "{SCRIPT} file to run on startup.", v => _options.LaunchFile = v },
                { "m|mode:", "Interactive {MODE} to use. Defaults to Standard.", v => _options.Backend = v },
                { "a|enable-attach", "Enable attaching the debugger via )attach.\n", v => _options.EnableAttach = v != null },
                { "h|help", "Show this message and exit.", v => showHelp = v != null }
            };

            try
            {
                _options.JOptions = optionSet.Parse(args).ToArray();
                if (showHelp)
                {
                    ShowHelp(optionSet);
                    return(0);
                }
                if (_options.Port < 1)
                {
                    throw new Exception(string.Format("Missing PORT for repl processor client session."));
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.Message);
                System.Console.Error.WriteLine(string.Format("Try '{0} --help' for more information.", _programName));
                return(1);
            }

            try
            {
                using (_jSession = new JSession(_options.JOptions))
                {
                    System.Console.CancelKeyPress += (sender, e) =>
                    {
                        e.Cancel = true;
                        _jSession.IncAdBreak();
                    };
                    _jSession.SetType(JSession.SMCON);
                    throw new NotImplementedException();
                    ReplProcessor.Run(_options, _jSession);
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.ToString());
                return(1);
            }
            return(0);
        }
Exemple #16
0
        private static int Main(string[] argv)
        {
            try
            {
                System.Console.InputEncoding = (5 == Environment.OSVersion.Version.Major) ? Encoding.UTF8 : Encoding.Unicode;
                System.Console.OutputEncoding = Encoding.UTF8;
                _programName = JSession.ProgramName;
                _options = new CmdLineOptions();

                bool showHelp = false;
                bool isServer = false;
                var optionSet = new OptionSet()
                {
                    { "p|port:", "{PORT} to listen to. Multiple ports are supported.", (ushort v) => { _options.Ports.Add(v); isServer = true; } },
                    { "i|interactive", "Interactive session. Use -i- to turn off.", v => _options.Interactive = v != null },
                    { "l|loopback", "Listen on loopback. Use -l- to use network.\n", v => _options.Loopback = v != null },
                    { "h|help",  "Show this message and exit.", v => showHelp = v != null }
                };

                try
                {
                    _options.JOptions = optionSet.Parse(argv).ToArray();
                    if (showHelp)
                    {
                        ShowHelp(optionSet);
                        return 0;
                    }
                    if ((!_options.Interactive || !_options.Loopback) && _options.Ports.Count < 1)
                    {
                        throw new Exception(string.Format("Missing PORT for server session."));
                    }
                }
                catch (Exception ex)
                {
                    System.Console.Error.WriteLine();
                    System.Console.Error.Write(string.Format("{0}: ", _programName));
                    System.Console.Error.WriteLine(ex.Message);
                    System.Console.Error.WriteLine(string.Format("Try '{0} --help' for more information.", _programName));
                    return 1;
                }
                using (_jSession = new JSession(_options.JOptions))
                {
                    System.Console.CancelKeyPress += (sender, e) =>
                    {
                        e.Cancel = true;
                        _jSession.IncAdBreak();
                    };
                    _jSession.SetType(JSession.SMCON);
                    if (!isServer) // normal interactive console read/write to standard streams.
                    {
                        _jSession.SetStringOutput((tp, s) =>
                        {
                            if (JSession.MTYOEXIT == tp) Environment.Exit(tp);
                            System.Console.Out.Write(s); System.Console.Out.Flush();
                        });
                        _jSession.SetDoWd(Parser.Parse);
                        _jSession.SetInput(JInput);
                        _jSession.ApplyCallbacks();
                    }
                    if (isServer)
                    {
                        var threadCount = _options.Interactive ? _options.Ports.Count : _options.Ports.Count - 1;
                        for (int i = 0; i < threadCount; i++)
                        {
                            ServerProc(_options.Ports[i]);
                        }
                        if (!_options.Interactive) // use main thread
                        {
                            ServerProc(_options.Ports[threadCount]);
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            _jSession.Do(JInput("   "));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.ToString());
                if (!IsConsoleInputRedirected())
                {
                    System.Console.Error.Write("Press any key to continue... ");
                    System.Console.ReadKey();
                }
                return 1;
            }
            return 0;
        }
Exemple #17
0
        private static SessionInfo GenerateSessionInfo(Session isession)
        {
            var session = new JSession(isession);
            var timers  = new SessionInfoTimers
            {
                ClientConnected           = isession.Timers.ClientConnected,
                ClientBeginRequest        = isession.Timers.ClientBeginRequest,
                FiddlerGotRequestHeaders  = isession.Timers.FiddlerGotRequestHeaders,
                ClientDoneRequest         = isession.Timers.ClientDoneRequest,
                ServerConnected           = isession.Timers.ServerConnected,
                FiddlerBeginRequest       = isession.Timers.FiddlerBeginRequest,
                ServerGotRequest          = isession.Timers.ServerGotRequest,
                ServerBeginResponse       = isession.Timers.ServerBeginResponse,
                FiddlerGotResponseHeaders = isession.Timers.FiddlerGotResponseHeaders,
                ServerDoneResponse        = isession.Timers.ServerDoneResponse,
                ClientBeginResponse       = isession.Timers.ClientBeginResponse,
                ClientDoneResponse        = isession.Timers.ClientDoneResponse,
                GatewayDeterminationTime  = isession.Timers.GatewayDeterminationTime,
                DNSTime            = isession.Timers.DNSTime,
                TCPConnectTime     = isession.Timers.TCPConnectTime,
                HTTPSHandshakeTime = isession.Timers.HTTPSHandshakeTime
            };

            return(new SessionInfo
            {
                Id = session.Id,
                Url = session.FullUrl,
                Timers = timers,
                IsBufferResponse = session.IsBufferResponse,
                Tag = session.Tag,
                Method = session.Method,
                IsHTTPS = session.IsHTTPS,
                LocalProcessID = session.LocalProcessID,
                LocalProcess = session.LocalProcess,
                SuggestedFilename = session.SuggestedFilename,
                BypassGateway = session.BypassGateway,
                ClientPort = session.ClientPort,
                PathAndQuery = session.PathAndQuery,
                FullUrl = session.FullUrl,
                Host = session.Host,
                Hostname = session.Hostname,
                Port = session.Port,
                ClientIP = session.ClientIP,
                ResponseCode = session.ResponseCode,
                HasWebSocketMessages = session.HasWebSocketMessages,
                HasResponse = session.HasResponse,
                BitFlags = session.BitFlags,
                IsTunnel = session.IsTunnel,
                TunnelIsOpen = session.TunnelIsOpen,
                TunnelIngressByteCount = session.TunnelIngressByteCount,
                TunnelEgressByteCount = session.TunnelEgressByteCount,
                IsFTP = session.IsFTP,
                RequestBodyEncoding = session.RequestBodyEncoding,
                ResponseBodyEncoding = session.ResponseBodyEncoding,
                State = session.State,
                UriScheme = session.UriScheme,
                Return = session.Return,
                UriUserInfo = session.UriUserInfo,
                RequestPath = session.RequestPath,
                GetHttpResponseStatus = session.GetHttpResponseStatus,
                GetStatusDescription = session.GetStatusDescription,
                RequesetBody = session.GetRequestBodyAsString(),
                UrlParam = session.UrlParam,
                RequestHeaders = session.RequestHeaders,
                ResponseHeaders = session.ResponseHeaders
            });
        }
Exemple #18
0
 internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession)
     : this(replProcessor, jSession, null)
 {
 }