Exception: Invalid type owner for DynamicMethod.
Uniwares_AS
Posts: 168
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.
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.
Comments
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.
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.
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.
I will be able to repro that for you but give me a few days resolver other issues first.