public override void Evaluate(string script) { var filename = this.Location.FilesystemPath; this.eventsAPI = Evaluate( outputWriter, eventListener, cfgSvc, fsSvc, script, filename); }
private static RekoEventsAPI Evaluate( TextWriter outputWriter, DecompilerEventListener eventListener, IConfigurationService cfgSvc, IFileSystemService fsSvc, string script, string filename) { var engine = CreateEngine(outputWriter); outputWriter.WriteLine($"Evaluating {filename}"); var pythonAPI = new PythonAPI(cfgSvc, fsSvc, engine); var eventsAPI = new RekoEventsAPI(engine); var scope = CreateRekoVariable(engine, pythonAPI, eventsAPI); var src = engine.CreateScriptSourceFromString(script, filename); try { src.Execute(scope); } catch (Exception ex) { var scriptError = CreateError( filename, ex, "An error occurred while evaluating the Python script.", engine); eventListener.Error(scriptError); DumpPythonStack(outputWriter, ex, engine); return(new RekoEventsAPI(engine)); } return(eventsAPI); }
private static ScriptScope CreateRekoVariable( ScriptEngine engine, PythonAPI pythonAPI, RekoEventsAPI eventsAPI) { var scope = engine.CreateScope(); var rekoWrapper = pythonAPI.CreateRekoWrapper(eventsAPI); scope.SetVariable("reko", rekoWrapper); return(scope); }
public PythonModule( IServiceProvider services, string filename, byte[] bytes) : base(services, filename, bytes) { this.eventListener = services.RequireService <DecompilerEventListener>(); this.engine = IronPython.Hosting.Python.CreateEngine(); // $TODO: Redirect script output to Reko Console tab engine.Runtime.IO.RedirectToConsole(); this.pythonAPI = new PythonAPI(services, engine); var stream = new MemoryStream(bytes); using var rdr = new StreamReader(stream); this.eventsAPI = Evaluate(rdr.ReadToEnd(), filename); }
public PythonModule( IServiceProvider services, string filename, byte[] bytes) : base(services, filename, bytes) { this.eventListener = services.RequireService <DecompilerEventListener>(); this.engine = IronPython.Hosting.Python.CreateEngine(); var outputService = services.RequireService <IOutputService>(); this.outputWriter = outputService.EnsureOutputSource("Scripting"); RedirectConsoleOutput(outputWriter, engine); this.pythonAPI = new PythonAPI(services, engine); var stream = new MemoryStream(bytes); using var rdr = new StreamReader(stream); this.eventsAPI = Evaluate(rdr.ReadToEnd(), filename); }
public PythonModule( IServiceProvider services, string filename, byte[] bytes) : base(services, filename, bytes) { this.eventListener = services.RequireService <DecompilerEventListener>(); this.cfgSvc = services.RequireService <IConfigurationService>(); this.fsSvc = services.RequireService <IFileSystemService>(); var outputService = services.RequireService <IOutputService>(); this.outputWriter = outputService.EnsureOutputSource("Scripting"); var stream = new MemoryStream(bytes); using var rdr = new StreamReader(stream); this.eventsAPI = Evaluate( outputWriter, eventListener, cfgSvc, fsSvc, rdr.ReadToEnd(), filename); }
private RekoEventsAPI Evaluate(string script, string filename) { var eventsAPI = new RekoEventsAPI(); var scope = CreateRekoVariable(engine, pythonAPI, eventsAPI); var src = engine.CreateScriptSourceFromString(script, filename); try { src.Execute(scope); } catch (Exception ex) { eventListener.Error( new NullCodeLocation(filename), ex, "An error occurred while evaluating the Python script."); DumpPythonStack(ex, engine); return(new RekoEventsAPI()); } return(eventsAPI); }
public PythonModule(IServiceProvider services, ImageLocation scriptLocation, byte[] bytes) : base(services, scriptLocation, bytes) { if (scriptLocation.HasFragments) { throw new NotSupportedException("Loading scripts inside archives is not supported yet."); } var filename = scriptLocation.FilesystemPath; this.eventListener = services.RequireService <DecompilerEventListener>(); this.cfgSvc = services.RequireService <IConfigurationService>(); this.fsSvc = services.RequireService <IFileSystemService>(); var outputService = services.RequireService <IOutputService>(); this.outputWriter = outputService.EnsureOutputSource("Scripting"); var stream = new MemoryStream(bytes); using var rdr = new StreamReader(stream); this.eventsAPI = Evaluate( outputWriter, eventListener, cfgSvc, fsSvc, rdr.ReadToEnd(), filename); }
public override void Evaluate(string script) { this.eventsAPI = Evaluate( outputWriter, eventListener, cfgSvc, fsSvc, script, Filename); }