Ejemplo n.º 1
0
 public TaskManager(RepeatClient client)
 {
     this.client   = client;
     this.compiler = new CSCompiler(".");
     actions       = new Dictionary <string, UserDefinedAction>();
     emptyAction   = new EmptyAction("");
 }
Ejemplo n.º 2
0
        public void Compile_with_errors()
        {
            var csSource = new Sourcecode
            {
                Filename = "program_with_errors.cs",
                Text     = @"using System
public class Program {
  public static void Main(string[] args) {
    #region main
var answer == 42
Console.WriteLine(answer);
    #endregion
  }
}
".Split('\n')
            };

            csrun.data.domain.CompilerError[] result = null;
            CSCompiler.Compile(csSource,
                               null,
                               errors => result = errors.ToArray());

            foreach (var err in result)
            {
                Console.WriteLine($"{err.Filename}-{err.LineNumber},{err.ColumnNumber}: {err.Description}");
            }

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(2, result[0].LineNumber);
            Assert.AreEqual(5, result[1].LineNumber);
        }
Ejemplo n.º 3
0
        // Functionality methods

        private void TestMet1()
        {
            if (structureViever.SelectedNode == null)
            {
                return;
            }
            TypeDefinition TypDef = structureViever.SelectedNode.Tag as TypeDefinition;

            if (TypDef == null)
            {
                return;
            }

            string     test = @"using System.Windows.Forms;
							namespace DefNamSp
							{
							  public class DefClass
							  {
								public void DefFunc()
								{
									MessageBox.Show(""Message Successfuly Injected"");
								}
							  }
							}"                            ;
            CSCompiler csc  = new CSCompiler(dataStruct.AssemblyDefinition);

            csc.Code = test;
            MethodDefinition md = csc.GetMethodDefinition(string.Empty, string.Empty);

            if (md == null)
            {
                return;
            }
            TypeDefinition tdret = (TypeDefinition)dataStruct.ILNodeManager.FindMemberByPath("-.System.Void");

            if (tdret == null)
            {
                return;
            }
            MethodDefinition md2 = new MethodDefinition("blub", MethodAttributes.Public, tdret);

            TypDef.Methods.Add(md2);

            CecilHelper.CloneMethodBody(md, md2);

            using (SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Title = "Save to :",
                Filter = "Executables | *.exe;*.dll"
            })
            {
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    dataStruct.AssemblyDefinition.MainModule.Runtime = TargetRuntime.Net_4_0;
                    dataStruct.AssemblyDefinition.Write(saveFileDialog.FileName);
                    MessageBox.Show("Message Successfuly Injected");
                }
            }
        }
Ejemplo n.º 4
0
        private void ExecuteOnce()
        {
            var csSource = Transpile(_cmd.SourceFilename);

            _reEval = new ResultEvaluation(csSource, _resultLog);
            CSCompiler.Compile(csSource,
                               onSuccess: Run,
                               onFailure: _reEval.HandleCompilerErrors
                               );
        }
Ejemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            int    error   = 0;
            string message = string.Empty;
            var    cpr     = CSCompiler.Compile(textBox1.Text, "aaa.dll", out error, out message);

            if (error != 0)
            {
                textBox2.Text = message;
            }

            object obj1 = CSCompiler.CreateObject(cpr, "WpfApplication1.NS", null, 0);
            //object obj2 = CSCompiler.CreateObject(cpr, "test.CTObservableCollection", null, 0);
        }
Ejemplo n.º 6
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var cs      = new ComputeShader(GraphicsDevice, CSCompiler.Compile("sample.compute"));
            var surface = new ComputeTexture2D(GraphicsDevice, 1024, 1024, false, SurfaceFormat.Color);

            cs.SetRWTexture(0, surface);
            cs.Dispatch("Main", 32, 32, 1);
            surface.Texture.SaveAsJpeg(File.Create("file.jpg"), 1024, 1024);

            cs.Dispatch("Main2", 32, 32, 1);
            surface.Texture.SaveAsJpeg(File.Create("file1.jpg"), 1024, 1024);
            // TODO: use this.Content to load your game content here
        }
Ejemplo n.º 7
0
        internal ScriptSession(String applicationType, Boolean personalizedSettings, String contextWebsite = "website", Boolean onlyBuild = false)
        {
            ApplicationType = applicationType;

            this.Output = new OutputBuffer();

            this.OnlyBuildCode = onlyBuild;

            this.ContextWebsite = contextWebsite;

            this.compiler = new CSCompiler();

            //TODO: Implement settings
            if (!initialized)
            {
                Initialize();
            }
        }
Ejemplo n.º 8
0
        private void TypeCompiler_Click(object sender, EventArgs e)
        {
            string compileVar = CapsuleVarNamespaces
                                + CapsuleVarStart
                                + txtTypeCompile.Text
                                + CapsuleVarEnd;

            if (cSCompiler == null)
            {
                cSCompiler = new CSCompiler(dataStruct.AssemblyDefinition);
            }
            cSCompiler.Code = compileVar;
            MethodDefinition methodDefiniton = cSCompiler.GetMethodDefinition("B", "C");

            if (methodDefiniton == null)
            {
                return;
            }
            SetTypeReference(methodDefiniton.ReturnType);
        }
Ejemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            string message   = string.Empty;
            int    errorcode = CSCompiler.Compile(textBox1.Text, "test.dll", out message);

            if (errorcode != 0)
            {
                textBox2.Text = message;
            }

            //object obj1 = CSScript.CSScript.CreateObject("test.dll", "test.testdata", null);
            //object obj2 = CSScript.CSScript.CreateObject("test.dll", "test.CTObservableCollection", null);

            //string message = string.Empty;
            int    error = 0;
            object obj   = CSCompiler.Compile(textBox1.Text, "test.testdata", null, out error, out message);

            if (errorcode != 0)
            {
                textBox2.Text = message;
            }
        }
Ejemplo n.º 10
0
        public void Compile_no_errors()
        {
            var csSource = new Sourcecode
            {
                Filename = "program_no_errors.cs",
                Text     = @"using System;
public class Program {
  public static void Main(string[] args) {
    #region main
var answer = 42;
Console.WriteLine(answer);
    #endregion
  }
}
".Split('\n')
            };

            Executable result = null;

            CSCompiler.Compile(csSource,
                               exe => result = exe,
                               errors => {
                foreach (var err in errors)
                {
                    Console.WriteLine($"{err.Filename} - {err.LineNumber},{err.ColumnNumber}: {err.Description}");
                }
                Assert.Fail("There should not be any errors!");
            });

            Assert.NotNull(result);


            var output = ConsoleOutput.Capture(() => result.Main());

            Assert.AreEqual("42", output.Trim());
        }