Exception: Invalid type owner for DynamicMethod.

Uniwares_ASUniwares_AS Posts: 168
edited March 29, 2011 6:01PM in SmartAssembly
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<&#150;.&#153;>.ServiceApplication()
[Native to Managed Transition]
[Managed to Native Transition]
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>.#Xk(string methodName = "OnStart", object[] parameters = {object[0x00000001]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>.Start()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>.ServiceMain(string[] args = {string[0x00000000]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.SelfMonitoringServiceApplication<&#150;.&#153;>.Main2(string[] args = {string[0x00000000]})
aMandaServer.exe!&#150;.&#152;.(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<&#150;.&#153;>.ServiceApplication()
[Native to Managed Transition]
[Managed to Native Transition]
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>.InvokeServiceMethod(string methodName = "OnStart", object[] parameters = {object[0x00000001]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>.Start()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>.ServiceMain(string[] args = {string[0x00000000]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.SelfMonitoringServiceApplication<&#150;.&#153;>.Main2(string[] args = {string[0x00000000]})
aMandaServer.exe!&#150;.&#152;.(string[] args = {string[0x00000000]})
[Native to Managed Transition]
[Managed to Native Transition]

The "Uniwares.Mail.Server.ServiceApplication<&#150;.&#153;>" 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.

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    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.
  • 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.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    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 DonahueBrian Donahue Posts: 6,590 Bronze 1
    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.
  • 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.
  • 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.
Sign In or Register to comment.