How do i know my dll is obfuscated with a non trial version

I need my application to tell me if it has been obfuscated with SmartAssembly trial or professional. I need it to open a messagebox that says if the version I used is trial and therefore expires or if I used the professional. How do you do this in C #? What code should I write? What dll should I use?
Tagged:

Answers

  • Hi 

    The best way would be to look for custom attributes added to the assembly by SA. Each assembly processed by SA will have PoweredByAttribute on it and those processed with trial version, will additionally have DoNotDistributeAttribute on them.

    So, you can use System.Reflection or something similar and look if there is:
    • SmartAssembly.Attributes.PoweredByAttribute on the assembly in order to find out if it was processed by SmartAssembly,
    • SmartAssembly.Attributes.DoNotDistributeAttribute on the assembly in order to find out if it was processed by trial version of SmartAssembly.

    // .NET Core 3.1 app, using System.Reflection
    static void Main(string[] args)
    {
        var mainAssembly = typeof(Program).Assembly;
        Console.WriteLine($"Processed by SA: {IsProcessedBySA(mainAssembly)}");
        Console.WriteLine($"Trial version: {IsProcessedByTrialVersion(mainAssembly)}");
        Console.ReadKey();
    }

    static bool IsProcessedBySA(Assembly assembly)
    {
        return assembly.CustomAttributes
            // Can use .FullName == "SmartAssembly.Attributes.PoweredByAttribute" as well
            .Any(a => a.AttributeType.Name == "PoweredByAttribute");
    }

    static bool IsProcessedByTrialVersion(Assembly assembly)
    {
        return assembly.CustomAttributes
            // Can use .FullName == "SmartAssembly.Attributes.DoNotDistributeAttribute" as well
            .Any(a => a.AttributeType.Name == "DoNotDistributeAttribute");
    }

    I imagine you are wanting to check this before sending the application out - but otherwise if you try to launch application processed with trial version, on machine that doesn't have the SA installed (or expiration date was reached), it'll show a messagebox and then quit.

    ​​

    Kind regards

    Victoria Wiseman | Redgate Software
    Have you visited our Help Center?
  • ms0713ms0713 Posts: 4 New member
    edited April 12, 2021 5:02AM
    I have obfuscated my Dlls using SA Trial Version. Now I want to load test them on my Testing Environment which is different machine. I m not able do this as it gives error mentioned in previous comment. I cannot have two Trial Licenses as Red Gate issues only one Trial License per Company. What can be the solution for this as my Evaluation completely depend on Load Testing?
  • Hi @ms0713

    This should work, the trial version expires and turns into the free version. You should still be able to do testing with the free version and you don't need to worry about the trial keys.
    Kind regards

    Victoria Wiseman | Redgate Software
    Have you visited our Help Center?
  • ms0713ms0713 Posts: 4 New member
    Hi @Victoria W
    My point is I required two trial licenses as my development and testing environments are different. Red-Gate provides only single trial license per Company. However I have been offered second trial license from Red-Gate team.

    Thanks.
  • bitshiftbitshift Posts: 3 New member
    "...The best way would be to look for custom attributes added to the assembly by SA. ...

    SmartAssembly.Attributes.PoweredByAttribute on the assembly in order to find out if it was processed by SmartAssembly,
    SmartAssembly.Attributes.DoNotDistributeAttribute on the assembly in order to find out if it was processed by trial version of SmartAssembly...."

    ... the easiest way to look at this is probably ILSpy -- you don't have to write your own ObfuscationChecker.  https://github.com/icsharpcode/ILSpy . You load the obfuscated dll, and it displays the assembly attributes at the very top. You can also inspect the quality of the obfuscation that way.


Sign In or Register to comment.