This repository has been archived by the owner on Jan 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Program.cs
57 lines (51 loc) · 1.77 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
using System;
using System.IO;
using System.Reflection;
using Rocket.Sandbox;
namespace Rocket.SandboxTester
{
class Program
{
static void Main(string[] args)
{
WriteLine("Rocketmod Sandbox Tester");
start:
WriteLine(string.Empty);
WriteLine("Input file name: ", ConsoleColor.Yellow);
Write("> ");
string name = Console.ReadLine();
if (!File.Exists(name))
{
WriteLine("File not found", ConsoleColor.Red);
goto start;
}
var asm = Assembly.LoadFile(Path.GetFullPath(name));
var res = new SandboxCodeChecker().IsSafeAssembly(asm);
if (res.Passed)
{
WriteLine("All checks passed. File is safe.", ConsoleColor.DarkGreen);
goto start;
}
var blockedIns = res.IllegalInstruction;
var pos = res.Position;
WriteLine("Check not passed!", ConsoleColor.Red);
WriteLine("> Failed on: " + pos.InstructionName);
WriteLine("> Reason: " + blockedIns.BlockReason + " on " + blockedIns.InstructionName);
goto start;
}
public static void Write(string s, ConsoleColor color = ConsoleColor.White)
{
var orgColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.Write(s);
Console.ForegroundColor = orgColor;
}
public static void WriteLine(string s, ConsoleColor color = ConsoleColor.White)
{
var orgColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(s);
Console.ForegroundColor = orgColor;
}
}
}