Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 70 additions & 31 deletions dnlib.sln
Original file line number Diff line number Diff line change
@@ -1,31 +1,70 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
MinimumVisualStudioVersion = 16.0.29318.209
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dnlib", "src\dnlib.csproj", "{FDFC1237-143F-4919-8318-4926901F4639}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples", "Examples\Examples.csproj", "{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|Any CPU.Build.0 = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49902A67-E85B-44E8-9C4F-26F8854AA894}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
MinimumVisualStudioVersion = 16.0.29318.209
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dnlib", "src\dnlib.csproj", "{FDFC1237-143F-4919-8318-4926901F4639}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples", "Examples\Examples.csproj", "{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dnlib.Tests", "tests\dnlib.Tests\dnlib.Tests.csproj", "{B57399F8-DA15-4876-A3C2-E2B66153D77C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|x64.ActiveCfg = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|x64.Build.0 = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|x86.ActiveCfg = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Debug|x86.Build.0 = Debug|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|Any CPU.Build.0 = Release|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|x64.ActiveCfg = Release|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|x64.Build.0 = Release|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|x86.ActiveCfg = Release|Any CPU
{FDFC1237-143F-4919-8318-4926901F4639}.Release|x86.Build.0 = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|x64.ActiveCfg = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|x64.Build.0 = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|x86.ActiveCfg = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Debug|x86.Build.0 = Debug|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|Any CPU.Build.0 = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|x64.ActiveCfg = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|x64.Build.0 = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|x86.ActiveCfg = Release|Any CPU
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}.Release|x86.Build.0 = Release|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Debug|x64.ActiveCfg = Debug|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Debug|x64.Build.0 = Debug|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Debug|x86.ActiveCfg = Debug|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Debug|x86.Build.0 = Debug|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Release|Any CPU.Build.0 = Release|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Release|x64.ActiveCfg = Release|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Release|x64.Build.0 = Release|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Release|x86.ActiveCfg = Release|Any CPU
{B57399F8-DA15-4876-A3C2-E2B66153D77C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B57399F8-DA15-4876-A3C2-E2B66153D77C} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49902A67-E85B-44E8-9C4F-26F8854AA894}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions src/DotNet/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@ IEnumerable<string> GetDirs(string baseDir) {
IEnumerable<string> FindAssembliesModuleSearchPaths(IAssembly assembly, ModuleDef sourceModule, bool matchExactly) {
string asmSimpleName = UTF8String.ToSystemStringOrEmpty(assembly.Name);
var searchPaths = GetSearchPaths(sourceModule);
#if NETCOREAPP
searchPaths = searchPaths.Union(new string[] { System.IO.Path.GetDirectoryName(typeof(System.Math).Assembly.Location) });
#endif
var exts = assembly.IsContentTypeWindowsRuntime ? winMDAssemblyExtensions : assemblyExtensions;
foreach (var ext in exts) {
foreach (var path in searchPaths) {
Expand Down
3 changes: 3 additions & 0 deletions src/DotNet/FrameworkRedirect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ static bool TryApplyFrameworkRedirect(IAssembly assembly, Dictionary<string, Fra
if (Utils.CompareTo(assembly.Version, redirect.redirectVersion) == 0)
redirectedAssembly = assembly;
else {
// Don't redirect System.Runtime to an older version
if (assembly.Name == "System.Runtime" && Utils.CompareTo(assembly.Version, redirect.redirectVersion) > 0)
return false;
redirectedAssembly = new AssemblyNameInfo(assembly);
redirectedAssembly.Version = redirect.redirectVersion;
}
Expand Down
41 changes: 41 additions & 0 deletions tests/dnlib.Tests/AssemblyResolutionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;

namespace dnlib.Tests;

[TestClass]
public sealed class AssemblyResolutionTests
{
private static Stream? GetManifestStreamSource() =>
typeof(AssemblyResolutionTests).Assembly.GetManifestResourceStream(typeof(AssemblyResolutionTests), "Test_Resource.txt");

[TestMethod]
public void ResolveSystemRuntimeMethods()
{
var moduleDef = LoadTestModuleDef();
var thisTypeDef = moduleDef.Find(typeof(AssemblyResolutionTests).FullName, false);
var refMethod = thisTypeDef.FindMethod(nameof(GetManifestStreamSource));
var instructions = refMethod.Body.Instructions;
for (var i = 0; i < instructions.Count; i++) {
var instruction = instructions[i];
if (instruction.OpCode != OpCodes.Callvirt ||
!(instruction.Operand is IMethodDefOrRef targetMethodDefOrRef) ||
!UTF8String.Equals(targetMethodDefOrRef.Name, "GetManifestResourceStream") ||
!UTF8String.Equals(targetMethodDefOrRef.DeclaringType.FullName, "System.Reflection.Assembly")) continue;

var targetMethodDef = targetMethodDefOrRef.ResolveMethodDefThrow();
Assert.AreEqual("System.IO.Stream", targetMethodDef.ReturnType.FullName);
Assert.AreEqual(3, targetMethodDef.Parameters.Count);
}
}
internal static ModuleDefMD LoadTestModuleDef() {
var asmResolver = new AssemblyResolver();
asmResolver.DefaultModuleContext = new ModuleContext(asmResolver);
var options = new ModuleCreationOptions(asmResolver.DefaultModuleContext);

var thisModule = ModuleDefMD.Load(typeof(AssemblyResolutionTests).Module, options);
asmResolver.AddToCache(thisModule);

return thisModule;
}
}
1 change: 1 addition & 0 deletions tests/dnlib.Tests/MSTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
22 changes: 22 additions & 0 deletions tests/dnlib.Tests/dnlib.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\dnlib.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>