Skip to content

Instantly share code, notes, and snippets.

@vivami
Created August 31, 2018 10:07
Show Gist options
  • Save vivami/8b5e117a65ea15f23c2b40a8b15889be to your computer and use it in GitHub Desktop.
Save vivami/8b5e117a65ea15f23c2b40a8b15889be to your computer and use it in GitHub Desktop.
Compile C# src at runtime.
compile(srcFinal, filename + "_obfuscated.exe");
static void compile(String source, String outfile) {
var provider_options = new Dictionary<string, string>
{
{"CompilerVersion","v3.5"}
};
var provider = new Microsoft.CSharp.CSharpCodeProvider(provider_options);
var compiler_params = new System.CodeDom.Compiler.CompilerParameters();
compiler_params.OutputAssembly = outfile;
compiler_params.GenerateExecutable = true;
// Compile
var results = provider.CompileAssemblyFromSource(compiler_params, source);
Console.WriteLine("Output file: {0}", outfile);
Console.WriteLine("Number of Errors: {0}", results.Errors.Count);
foreach (System.CodeDom.Compiler.CompilerError err in results.Errors) {
Console.WriteLine("ERROR {0}", err.ErrorText);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment