Reputation: 43
Is there a way to embed my .net executable (C#/VB.Net) in a ntive binary like a C/C++ file which will load the .net assembly on startup? Like building a native wall arround the .net assembly?
Upvotes: 1
Views: 690
Reputation: 1236
You could embed your .Net binary in the C++ project as a resource and load it runtime, but I doubt that is a recommended way to increase security.
Edit: Someone asked for source code and suggested that I make a comment instead of an answer. I've just signed up for StackOverflow and I don't have enough reputation to make comments yet. But here's some source I used at some point:
public static int RunInternalExe(byte[] rawData, params string[] args)
{
Assembly asm = Assembly.Load(rawData);
MethodInfo mi = asm.EntryPoint;
if (mi == null)
throw new Exception("Entry point not found");
ParameterInfo[] prms = mi.GetParameters();
object[] mtd_args = null;
if (prms.Length > 0)
mtd_args = new object[] { args };
object result = mi.Invoke(null, mtd_args);
if (result is int)
return (int)result;
return 0;
}
Embed the managed .exe in your wrapper .exe and pass the raw data to the proc above.
MyTools.RunInternalExe(Resources.ExeData);
Ofcourse, if you want your wrapper .exe to be non-managed you'd have to translate the code above to C++ or some other language of your choice, that's kind of above my head right now...
Upvotes: 3