Options

ExecuteAssembly

SlushPuppySlushPuppy Posts: 5
edited January 5, 2012 8:49AM in SmartAssembly
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.

Comments

  • Options
    Execute Assembly probably finds the entry point using
    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.
    Thanks,
    James Davies
    Technical Support Engineer
    Red Gate Software
  • Options
    Execute Assembly probably finds the entry point using
    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.

    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);
  • Options
    OK. Using reflection on obfuscated code often causes issues.

    Could you add the licensing wrapper to your code and then process with SA? (SA generally works best when it is done last)
    Thanks,
    James Davies
    Technical Support Engineer
    Red Gate Software
  • Options
    OK. Using reflection on obfuscated code often causes issues.

    Could you add the licensing wrapper to your code and then process with SA? (SA generally works best when it is done last)

    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.
  • Options
    I am not sure why you don't have access to the code until after it has been processed by Smartassembly ? Do you have a Smartassembly license ?

    The supported way to use Smartassembly is to apply it last , and not to use reflection on obfuscated code.
    Thanks,
    James Davies
    Technical Support Engineer
    Red Gate Software
  • Options
    The problem is it is outputted from a private Rapid Development tool that outputs a .net assembly, and they already pass it through SA6. We tried making our wrapper using .NET (C#) but can't execute the assembly when using byte loaded assembly.

    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.
  • Options
    We need to reproduce this exact problem in-house to know if what you are doing is even supported. Would you be willing to help us create an exact reproduction of your issue? If so, we can set up space for uploads etc.
Sign In or Register to comment.