Ejemplo n.º 1
0
        public int Run()
        {
            var engine = new HostedScriptEngine();
            var src    = new BinaryCodeSource();

            engine.SetGlobalEnvironment(this, src);

            try
            {
                ScriptModuleHandle module;
                engine.Initialize();

                using (var codeStream = LocateCode())
                    using (var binReader = new BinaryReader(codeStream))
                    {
                        var modulesCount = binReader.ReadInt32();

                        var reader = new ModulePersistor();

                        var entry = reader.Read(codeStream);
                        --modulesCount;

                        while (modulesCount-- > 0)
                        {
                            var userScript = reader.Read(codeStream);
                            engine.LoadUserScript(userScript);
                        }

                        module = entry.Module;
                    }

                var process = engine.CreateProcess(this, module, src);

                return(process.Start());
            }
            catch (ScriptInterruptionException e)
            {
                return(e.ExitCode);
            }
            catch (Exception e)
            {
                ShowExceptionInfo(e);
                return(1);
            }
        }
Ejemplo n.º 2
0
        public int Run()
        {
            if (_sourceStream == null && CommandLineArguments != null && CommandLineArguments.Length > 1)
            {
                var firstArg = CommandLineArguments[0];
                if (firstArg == "-loadDump")
                {
                    var path = CommandLineArguments[1];
                    CommandLineArguments = CommandLineArguments.Skip(2).ToArray();
                    using (var dumpStream = new FileStream(path, FileMode.Open))
                    {
                        _sourceStream = GetCodeStream(dumpStream);
                    }

                    Run(); //ну да, говнокод и лапша, время жмет
                }
            }

            if (_sourceStream == null)
            {
                _sourceStream = LocateCode();
            }

            var engine = new HostedScriptEngine();
            var src    = new BinaryCodeSource();

            engine.SetGlobalEnvironment(this, src);

            try
            {
                ModuleImage module;
                engine.Initialize();

                using (var binReader = new BinaryReader(_sourceStream))
                {
                    var modulesCount = binReader.ReadInt32();

                    var reader = new ModulePersistor();

                    var entry = reader.Read(_sourceStream);
                    --modulesCount;

                    while (modulesCount-- > 0)
                    {
                        var userScript = reader.Read(_sourceStream);
                        engine.LoadUserScript(userScript);
                    }

                    module = entry.Image;
                }

                var process = engine.CreateProcess(this, module, src);

                return(process.Start());
            }
            catch (ScriptInterruptionException e)
            {
                return(e.ExitCode);
            }
            catch (Exception e)
            {
                ShowExceptionInfo(e);
                return(1);
            }
        }