GetModuleType and derivatives should respect .NET Core / .NET 5+ behavior
Closed this issue · 0 comments
Washi1337 commented
AsmResolver Version
5.0.0
.NET Version
.NET 6.0
Operating System
Windows
Describe the Bug
While in .NET Framework the module type (<Module>
) is always considered to be the first type in the TypeDef metadata table (i.e., token 0x02000001), .NET Core also checks whether this type is actually called <Module>
. This behavior is currently not reflected in ModuleDefinition.GetModuleType()
and derivatives.
How To Reproduce
With the following sample binaries:
Run the following code:
string[] paths = {
"ModuleCctorNetFramework.exe",
"ModuleCctorNet6.dll",
"ModuleCctorAbsentNet6.dll",
"ModuleCctorLookalikeNet6.dll",
};
foreach (string path in paths)
{
var module = ModuleDefinition.FromFile(path);
Console.WriteLine(path + ": " + (module.GetModuleType()?.FullName ?? "No <Module> type."));
}
Expected Behavior
ModuleCctorNetFramework.exe: CustomModuleType
ModuleCctorNet6.dll: <Module>
ModuleCctorAbsentNet6.dll: No <Module> type.
ModuleCctorLookalikeNet6.dll: No <Module> type.
Actual Behavior
ModuleCctorNetFramework.exe: CustomModuleType
ModuleCctorNet6.dll: <Module>
ModuleCctorAbsentNet6.dll: <Module>
ModuleCctorLookalikeNet6.dll: Program
Additional Context
No response