static int MainWorker(ILanguage lang, string pathSourceFile, string pathFinalOut) { // Some compilers (like VBC) get confused if the output extension isn't .exe. string pathTempOut = Path.ChangeExtension(Path.GetTempFileName(), ".exe"); // First invoke the high-level compiler WriteMarker(); Console.WriteLine("Compiling input file '" + pathSourceFile + "' with '" + lang.PrettyName + "' to output '" + pathFinalOut + "'"); Console.WriteLine("Compiling to temporary file:" + pathTempOut); lang.Compile(pathSourceFile, pathTempOut); // Now, IL-disassemble it. WriteMarker(); ILDocument doc = new ILDocument(pathTempOut); InlineILSnippet[] snippets = FindInlineILSnippets(lang, pathSourceFile); // Reinject the snippets. foreach (InlineILSnippet s in snippets) { Console.WriteLine("Found:" + s); foreach (string x in s.Lines) { Console.WriteLine(" :" + x); } doc.InsertSnippet(s); } // Now re-emit the new IL. WriteMarker(); doc.EmitToFile(pathFinalOut); // Since they're doing direct IL manipulation, we really should run peverify on the output. WriteMarker(); Console.WriteLine("runnning PEVerify on '{0}'.", pathFinalOut); Util.Run(SdkDir + @"\bin\PEverify.exe", pathFinalOut); Console.WriteLine("PEVerify passed!"); return(0); } // end main
// Main entry point. static int Main(string[] args) { string outputType = null; var showHelp = false; string outputFile = null; string inputFile = null; var verify = false; var verbose = false; string keyFile = null; var o = new OptionSet { {"dll", v => outputType = "DLL"}, {"exe", v => outputType = "EXE"}, {"k|key=", v => keyFile = v}, {"c|verify", v => verify = v != null }, {"v|verbose", v => verbose = v != null }, {"i|input=", v => inputFile = v}, {"o|output=", v => outputFile = v}, {"h|?|help", "show this help message", v => showHelp = v != null}, }; var extra = o.Parse(args); if (showHelp) { ShowHelp(o); return 0; } if (extra.Count != 0) { ShowHelp(o); return 1; } InitSdkDir(); try { var doc = new ILDocument(inputFile); var snippets = FindInlineILSnippets(doc); // Re-inject the snippets. foreach (var s in snippets) { if (verbose) { Console.WriteLine("Found:" + s); foreach (var x in s.Lines) Console.WriteLine(" :" + x); } s.InsertLocation = doc.FindSnippetLocation(s); } snippets.Sort((x, y) => y.InsertLocation - x.InsertLocation); foreach (var s in snippets) doc.Lines = Util.InsertArrayIntoArray(doc.Lines, s.Lines, s.InsertLocation); // Now re-emit the new IL. doc.EmitToFile(outputFile, outputType, keyFile, verbose); // Since they're doing direct IL manipulation, we really should run peverify on the output. if (verify) { Console.WriteLine("Running PEVerify on '{0}'.", outputFile); Util.Run(Path.Combine(SdkDir + "PEverify.exe"), outputFile); Console.WriteLine("PEVerify passed!"); } } catch (Exception e) { Console.WriteLine("Error:" + e.Message); return 1; } return 0; }
// Main entry point. static int Main(string[] args) { string outputType = null; var showHelp = false; string outputFile = null; string inputFile = null; var verify = false; var verbose = false; string keyFile = null; var o = new OptionSet { { "dll", v => outputType = "DLL" }, { "exe", v => outputType = "EXE" }, { "k|key=", v => keyFile = v }, { "c|verify", v => verify = v != null }, { "v|verbose", v => verbose = v != null }, { "i|input=", v => inputFile = v }, { "o|output=", v => outputFile = v }, { "h|?|help", "show this help message", v => showHelp = v != null }, }; var extra = o.Parse(args); if (showHelp) { ShowHelp(o); return(0); } if (extra.Count != 0) { ShowHelp(o); return(1); } InitSdkDir(); try { var doc = new ILDocument(inputFile); var snippets = FindInlineILSnippets(doc); // Re-inject the snippets. foreach (var s in snippets) { if (verbose) { Console.WriteLine("Found:" + s); foreach (var x in s.Lines) { Console.WriteLine(" :" + x); } } s.InsertLocation = doc.FindSnippetLocation(s); } snippets.Sort((x, y) => y.InsertLocation - x.InsertLocation); foreach (var s in snippets) { doc.Lines = Util.InsertArrayIntoArray(doc.Lines, s.Lines, s.InsertLocation); } // Now re-emit the new IL. doc.EmitToFile(outputFile, outputType, keyFile, verbose); // Since they're doing direct IL manipulation, we really should run peverify on the output. if (verify) { Console.WriteLine("Running PEVerify on '{0}'.", outputFile); Util.Run(Path.Combine(SdkDir + "PEverify.exe"), outputFile); Console.WriteLine("PEVerify passed!"); } } catch (Exception e) { Console.WriteLine("Error:" + e.Message); return(1); } return(0); }