Home - Forums-.NET - Spices.Net - Generic methods obfuscation

Spices.Net

NET code security, tools to protect, obfuscate, tamper defense, code and data safety, recover, convert, optimize, explore, browse and analyze .Net software.

This forum related to following products: Spices.Net Suite, Spices.Net Obfuscator, Spices.Net Decompiler

Generic methods obfuscation
Link Posted: 28-Oct-2010 00:59
I have the following code


namespace ConsoleApplication1
{
    class A
    {
        public void DoSomething<T>()
        {
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                A a = new A();
                a.DoSomething<int>(); //<-BadImageFormatException: An attempt was made to load a program with an incorrect format
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }
    }
}

Without obfuscation all work correctly. After obfuscation, execution of this code finished with exception (see comment).
Is it bug or feature? )
Link Posted: 28-Oct-2010 01:30
Could you give the settings used for obfuscation? What version of Spices.Net Obfuscator have you used?
We've tried to reproduce that problem, but with v 5.8.1.0 this code is obfuscated correctly.
Link Posted: 28-Oct-2010 03:19
I use these settings:

  • Anonymizer: ReferencedMethods, ReferencedFields, InternalFields, InternalMethods, StringEncryption, StubUntouchedMethods, AnonymizePrivateMembers
  • AntiILDASM: False
  • IncrementalObfuscation: True
  • Members: Namespaces, Types, Methods, Fields, Properties, Events, Public, Interfaces, Parameters, Use_Attributes, Resources, Overridables, Enums, Structures, Protected, LeaveDebuggerHidden
  • MixDictionary: False
  • NamespacesRestructuring: AllTypesOneNameSpace
  • Naming: AlphaNumeric
  • Optimizer:
  • ResourcesProtection: None
  • SoftwareWatermark:
  • StringEncryptionMode: Encrypt
  • UniqueNames: False

Spices.Net Obfuscator version is 5.8.1.0. Version of .NET Framework - 3.5
Link Posted: 28-Oct-2010 04:36
Thanks for additional information. We'll make some tests and update Spices.Obfuscator ASAP. I'll let you know when fixed verison will be available for downloading (I think it takes not so much time to fix it).
Link Posted: 28-Oct-2010 04:53
Roger
Link Posted: 28-Oct-2010 06:21
Seems the problem is in Anonymizer.InternalMethods setting. Currently, as workaround, you can turn off this setting.
Link Posted: 01-Nov-2010 17:50
Let you know that the fixed version of Spices.Net v5.8.1.4 is available for downloading.
Thanks again for the additional information and for your patience.
Link Posted: 03-Nov-2010 04:43
Hi! It's me again. And my another problem with generic methods (
I have two assemblies A and B, B makes reference to A.
Assembly A contains abstract class Class1
    public abstract class Class1
    {
        public abstract IList GetObjects();
        public abstract List<int> GetObjects(Type objectType);
        public abstract List<T> GetObjects<T>();
    }

Assembly B contains class Class2, which implements Class1 and also has its own method
    
public class Class2: Class1
    {
        public override IList GetObjects()
        {
            return new ArrayList();
        }
        
        public override List<int> GetObjects(Type objectType)
        {
            return new List<int>();
        }

        public override List<T> GetObjects<T>()
        {
            return new List<T>();
        }

        public void GetObjects(out IList list)
        {
            list = new ArrayList();
        }
    }

In obfuscation options for assembly B I set Naming=Alphabetical, but for A Naming=AlphaNumeric.
Obfuscated code looks like following:
for Class1
public abstract class GZmyQ
{
    protected GZmyQ();
    public abstract List<T> 1vcGtMZ<T>();
    public abstract IList 1vcGtMZ();
    public abstract List<int> 1vcGtMZ(Type);
}

for Class2
public class yLZtP : GZmyQ
{
    public yLZtP();
    public override IList 1vcGtMZ(); //ok
    public override List<int> 1vcGtMZ(Type); //ok
    public override List<T> clwnpLZ<T>(); // ?
    public void clwnpLZ(out IList); //ok
}

So, if we'll try to create instance of Class2, we'll get TypeLoadException...
What I have to do, except setting Naming=Alphabetical for both assemblies?
Link Posted: 03-Nov-2010 04:58
No, specifying Alphabetical naming mode for both won't solve that problem.
To more precisely answer your question, we should analyze that situation.
Link Posted: 03-Nov-2010 19:08
Thanks for your very helpful code samples,
please download the latest fix - v5.8.1.6 what solves that problem.