Exception: Invalid type owner for DynamicMethod.

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, melvyn.harbour, dom.smith

Exception: Invalid type owner for DynamicMethod.

Postby Uniwares_AS » Wed Mar 23, 2011 3:40 pm

I am a bit lost on this one. It happened with SA5 and happens with SA6 but doesnt (of course) in the non-protected assembly.

What i get is the following:

System.ArgumentException occurred
Message=Invalid type owner for DynamicMethod.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility, Boolean transparentMethod)
InnerException:

The call stack though shows a bit more:

mscorlib.dll!System.Reflection.Emit.DynamicMethod.Init(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] signature, System.Type owner, System.Reflection.Module m, bool skipVisibility, bool transparentMethod)
mscorlib.dll!System.Reflection.Emit.DynamicMethod.DynamicMethod(string name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, bool skipVisibility)
Uniwares.Mail.Server.dll!#e.#d.#F()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceApplication()
[Native to Managed Transition]
[Managed to Native Transition]
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.#Xk(string methodName = "OnStart", object[] parameters = {object[0x00000001]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.Start()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceMain(string[] args = {string[0x00000000]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.SelfMonitoringServiceApplication<–.™>.Main2(string[] args = {string[0x00000000]})
aMandaServer.exe!–.˜.(string[] args = {string[0x00000000]})
[Native to Managed Transition]
[Managed to Native Transition]


Deobfuscating the trace:

mscorlib.dll!System.Reflection.Emit.DynamicMethod.Init(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] signature, System.Type owner, System.Reflection.Module m, bool skipVisibility, bool transparentMethod)
mscorlib.dll!System.Reflection.Emit.DynamicMethod.DynamicMethod(string name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, bool skipVisibility)
Uniwares.Mail.Server.dll!SmartAssembly.HouseOfCards.Strings.CreateGetStringDelegate()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceApplication()
[Native to Managed Transition]
[Managed to Native Transition]
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.InvokeServiceMethod(string methodName = "OnStart", object[] parameters = {object[0x00000001]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.Start()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceMain(string[] args = {string[0x00000000]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.SelfMonitoringServiceApplication<–.™>.Main2(string[] args = {string[0x00000000]})
aMandaServer.exe!–.˜.(string[] args = {string[0x00000000]})
[Native to Managed Transition]
[Managed to Native Transition]

The "Uniwares.Mail.Server.ServiceApplication<–.™>" doesnt deobfuscate at all, reason unknown yet.

Any ideas where to start? This used to work before, there has been no change at all in the Uniwares.Mail.Server.dll since ages. Changes have been applied to assemblies below and above the call chain.
Uniwares_AS
 
Posts: 132
Joined: Thu Oct 11, 2007 3:29 pm

Postby Brian Donahue » Fri Mar 25, 2011 10:54 am

Hello.

It looks like this is one of those "you can't obfuscate anonymous types" issues that can happen with LINQ to SQL. The list of all the types I know of that must be excluded are listed on the SDK Wiki. (The list may be incomplete)

The bits that can't be deobfuscated probably exist in another assembly that has been protected with SmartAssembly at obfuscation level 2 or higher (non-ASCII) because you can't use the stack decoder except with ASCII obfuscation.
Brian Donahue
 
Posts: 6668
Joined: Mon Aug 23, 2004 10:48 am

Postby Uniwares_AS » Fri Mar 25, 2011 1:02 pm

I wish it was LINQ to SQL or at least LINQ at all, but its not. LINQ is not used at all.

The interesting thing I found out here is that in a release version without SA the exception is another one but its swallowed by the runtime.
The runtime tries to load an serialization assembly which doesn't exist but it continues without it (who has the guts to dive into such a thing?)

Yet, after protection it turns into something completely different which worries me a bit.
Uniwares_AS
 
Posts: 132
Joined: Thu Oct 11, 2007 3:29 pm

Postby Brian Donahue » Fri Mar 25, 2011 1:40 pm

It looks like an anonymous type -- I'm not sure about all of the .NET objects that use them, but LINQ and lambda expressions are two I know of.
Brian Donahue
 
Posts: 6668
Joined: Mon Aug 23, 2004 10:48 am

Postby Brian Donahue » Tue Mar 29, 2011 1:08 pm

Did you try excluding the anonymous types? Sorry I don't know which - they appear to be non-ASCII obfuscated in another assembly of yours.

In my experience all .NET apps throw a serialization exception when they look for pre-compiled "XmlSerializers" assemblies, handle the exception, and emit an "XmlSerializers" assembly dynamically.
Brian Donahue
 
Posts: 6668
Joined: Mon Aug 23, 2004 10:48 am

Postby Chris.Allen » Tue Mar 29, 2011 1:22 pm

Another line of attack- could you help us reproduce please? This allows us access to development resources and often speeds up resolution time dramatically. I can set you up any ftp space necessary.
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

Postby Uniwares_AS » Tue Mar 29, 2011 11:01 pm

I guess what Brian said about the XmlSerializers is happening here (at the not protected app shows that), but what happens then with the protected app is at the moment out of my understanding.

I will be able to repro that for you but give me a few days resolver other issues first.
Uniwares_AS
 
Posts: 132
Joined: Thu Oct 11, 2007 3:29 pm


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests

cron