Skip to content

Commit

Permalink
Merge pull request #331 from Washi1337/hotfix/md-resolution-version-c…
Browse files Browse the repository at this point in the history
…heck

Hotfix: Metadata resolution should not check for assembly version during member lookup
  • Loading branch information
Washi1337 authored Jul 9, 2022
2 parents 9b51059 + c052097 commit de84e0e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AsmResolver.DotNet/DefaultMetadataResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DefaultMetadataResolver : IMetadataResolver
private readonly ConcurrentDictionary<ITypeDescriptor, TypeDefinition> _typeCache;
private readonly SignatureComparer _comparer = new()
{
AcceptNewerAssemblyVersionNumbers = true
IgnoreAssemblyVersionNumbers = true
};

/// <summary>
Expand Down
22 changes: 22 additions & 0 deletions test/AsmResolver.DotNet.Tests/MetadataResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ public void MaliciousExportedTypeLoop()
}

[Fact]
public void ResolveToOlderNetVersion()
{
// https://github.com/Washi1337/AsmResolver/issues/321

var mainApp = ModuleDefinition.FromBytes(Properties.Resources.DifferentNetVersion_MainApp);
var library = ModuleDefinition.FromBytes(Properties.Resources.DifferentNetVersion_Library);

mainApp.MetadataResolver.AssemblyResolver.AddToCache(library.Assembly!, library.Assembly!);

var definition = library
.TopLevelTypes.First(t => t.Name == "MyClass")
.Methods.First(m => m.Name == "ThrowMe");

var reference = (IMethodDescriptor) mainApp.ManagedEntrypointMethod!.CilMethodBody!.Instructions.First(
i => i.OpCode == CilOpCodes.Callvirt && ((IMethodDescriptor) i.Operand)?.Name == "ThrowMe")
.Operand!;

var resolved = reference.Resolve();
Assert.NotNull(resolved);
Assert.Equal(definition, resolved);
}

public void ResolveMethodWithoutHideBySig()
{
// https://github.com/Washi1337/AsmResolver/issues/241
Expand Down
14 changes: 14 additions & 0 deletions test/AsmResolver.DotNet.Tests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/AsmResolver.DotNet.Tests/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<data name="FieldRvaTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\FieldRvaTest.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="DifferentNetVersion_MainApp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DifferentNetVersion.MainApp.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="DifferentNetVersion_Library" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DifferentNetVersion.Library.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="CallManagedExport_X86" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\CallManagedExport.x86.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit de84e0e

Please sign in to comment.