private bool ParseForReflection(string FilePath, string OutputBaseFileName) { //if (FilePath.EndsWith("Reflection\\Definitions.h")) // return false; if (reflectionGeneratorProcess == null) { if (!File.Exists(EnvironmentHelper.ReflectionToolPath)) { return(false); } reflectionGeneratorProcess = new CommandLineProcess(); reflectionGeneratorProcess.FilePath = EnvironmentHelper.ReflectionToolPath; } reflectionGeneratorProcess.Start("\"" + FilePath + "\" \"" + OutputBaseFileName + "\""); while (!reflectionGeneratorProcess.Output.EndOfStream) { reflectionGeneratorProcess.Output.ReadLine(); } return(reflectionGeneratorProcess.ExitCode == 0); }
public string Run() { this.State = GraderState.RUNNING; string output = CommandLineProcess.Run(System.IO.Path.Combine(this.WorkingDirectory, "output", "python"), "python game.py"); if (output == null) { this.State = GraderState.ERROR_TIMED_OUT; return(null); } else if (output.Contains("start.cry, Line:")) { this.State = GraderState.ERROR_RUNTIME; return(output); } else if (output.Contains("Traceback (most recent call last)") && output.Contains("MemoryError")) { this.State = GraderState.ERROR_MEMORY_EXCEEDED; return(null); } else { this.State = GraderState.DONE; } return(output); }
private bool ParseForWrapper(string FilePath, string OutputBaseFileName) { if (wrapperGeneratorProcess == null) { if (!File.Exists(EnvironmentHelper.WrapperToolPath)) { return(false); } wrapperGeneratorProcess = new CommandLineProcess(); wrapperGeneratorProcess.FilePath = EnvironmentHelper.WrapperToolPath; } wrapperGeneratorProcess.Start(SelectedRule.TargetName + EnvironmentHelper.DynamicLibraryExtentions + " " + BuildSystemHelper.GetAPIPreprocessorName(BuildRule.ModuleName) + " \"" + FilePath + "\" \"" + OutputBaseFileName + "\""); while (!wrapperGeneratorProcess.Output.EndOfStream) { wrapperGeneratorProcess.Output.ReadLine(); } return(wrapperGeneratorProcess.ExitCode == 0); }
private void CompileCrayonToPython() { Util.CreateFile(this.WorkingDirectory + "\\UserCode.build", string.Join("\n", "<build>", " <projectname>UserCode</projectname>", " <source>source/</source>", " <output>output/%TARGET_NAME%</output>", " <target name=\"python\">", " <platform>python</platform>", " </target>", "</build>")); Util.CreateFile(this.WorkingDirectory + "/source/start.cry", this.Code); string output = CommandLineProcess.Run( this.WorkingDirectory, "crayon " + this.WorkingDirectory + "\\UserCode.build -target python"); if (output.Length > 0) { this.State = GraderState.ERROR_COMPILE; } }
public string Run() { Util.CreateFile(this.WorkingDirectory + "\\run_me.py", this.Code); string output = CommandLineProcess.Run(this.WorkingDirectory, @"C:\Python34\python run_me.py"); if (output == null) { this.State = GraderState.ERROR_TIMED_OUT; return(null); } if (output.Contains("Traceback (most recent call last)") && output.Contains("MemoryError")) { this.State = GraderState.ERROR_MEMORY_EXCEEDED; return(null); } if (output.Contains("SyntaxError: invalid syntax")) { this.State = GraderState.ERROR_COMPILE; } return(output); }
private void CheckForBannedFunctions() { string wrapperName = Util.GetGibberishString(); List <string> wrappedCode = new List <string>() { "def " + wrapperName + "():" }; foreach (string line in this.Code.Split('\n')) { wrappedCode.Add(" " + line); } wrappedCode.AddRange(new string[] { "", "import dis", "", "dis.dis(" + wrapperName + ")" }); Util.CreateFile(this.WorkingDirectory + "\\banned_code_check.py", string.Join("\n", wrappedCode)); string output = CommandLineProcess.Run(this.WorkingDirectory, @"C:\Python34\python banned_code_check.py"); if (output.Contains("SyntaxError: invalid syntax") || output.Contains("File \"run_me.py\",")) { this.State = GraderState.ERROR_COMPILE; return; } foreach (string bannedItem in new string[] { "IMPORT_NAME", }) { if (output.Contains(bannedItem)) { this.State = GraderState.ERROR_BANNED_CODE; return; } } HashSet <string> allDefaultGlobals = new HashSet <string>(new string[] { // Copied directly from the output of dir() "__builtins__", "__doc__", "__loader__", "__name__", "__package__", "__spec__", // Copied directly from the output of __builtins__ "ArithmeticError", "AssertionError", "AttributeError", "BaseException", "BlockingIOError", "BrokenPipeError", "BufferError", "BytesWarning", "ChildProcessError", "ConnectionAbortedError", "ConnectionError", "ConnectionRefusedError", "ConnectionResetError", "DeprecationWarning", "EOFError", "Ellipsis", "EnvironmentError", "Exception", "False", "FileExistsError", "FileNotFoundError", "FloatingPointError", "FutureWarning", "GeneratorExit", "IOError", "ImportError", "ImportWarning", "IndentationError", "IndexError", "InterruptedError", "IsADirectoryError", "KeyError", "KeyboardInterrupt", "LookupError", "MemoryError", "NameError", "None", "NotADirectoryError", "NotImplemented", "NotImplementedError", "OSError", "OverflowError", "PendingDeprecationWarning", "PermissionError", "ProcessLookupError", "ReferenceError", "ResourceWarning", "RuntimeError", "RuntimeWarning", "StopIteration", "SyntaxError", "SyntaxWarning", "SystemError", "SystemExit", "TabError", "TimeoutError", "True", "TypeError", "UnboundLocalError", "UnicodeDecodeError", "UnicodeEncodeError", "UnicodeError", "UnicodeTranslateError", "UnicodeWarning", "UserWarning", "ValueError", "Warning", "WindowsError", "ZeroDivisionError", "_", "__build_class__", "__debug__", "__doc__", "__import__", "__loader__", "__name__", "__package__", "__spec__", "abs", "all", "any", "ascii", "bin", "bool", "bytearray", "bytes", "callable", "chr", "classmethod", "compile", "complex", "copyright", "credits", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "exec", "exit", "filter", "float", "format", "frozenset", "getattr", "globals", "hasattr", "hash", "help", "hex", "id", "input", "int", "isinstance", "issubclass", "iter", "len", "license", "list", "locals", "map", "max", "memoryview", "min", "next", "object", "oct", "open", "ord", "pow", "print", "property", "quit", "range", "repr", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "vars", "zip" }); HashSet <string> theWhiteList = new HashSet <string>(new string[] { "abs", "all", "any", "ascii", "bin", "bool", "bytearray", "bytes", "callable", "chr", "complex", "dict", "divmod", "enumerate", "filter", "float", "format", "frozenset", "hash", "hex", "id", "int", "isinstance", "issubclass", "iter", "len", "list", "map", "max", "min", "next", "object", "oct", "ord", "pow", "print", "property", "range", "repr", "reversed", "round", "set", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "zip" }); string[] lines = output.Split('\n'); HashSet <string> globalsLoaded = new HashSet <string>(); foreach (string line in lines) { string[] parts = line.Replace(")", "").Split('('); string arg = parts[parts.Length - 1].Trim(); if (line.Contains("LOAD_GLOBAL")) { if (allDefaultGlobals.Contains(arg) && !theWhiteList.Contains(arg)) { this.State = GraderState.ERROR_BANNED_CODE; return; } } else if (line.Contains("LOAD_ATTR")) { if (arg.StartsWith("__")) { this.State = GraderState.ERROR_BANNED_CODE; return; } } } }