Skip to content

Commit 2f74e9f

Browse files
authored
Merge 728e205 into a60be60
2 parents a60be60 + 728e205 commit 2f74e9f

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Confuser.Core/Helpers/InjectHelper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ public InjectContext(ModuleDef module, ModuleDef target) {
272272
public override ITypeDefOrRef Map(ITypeDefOrRef source) {
273273
if (DefMap.TryGetValue(source, out var mappedRef))
274274
return mappedRef as ITypeDefOrRef;
275+
276+
// check if the assembly reference needs to be fixed.
277+
if (source is TypeRef sourceRef) {
278+
var targetAssemblyRef = TargetModule.GetAssemblyRef(sourceRef.DefinitionAssembly.Name);
279+
if (!(targetAssemblyRef is null) && !string.Equals(targetAssemblyRef.FullName, source.DefinitionAssembly.FullName, StringComparison.Ordinal)) {
280+
// We got a matching assembly by the simple name, but not by the full name.
281+
// This means the injected code uses a different assembly version than the target assembly.
282+
// We'll fix the assembly reference, to avoid breaking anything.
283+
var fixedTypeRef = new TypeRefUser(sourceRef.Module, sourceRef.Namespace, sourceRef.Name, targetAssemblyRef);
284+
return Importer.Import(fixedTypeRef);
285+
}
286+
}
275287
return null;
276288
}
277289

Confuser.Runtime/Confuser.Runtime.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Import Project="..\ConfuserEx.Common.props" Condition="Exists('..\ConfuserEx.Common.props')" />
55

66
<PropertyGroup Label="Assembly Settings">
7-
<TargetFrameworks>net461</TargetFrameworks>
7+
<TargetFrameworks>net20</TargetFrameworks>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>..\ConfuserEx.snk</AssemblyOriginatorKeyFile>
@@ -15,6 +15,13 @@
1515
<Description>Runtime library of ConfuserEx</Description>
1616
</PropertyGroup>
1717

18+
<ItemGroup>
19+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
</ItemGroup>
24+
1825
<Import Project="..\ConfuserEx.Common.targets" Condition="Exists('..\ConfuserEx.Common.targets')" />
1926

2027
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if NETFRAMEWORK && (NET20 || NET35)
2+
// ReSharper disable once CheckNamespace
3+
namespace System.Diagnostics.CodeAnalysis {
4+
internal sealed class ExcludeFromCodeCoverageAttribute : Attribute {
5+
}
6+
}
7+
#endif

0 commit comments

Comments
 (0)