Skip to content

Instantly share code, notes, and snippets.

@3lpsy
Created October 30, 2019 20:00
Show Gist options
  • Save 3lpsy/ef160b7e1de54903791afdb717ae1e52 to your computer and use it in GitHub Desktop.
Save 3lpsy/ef160b7e1de54903791afdb717ae1e52 to your computer and use it in GitHub Desktop.
EmbedMe.cs
using System;
using System.Reflection;
// this is a simple C# program that
// has another C# program (exe/dll)
// embedded in it
namespace Brunt
{
public class Brunt
{
// name of the assembly
// typically in Namespace.Classname format
public string TargetAssemblyName = "CustomHelper.CustomHelper";
// name of the method to call
// should probably be static and take no params
public string TargetMethodName = "Launch";
public Brunt()
{
StartApp();
}
[STAThread]
public static void Main(string[] args)
{
new Brunt();
}
public static void Execute()
{
new Brunt();
}
// the first third of the base64 encoded dll/exe
private string GetFirst()
{
return "";
}
// the second third of the base64 encoded dll/exe
private string GetSecond()
{
return "";
}
// the final third of the base64 encoded dll/exe
private string GetThird()
{
return "";
}
// just combine three sections into one
// and base64 decode them into a byte array
private byte[] Collab(string first, string second, string third)
{
string together = first + second + third;
return Convert.FromBase64String(together);
}
public void StartApp()
{
Console.WriteLine("Starting..");
string first = GetFirst();
Console.WriteLine("Starting...");
string second = GetSecond();
Console.WriteLine("Starting....");
string third = GetThird();
Console.WriteLine("Building app");
// concat the separated b64 encoded portions of the dll
// and decode them
byte[] myapp = Collab(first, second, third);
Console.WriteLine("Loading app");
Assembly a = Assembly.Load(myapp);
Type myType = a.GetType(TargetAssemblyName);
MethodInfo myMethod = myType.GetMethod(TargetMethodName);
Console.WriteLine(myMethod);
object obj = Activator.CreateInstance(myType);
Console.WriteLine("Triggering app");
// Execute the method.
myMethod.Invoke(obj, null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment