-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
69 lines (61 loc) · 2.41 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace ProxyExe
{
class Program
{
static string source = @"
using System;
using System.IO;
using System.Diagnostics;
class Program
{
static int Main(string[] args)
{
using (Process process = new Process())
{
process.StartInfo.FileName = $fileName;
process.StartInfo.Arguments = string.Join("" "", args);
process.StartInfo.WorkingDirectory = $workingDir;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
process.WaitForExit();
return process.ExitCode;
}
}
}";
static void Main(string[] args)
{
var target = @"\\?\" + Path.GetFullPath(args[0]);
var fileName = Path.GetFileName(target);
var workingDir = Path.GetDirectoryName(target);
source = source.Replace("$fileName", $"@\"{fileName}\"");
source = source.Replace("$workingDir", $"@\"{workingDir}\"");
var provider = new CSharpCodeProvider();
var parameters = new CompilerParameters()
{
GenerateInMemory = true,
GenerateExecutable = true,
OutputAssembly = Path.GetFullPath(args[1])
};
parameters.ReferencedAssemblies.AddRange( new string[] { "mscorlib.dll", "System.Core.dll", "System.dll" } );
var result = provider.CompileAssemblyFromSource(parameters, source);
if (result.Errors.Count == 0)
Console.WriteLine("Source {0} built into {1} successfully.", args[0], result.PathToAssembly);
else
{
Console.WriteLine("Errors building {0} into {1}", args[0], result.PathToAssembly);
foreach (CompilerError error in result.Errors)
{
Console.WriteLine(" {0}", error.ToString());
Console.WriteLine();
}
}
}
}
}