forked from bytecode77/self-morphing-csharp-binary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
37 lines (33 loc) · 1.23 KB
/
Program.cs
File metadata and controls
37 lines (33 loc) · 1.23 KB
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
using System;
using System.CodeDom.Compiler;
namespace ReflectionTesting
{
public static class Program
{
public static void Main()
{
int a1 = Environment.TickCount;
Random b1 = new Random(a1);
dynamic a2 = GetProperty("System.Environment", "TickCount");
dynamic b2 = GetConstructor("System.Random", new Type[] { GetType("System.Int32") }, new object[] { a2 });
CodeDomProvider c1 = CodeDomProvider.CreateProvider("CSharp");
dynamic c2 = InvokeMethod("System.CodeDom.Compiler.CodeDomProvider", "CreateProvider", new Type[] { GetType("System.String") }, new object[] { "CSharp" });
}
static dynamic GetConstructor(string type, Type[] types, object[] parameters)
{
return Type.GetType(type).GetConstructor(types).Invoke(parameters);
}
static dynamic GetProperty(string type, string property)
{
return Type.GetType(type).GetProperty(property).GetMethod.Invoke(null, new object[0]);
}
static dynamic InvokeMethod(string type, string method, Type[] types, object[] parameters)
{
return Type.GetType(type).GetMethod(method, System.Reflection.BindingFlags.Static).Invoke(null, parameters);
}
static Type GetType(string name)
{
return Type.GetType(name);
}
}
}