Example #1
0
        static int Main(string[] args)
        {
            const string message = "IronMeta.App -n {0} -o {1} {2}: {3}";

            try
            {
                if (args.Length == 1 && args[0].Equals("--version", StringComparison.InvariantCultureIgnoreCase))
                {
                    Console.WriteLine("IronMeta.App {0}", typeof(CSharpGen).Assembly.GetName().Version.ToString());
                    return(0);
                }

                var options = Options.Parse(args);

                var inputInfo  = new FileInfo(options.InputFile);
                var outputInfo = new FileInfo(options.OutputFile);

                if (outputInfo.Exists && outputInfo.LastWriteTimeUtc > inputInfo.LastWriteTimeUtc && !options.Force)
                {
                    Console.WriteLine(string.Format(message, options.Namespace, outputInfo.FullName, inputInfo.FullName, "input is older than output; not generating"));
                    return(0);
                }
                else
                {
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    var match = CSharpShell.Process(inputInfo.FullName, outputInfo.FullName, options.Namespace, true);
                    stopwatch.Stop();

                    if (match.Success)
                    {
                        Console.WriteLine(string.Format(message, options.Namespace, outputInfo.FullName, inputInfo.FullName, stopwatch.Elapsed));
                        return(0);
                    }
                    else
                    {
                        int num, offset;
                        var line = match.MatchState.GetLine(match.MatchState.LastErrorIndex, out num, out offset);
                        Console.Error.WriteLine("{0}({1},{2}): error: {3}", inputInfo.FullName, num, offset, match.MatchState.LastError);
                        Console.Error.WriteLine("{0}", line);
                        Console.Error.WriteLine("{0}^", new string(' ', offset));
                        return(1);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.Error.WriteLine(e.InnerException.Message);
                }

                return(2);
            }
        }
Example #2
0
        static int Main(string[] args)
        {
            const string message = "IronMeta -n {0} -o {1} {2}: {3}";

            try
            {
                var options = Options.Parse(args);

                var inputInfo  = new FileInfo(options.InputFile);
                var outputInfo = new FileInfo(options.OutputFile);

                //if (outputInfo.Exists && outputInfo.LastWriteTimeUtc > inputInfo.LastWriteTimeUtc && !options.Force)
                //{
                //    Console.WriteLine(string.Format(message, options.Namespace, outputInfo.FullName, inputInfo.FullName, "input is older than output; not generating"));
                //    return 1;
                //}
                //else
                //{
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var match = CSharpShell.Process(inputInfo.FullName, outputInfo.FullName, options.Namespace, true);
                stopwatch.Stop();

                if (match.Success)
                {
                    Console.WriteLine(string.Format(message, options.Namespace, outputInfo.FullName, inputInfo.FullName, stopwatch.Elapsed));
                    return(0);
                }
                else
                {
                    int num, offset;
                    var line = match.MatchState.GetLine(match.MatchState.LastErrorIndex, out num, out offset);
                    Console.Error.WriteLine("{0}({1},{2}): error: {3}", inputInfo.FullName, num, offset, match.MatchState.LastError);
                    Console.Error.WriteLine("{0}", line);
                    Console.Error.WriteLine("{0}^", new string(' ', offset));
                    return(1);
                }
                //}
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.Error.WriteLine(e.InnerException.Message);
                }

                return(2);
            }
        }
Example #3
0
        static int Main(string[] args)
        {
            const string message = "IronMeta -n {0} -o {1} {2}";

            try
            {
                var options    = Options.Parse(args);
                var inputInfo  = new FileInfo(options.InputFile);
                var outputInfo = new FileInfo(options.OutputFile);

                var match = CSharpShell.Process(inputInfo.FullName,
                                                outputInfo.FullName, options.Namespace, true);

                if (match.Success)
                {
                    Console.WriteLine(string.Format(message, options.Namespace,
                                                    outputInfo.FullName, inputInfo.FullName));
                    return(0);
                }
                else
                {
                    int num, offset;
                    var line = match.MatchState.GetLine(match.MatchState.LastErrorIndex, out num, out offset);
                    Console.Error.WriteLine("{0}({1},{2}): error: {3}",
                                            inputInfo.FullName, num, offset, match.MatchState.LastError);
                    Console.Error.WriteLine("{0}", line);
                    Console.Error.WriteLine("{0}^", new string(' ', offset));
                    return(1);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.Error.WriteLine
                        (e.InnerException.Message);
                }
                return(2);
            }
        }
