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?
Sign In or Register to comment.