ExecuteAssembly
SlushPuppy
Posts: 5
I am trying to byte load an assembly that has been processed with SmartAssembly and execute it, but I am having a lot of problems.
If I use EntryPoint.Invoke, it load two obfuscated modules and then exits with an exit code 0. I use .net reflector and I can see the entry point is #gB, so I have tried to manually invoke that with similar results.
I have just about given up thinking it is not possible but what bugs me is using AppDomain.ExecuteAssembly() finds the entry point just fine and executes it flawlessly.
The problem, is I can't find a way to get ExecuteAssembly to accept a byte loaded assembly so I can embed this assembly with a licensing wrapper.
If I was to guess, it looks like it is picking the wrong entry point when trying to run, but both AppDomain.ExecuteAssembly and Assembly.EntryPoint are suppose to invoke the entry point, yet one has successfully done so, and the other, not so much.
If anyone has some insight on how I can make this work, I would be eternally grateful.
If I use EntryPoint.Invoke, it load two obfuscated modules and then exits with an exit code 0. I use .net reflector and I can see the entry point is #gB, so I have tried to manually invoke that with similar results.
I have just about given up thinking it is not possible but what bugs me is using AppDomain.ExecuteAssembly() finds the entry point just fine and executes it flawlessly.
The problem, is I can't find a way to get ExecuteAssembly to accept a byte loaded assembly so I can embed this assembly with a licensing wrapper.
If I was to guess, it looks like it is picking the wrong entry point when trying to run, but both AppDomain.ExecuteAssembly and Assembly.EntryPoint are suppose to invoke the entry point, yet one has successfully done so, and the other, not so much.
If anyone has some insight on how I can make this work, I would be eternally grateful.
Comments
public virtual MethodInfo EntryPoint { get; }
(http://msdn.microsoft.com/en-us/library ... point.aspx)
Your best option is to use that rather than trying to manually lookup the entry point in the obfuscated assembly.
James Davies
Technical Support Engineer
Red Gate Software
I was using the below code, which I believe is doing what you suggest.
Assembly a (byte loaded exe that is run through SmartAssembly)
a.EntryPoint.Invoke(null, null);
Could you add the licensing wrapper to your code and then process with SA? (SA generally works best when it is done last)
James Davies
Technical Support Engineer
Red Gate Software
Unfortunately no, the output we are given has already been run through SmartAssembly. It seems like Main() is always "#gB" but when I specifically invoke that function using Assembly.Invoke or other methods, it will launch two obfuscated module names (different every execution) but won't actually show the application.
The supported way to use Smartassembly is to apply it last , and not to use reflection on obfuscated code.
James Davies
Technical Support Engineer
Red Gate Software
I assume this is the same problem we are having when using commercial licensing tools like ExecKey, Intellilock, and so on. They will wrap the exe, and the licensing wrapper works, but won't spawn off the exe properly.