Example #4
0
        public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace,
                            IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            using (var ms = new MemoryStream())
            {
                MatchResult <char, AstNode> result;

                using (var tw = new StreamWriter(ms, Encoding.UTF8))
                {
                    pGenerateProgress.Progress(0, 1);
                    result = CSharpShell.Process(wszInputFilePath, bstrInputFileContents, tw, wszDefaultNamespace);
                    pGenerateProgress.Progress(1, 1);
                }

                if (result.Success)
                {
                    byte[] bytes = ms.ToArray();
                    rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(bytes.Length);
                    Marshal.Copy(bytes, 0, rgbOutputFileContents[0], bytes.Length);
                    pcbOutput = (uint)bytes.Length;

                    return(VSConstants.S_OK);
                }
                else
                {
                    int num, offset;
                    var line = result.MatchState.GetLine(result.ErrorIndex, out num, out offset);

                    pGenerateProgress.GeneratorError(0, 0, result.Error, (uint)(num - 1), (uint)offset);

                    rgbOutputFileContents = null;
                    pcbOutput             = 0;

                    return(VSConstants.E_FAIL);
                }
            }
        }
Example #5
0
    public R2Repl(string[] args)
    {
        this.e = new Evaluator(new CompilerContext(
                new CompilerSettings {
                WarningLevel = 0,
                ShowFullPaths = true
            }, new ConsoleReportPrinter()));

        e.Run("LoadAssembly(\"Mono.Posix\")");
        e.Run("LoadAssembly(\"r2pipe\")");
        e.Run("LoadAssembly(\"Newtonsoft.Json\")");
        e.Run("using System;");
        e.Run("using System.Collections;");
        e.Run("using System.Collections.Generic;");
        e.Run("using Mono.Unix;");
        e.Run("using Newtonsoft.Json;");

        e.Run(@"
        /* example */
        public class Opcode {
        public string opcode;
        public string family;
        public string type;
        public string esil;
        public int address;
        public int size;
        }

        public class r2w {
        public r2pipe.IR2Pipe Instance;
        public r2w() {
        Instance = new r2pipe.RlangPipe();
        }
        public r2w(string file) {
        Instance = new r2pipe.R2Pipe(file);
        }
        public string cmd(string cmd) {
        return Instance.RunCommand(cmd).Trim();
        }
        public dynamic cmdj(string cmd) {
        return JsonConvert.DeserializeObject(this.cmd(cmd));
        }
        public Opcode[] Opcodes(int n) {
        var ops = new List<Opcode>();
        foreach (var op in cmdj(""aoj 10"")) {
            ops.Add (op.ToObject<Opcode>());
        }
        return ops.ToArray();
        }
        public void Seek(string addr) {
        cmd(""s "" + addr);
        }
        }
            ");
        args = ParseArgs(args);
        if (args == null) {
            /* exit */
            return;
        }
        if (args.Length > 0) {
            e.Run("var r2 = new r2w(\""+args[0]+"\");");
        } else {
            try {
                e.Run("var r2 = new r2w();");
            } catch (Exception _) {
                Console.WriteLine(@"
        Cannot find R2PIPE environment. See: csharp-r2 -h
        Run this from r2 like this: '#!pipe mono main.exe'
        ");
                return;
            }
        }
        if (RunArgs()) {
            this.shell = new CSharpShell (e);
        }
    }
Example #6
0
    public R2Repl(string[] args)
    {
        this.e = new Evaluator(new CompilerContext(
                                   new CompilerSettings {
            WarningLevel  = 0,
            ShowFullPaths = true
        }, new ConsoleReportPrinter()));

        e.Run("LoadAssembly(\"Mono.Posix\")");
        e.Run("LoadAssembly(\"r2pipe\")");
        e.Run("LoadAssembly(\"Newtonsoft.Json\")");
        e.Run("using System;");
        e.Run("using System.Collections;");
        e.Run("using System.Collections.Generic;");
        e.Run("using Mono.Unix;");
        e.Run("using Newtonsoft.Json;");

        e.Run(@"
/* example */
public class Opcode {
	public string opcode;
	public string family;
	public string type;
	public string esil;
	public int address;
	public int size;
}

public class r2w {
	public r2pipe.IR2Pipe Instance;
	public r2w() {
		Instance = new r2pipe.RlangPipe();
	}
	public r2w(string file) {
		Instance = new r2pipe.R2Pipe(file);
	}
	public string cmd(string cmd) {
		return Instance.RunCommand(cmd).Trim();
	}
	public dynamic cmdj(string cmd) {
		return JsonConvert.DeserializeObject(this.cmd(cmd));
	}
	public Opcode[] Opcodes(int n) {
		var ops = new List<Opcode>();
		foreach (var op in cmdj(""aoj 10"")) {
			ops.Add (op.ToObject<Opcode>());
		}
		return ops.ToArray();
	}
	public void Seek(string addr) {
		cmd(""s "" + addr);
	}
}
			"            );
        args = ParseArgs(args);
        if (args == null)
        {
            /* exit */
            return;
        }
        if (args.Length > 0)
        {
            e.Run("var r2 = new r2w(\"" + args[0] + "\");");
        }
        else
        {
            try {
                e.Run("var r2 = new r2w();");
            } catch (Exception _) {
                Console.WriteLine(@"
Cannot find R2PIPE environment. See: csharp-r2 -h
Run this from r2 like this: '#!pipe mono main.exe'
");
                return;
            }
        }
        if (RunArgs())
        {
            this.shell = new CSharpShell(e);
        }
    }