Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $test = @"
- using System;
- using System.Text;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Globalization;
- public class Wrapper {
- // Declare a delegate type that can be used to execute the completed dynamic method.
- private delegate string BaseDelegate(string input);
- public static void WOW(string input)
- {
- // Create a dynamic method with the name "Base", a return type of string, and one string parameter
- DynamicMethod baseDM = new DynamicMethod("Base",typeof(string),new Type[] { typeof(string) }, typeof(string).Module);
- MethodInfo base64Convertor = typeof(System.Convert).GetMethods()[308]; // System.Convert.FromBase64String
- MethodInfo getUTF8Encoding = typeof(System.Text.Encoding).GetMethod("get_UTF8", new Type[] { });
- MethodInfo getString = System.Text.Encoding.UTF8.GetType().GetMethod("GetString", new Type[] { typeof(byte[]) });
- ILGenerator il = baseDM.GetILGenerator(512);
- // Get UTF8 object
- il.EmitCall(OpCodes.Call, getUTF8Encoding, null);
- // Load the first argument, which is a string, onto the stack.
- il.Emit(OpCodes.Ldarg_0);
- // Call Convert.FromBase64String
- il.EmitCall(OpCodes.Call, base64Convertor, null);
- // Call UTF8.GetString
- il.EmitCall(OpCodes.Callvirt, getString, null);
- // Return the top value on the evaluation stack
- il.Emit(OpCodes.Ret);
- // Create a delegate that represents the dynamic method. This
- // action completes the method. Any further attempts to
- // change the method are ignored.
- BaseDelegate bbb = (BaseDelegate)baseDM.CreateDelegate(typeof(BaseDelegate));
- var ccc= bbb(input);
- Console.WriteLine(ccc);
- }
- }
- "@
- Add-Type -TypeDefinition $test
- [Wrapper]::WOW("dGhpcyBpcyBhIHRlc3Q=")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement