Home - Forums-.NET - Spices.Net - Accessing methods

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

Accessing methods
Link Posted: 07-Nov-2010 22:22
Hi, 9rays! Check this situation.
Assembly A:
    
public class A
    {
        public int Id
        {
            get { return 5; }
        }

        public bool Compare(int id)
        {
            return id == Id;
        }
    }

    class Y
    {
        class Z
        {
            public void Work()
            {
                A a = new A();
                int id = a.Id;
            }
        }
    }

Assembly B (makes reference to A):
    
class SomeClass
    {
        public void SomeMethod()
        {
            A a = new A();
            a.Compare(10);
        }
    }

After obfuscation, 'SomeMethod' calling results in MethodAccessException. Why?
Let's look at obfuscated 'Compare' method of class A.
public bool 2Oq6d(int num1)
{
    return (num1 == X0iH3Z.X0iH4Z.Ι.α(this));
}

X0iH4Z is nothing more then PRIVATE class Z!
Link Posted: 08-Nov-2010 04:13
Thanks for the question.
That's:
public bool 2Oq6d(int num1)
{
    return (num1 == X0iH3Z.X0iH4Z.Ι.α(this));
}

are results of anonymization.
Calling method is anonymized and its body moved to 'anonymizer' method (Ι.α).
Anonymization shouldn't cause MethodAccessException because anonymizer methods are internally visible to class from these methods were moved.
Could you send us the whole sample and obfuscation settings for both assemblies to reproduce this problem and find the source/reason?
We've tried to reproduce it, but all works fine on our side.
Link Posted: 08-Nov-2010 20:57
Method A.get_Id was moved to internal 'anonymizer' class I inside class Z. That's why it's not visible for SomeClass.
I think it's all about obfuscation order. Probably, nested classes process first. When anonymizer found A.get_Id invocation in class Z, it moved this invocation to Ι.α. Class A was next, but A.get_Id in Compare method was not moved to corresponding 'anonymizer' class for A, because it was already 'anonymized'.
Am I right?
I sent you additional information on support@9rays.net
Link Posted: 09-Nov-2010 15:45
Thanks for the additional information. Yes, you are right, CodeAnonymizer incorrectly works with nested classes.
I'll let you know when we'll fix that problem.
Link Posted: 10-Nov-2010 17:40
Let you know, that fixed version of Spices.Net v5.8.1.9 is available for downloading.
Thanks again for your patience and additional information and samples, they were very helpful.
Link Posted: 10-Nov-2010 22:55
I downloaded new version.

First:
Lines like [MD] Error: TypeDef has a duplicate based on name+namespace, token=0x0200016b, duplicate:token=0x020001e0. appeared in results of verification for some assemblies.
What the consequences might be because of these errors?

Second:
Now, 'anonymizer' classes are moved outside private nested ones. But it doesn't always solve the problem (I sent you another sample about it).
Link Posted: 11-Nov-2010 16:36
First:
Lines like [MD] Error: TypeDef has a duplicate based on name+namespace, token=0x0200016b, duplicate:token=0x020001e0. appeared in results of verification for some assemblies.
What the consequences might be because of these errors?

If these classes aren't used in reflection/serialization usually no consequences. But this error shows the name conflict that's not good for quality of obfuscation.
We've solved that problem in a today update (v5.8.1.10.)
Second:
Now, 'anonymizer' classes are moved outside private nested ones. But it doesn't always solve the problem (I sent you another sample about it).

We've received your message, but seems you forgot to attach the sample. Before sending it again (don't forget about attachments :)) please try the latest update.
Link Posted: 11-Nov-2010 20:43
:) Seems I laid an egg with my last message. It happens sometimes...
In general, I tried your latest update and sent message again, because the problem with access still remains.
Link Posted: 12-Nov-2010 02:06
Thanks, now we got it.
Link Posted: 16-Nov-2010 13:37
Thanks again for all your help! Let you know that fixed version of Spices.Net v.5.8.1.14 is available for downloading.