Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetModuleType and derivatives should respect .NET Core / .NET 5+ behavior #393

Closed
Washi1337 opened this issue Dec 22, 2022 · 0 comments · Fixed by #396
Closed

GetModuleType and derivatives should respect .NET Core / .NET 5+ behavior #393

Washi1337 opened this issue Dec 22, 2022 · 0 comments · Fixed by #396
Labels
bug dotnet Issues related to AsmResolver.DotNet
Milestone

Comments

@Washi1337
Copy link
Owner

Washi1337 commented Dec 22, 2022

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:

ModuleCctor.zip

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dotnet Issues related to AsmResolver.DotNet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant