Updated references to support dnlib nuget
This changes all the things required to support the newer version of dnlib and switch to use the nuget package of this library.
This commit is contained in:
Родитель
1402a8a145
Коммит
5c4e4ed89f
|
@ -1,3 +0,0 @@
|
|||
[submodule "dnlib"]
|
||||
path = dnlib
|
||||
url=../dnlib.git
|
|
@ -15,15 +15,12 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Label="Nuget Dependencies">
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.*" />
|
||||
<PackageReference Include="System.Threading" Version="4.*" />
|
||||
<PackageReference Include="dnlib" Version="3.3.2" />
|
||||
<PackageReference Include="Microsoft.DiaSymReader.Native" Version="1.7.0" />
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
|
||||
<PackageReference Include="System.Threading" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Label="Project Dependencies">
|
||||
<ProjectReference Include="..\dnlib\src\dnlib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Project\ConfuserPrj.xsd">
|
||||
<SubType>Designer</SubType>
|
||||
|
|
|
@ -58,23 +58,20 @@ namespace Confuser.Core.Helpers {
|
|||
/// <param name="ctx">The injection context.</param>
|
||||
/// <returns>The new TypeDef.</returns>
|
||||
static TypeDef PopulateContext(TypeDef typeDef, InjectContext ctx) {
|
||||
TypeDef ret;
|
||||
IDnlibDef existing;
|
||||
if (!ctx.Map.TryGetValue(typeDef, out existing)) {
|
||||
var ret = ctx.Map(typeDef)?.ResolveTypeDef();
|
||||
if (ret is null) {
|
||||
ret = Clone(typeDef);
|
||||
ctx.Map[typeDef] = ret;
|
||||
ctx.DefMap[typeDef] = ret;
|
||||
}
|
||||
else
|
||||
ret = (TypeDef)existing;
|
||||
|
||||
foreach (TypeDef nestedType in typeDef.NestedTypes)
|
||||
ret.NestedTypes.Add(PopulateContext(nestedType, ctx));
|
||||
|
||||
foreach (MethodDef method in typeDef.Methods)
|
||||
ret.Methods.Add((MethodDef)(ctx.Map[method] = Clone(method)));
|
||||
ret.Methods.Add((MethodDef)(ctx.DefMap[method] = Clone(method)));
|
||||
|
||||
foreach (FieldDef field in typeDef.Fields)
|
||||
ret.Fields.Add((FieldDef)(ctx.Map[field] = Clone(field)));
|
||||
ret.Fields.Add((FieldDef)(ctx.DefMap[field] = Clone(field)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -85,12 +82,11 @@ namespace Confuser.Core.Helpers {
|
|||
/// <param name="typeDef">The origin TypeDef.</param>
|
||||
/// <param name="ctx">The injection context.</param>
|
||||
static void CopyTypeDef(TypeDef typeDef, InjectContext ctx) {
|
||||
var newTypeDef = (TypeDef)ctx.Map[typeDef];
|
||||
|
||||
newTypeDef.BaseType = (ITypeDefOrRef)ctx.Importer.Import(typeDef.BaseType);
|
||||
var newTypeDef = ctx.Map(typeDef)?.ResolveTypeDefThrow();
|
||||
newTypeDef.BaseType = ctx.Importer.Import(typeDef.BaseType);
|
||||
|
||||
foreach (InterfaceImpl iface in typeDef.Interfaces)
|
||||
newTypeDef.Interfaces.Add(new InterfaceImplUser((ITypeDefOrRef)ctx.Importer.Import(iface.Interface)));
|
||||
newTypeDef.Interfaces.Add(new InterfaceImplUser(ctx.Importer.Import(iface.Interface)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -99,7 +95,7 @@ namespace Confuser.Core.Helpers {
|
|||
/// <param name="methodDef">The origin MethodDef.</param>
|
||||
/// <param name="ctx">The injection context.</param>
|
||||
static void CopyMethodDef(MethodDef methodDef, InjectContext ctx) {
|
||||
var newMethodDef = (MethodDef)ctx.Map[methodDef];
|
||||
var newMethodDef = ctx.Map(methodDef)?.ResolveMethodDefThrow();
|
||||
|
||||
newMethodDef.Signature = ctx.Importer.Import(methodDef.Signature);
|
||||
newMethodDef.Parameters.UpdateParameterTypes();
|
||||
|
@ -169,7 +165,7 @@ namespace Confuser.Core.Helpers {
|
|||
/// <param name="fieldDef">The origin FieldDef.</param>
|
||||
/// <param name="ctx">The injection context.</param>
|
||||
static void CopyFieldDef(FieldDef fieldDef, InjectContext ctx) {
|
||||
var newFieldDef = (FieldDef)ctx.Map[fieldDef];
|
||||
var newFieldDef = ctx.Map(fieldDef).ResolveFieldDefThrow();
|
||||
|
||||
newFieldDef.Signature = ctx.Importer.Import(fieldDef.Signature);
|
||||
}
|
||||
|
@ -202,9 +198,9 @@ namespace Confuser.Core.Helpers {
|
|||
/// <returns>The injected TypeDef.</returns>
|
||||
public static TypeDef Inject(TypeDef typeDef, ModuleDef target) {
|
||||
var ctx = new InjectContext(typeDef.Module, target);
|
||||
PopulateContext(typeDef, ctx);
|
||||
var result = PopulateContext(typeDef, ctx);
|
||||
Copy(typeDef, ctx, true);
|
||||
return (TypeDef)ctx.Map[typeDef];
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -215,9 +211,10 @@ namespace Confuser.Core.Helpers {
|
|||
/// <returns>The injected MethodDef.</returns>
|
||||
public static MethodDef Inject(MethodDef methodDef, ModuleDef target) {
|
||||
var ctx = new InjectContext(methodDef.Module, target);
|
||||
ctx.Map[methodDef] = Clone(methodDef);
|
||||
MethodDef result;
|
||||
ctx.DefMap[methodDef] = result = Clone(methodDef);
|
||||
CopyMethodDef(methodDef, ctx);
|
||||
return (MethodDef)ctx.Map[methodDef];
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -229,20 +226,20 @@ namespace Confuser.Core.Helpers {
|
|||
/// <returns>Injected members.</returns>
|
||||
public static IEnumerable<IDnlibDef> Inject(TypeDef typeDef, TypeDef newType, ModuleDef target) {
|
||||
var ctx = new InjectContext(typeDef.Module, target);
|
||||
ctx.Map[typeDef] = newType;
|
||||
ctx.DefMap[typeDef] = newType;
|
||||
PopulateContext(typeDef, ctx);
|
||||
Copy(typeDef, ctx, false);
|
||||
return ctx.Map.Values.Except(new[] { newType });
|
||||
return ctx.DefMap.Values.Except(new[] { newType }).OfType<IDnlibDef>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Context of the injection process.
|
||||
/// </summary>
|
||||
class InjectContext : ImportResolver {
|
||||
class InjectContext : ImportMapper {
|
||||
/// <summary>
|
||||
/// The mapping of origin definitions to injected definitions.
|
||||
/// </summary>
|
||||
public readonly Dictionary<IDnlibDef, IDnlibDef> Map = new Dictionary<IDnlibDef, IDnlibDef>();
|
||||
public readonly Dictionary<IMemberRef, IMemberRef> DefMap = new Dictionary<IMemberRef, IMemberRef>();
|
||||
|
||||
/// <summary>
|
||||
/// The module which source type originated from.
|
||||
|
@ -254,11 +251,6 @@ namespace Confuser.Core.Helpers {
|
|||
/// </summary>
|
||||
public readonly ModuleDef TargetModule;
|
||||
|
||||
/// <summary>
|
||||
/// The importer.
|
||||
/// </summary>
|
||||
readonly Importer importer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InjectContext" /> class.
|
||||
/// </summary>
|
||||
|
@ -267,36 +259,39 @@ namespace Confuser.Core.Helpers {
|
|||
public InjectContext(ModuleDef module, ModuleDef target) {
|
||||
OriginModule = module;
|
||||
TargetModule = target;
|
||||
importer = new Importer(target, ImporterOptions.TryToUseTypeDefs);
|
||||
importer.Resolver = this;
|
||||
Importer = new Importer(target, ImporterOptions.TryToUseTypeDefs, new GenericParamContext(), this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the importer.
|
||||
/// </summary>
|
||||
/// <value>The importer.</value>
|
||||
public Importer Importer {
|
||||
get { return importer; }
|
||||
}
|
||||
public Importer Importer { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override TypeDef Resolve(TypeDef typeDef) {
|
||||
if (Map.ContainsKey(typeDef))
|
||||
return (TypeDef)Map[typeDef];
|
||||
public override ITypeDefOrRef Map(ITypeDefOrRef source) {
|
||||
if (DefMap.TryGetValue(source, out var mappedRef))
|
||||
return mappedRef as ITypeDefOrRef;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MethodDef Resolve(MethodDef methodDef) {
|
||||
if (Map.ContainsKey(methodDef))
|
||||
return (MethodDef)Map[methodDef];
|
||||
public override IMethod Map(MethodDef source) {
|
||||
if (DefMap.TryGetValue(source, out var mappedRef))
|
||||
return mappedRef as IMethod;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override FieldDef Resolve(FieldDef fieldDef) {
|
||||
if (Map.ContainsKey(fieldDef))
|
||||
return (FieldDef)Map[fieldDef];
|
||||
public override IField Map(FieldDef source) {
|
||||
if (DefMap.TryGetValue(source, out var mappedRef))
|
||||
return mappedRef as IField;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MemberRef Map(MemberRef source) {
|
||||
if (DefMap.TryGetValue(source, out var mappedRef))
|
||||
return mappedRef as MemberRef;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -301,7 +301,7 @@ namespace Confuser.Protections {
|
|||
}
|
||||
}
|
||||
|
||||
class KeyInjector : IModuleWriterListener {
|
||||
class KeyInjector {
|
||||
readonly CompressorContext ctx;
|
||||
|
||||
public KeyInjector(CompressorContext ctx) {
|
||||
|
@ -312,7 +312,7 @@ namespace Confuser.Protections {
|
|||
OnWriterEvent(args.Writer, args.Event);
|
||||
}
|
||||
|
||||
public void OnWriterEvent(ModuleWriterBase writer, ModuleWriterEvent evt) {
|
||||
private void OnWriterEvent(ModuleWriterBase writer, ModuleWriterEvent evt) {
|
||||
if (evt == ModuleWriterEvent.MDBeginCreateTables) {
|
||||
// Add key signature
|
||||
uint sigBlob = writer.Metadata.BlobHeap.Add(ctx.KeySig);
|
||||
|
|
|
@ -52,8 +52,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsRenaming", "Tests\W
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsRenaming.Test", "Tests\WinFormsRenaming.Test\WinFormsRenaming.Test.csproj", "{6C8ECB51-EECE-49C3-89EC-CB0AAECCFF7E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dnlib", "dnlib\src\dnlib.csproj", "{18A3AD8D-DBF6-4489-A407-2972272CC6CB}"
|
||||
EndProject
|
||||
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VisualBasicRenamingResx", "Tests\VisualBasicRenamingResx\VisualBasicRenamingResx.vbproj", "{4B2CE997-8157-40B4-B42F-51CE33954AAC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualBasicRenamingResx.Test", "Tests\VisualBasicRenamingResx.Test\VisualBasicRenamingResx.Test.csproj", "{40C6A1BB-69AA-4869-81EE-41917D0B009A}"
|
||||
|
@ -78,17 +76,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "161_DynamicTypeRename", "Te
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "161_DynamicTypeRename.Test", "Tests\161_DynamicTypeRename.Test\161_DynamicTypeRename.Test.csproj", "{2B914EE7-F206-4A83-B435-460D054315BB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "193_ConstantsInlining", "Tests\193_ConstantsInlining\193_ConstantsInlining.csproj", "{AB2E1440-7EC2-45A2-8CF3-2975DE8A57AD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "193_ConstantsInlining", "Tests\193_ConstantsInlining\193_ConstantsInlining.csproj", "{AB2E1440-7EC2-45A2-8CF3-2975DE8A57AD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "193_ConstantsInlining.Lib", "Tests\193_ConstantsInlining.Lib\193_ConstantsInlining.Lib.csproj", "{630BF262-768C-4085-89B1-9FEF7375F442}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "193_ConstantsInlining.Lib", "Tests\193_ConstantsInlining.Lib\193_ConstantsInlining.Lib.csproj", "{630BF262-768C-4085-89B1-9FEF7375F442}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "193_ConstantsInlining.Test", "Tests\193_ConstantsInlining.Test\193_ConstantsInlining.Test.csproj", "{E9D90B2A-F563-4A5E-9EFB-B1D6B1E7F8CB}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "193_ConstantsInlining.Test", "Tests\193_ConstantsInlining.Test\193_ConstantsInlining.Test.csproj", "{E9D90B2A-F563-4A5E-9EFB-B1D6B1E7F8CB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignatureMismatch2", "Tests\SignatureMismatch2\SignatureMismatch2.csproj", "{3504F678-95FA-4DB2-8437-31A927CABC16}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignatureMismatch2", "Tests\SignatureMismatch2\SignatureMismatch2.csproj", "{3504F678-95FA-4DB2-8437-31A927CABC16}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignatureMismatch2Helper", "Tests\SignatureMismatch2Helper\SignatureMismatch2Helper.csproj", "{02948DD6-47BD-4C82-9B4B-78931DB23B8A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignatureMismatch2Helper", "Tests\SignatureMismatch2Helper\SignatureMismatch2Helper.csproj", "{02948DD6-47BD-4C82-9B4B-78931DB23B8A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignatureMismatch2.Test", "Tests\SignatureMismatch2.Test\SignatureMismatch2.Test.csproj", "{87BEF4D7-813E-48BA-96FE-E3A24BF2DC34}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignatureMismatch2.Test", "Tests\SignatureMismatch2.Test\SignatureMismatch2.Test.csproj", "{87BEF4D7-813E-48BA-96FE-E3A24BF2DC34}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -164,10 +162,6 @@ Global
|
|||
{6C8ECB51-EECE-49C3-89EC-CB0AAECCFF7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6C8ECB51-EECE-49C3-89EC-CB0AAECCFF7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6C8ECB51-EECE-49C3-89EC-CB0AAECCFF7E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{18A3AD8D-DBF6-4489-A407-2972272CC6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{18A3AD8D-DBF6-4489-A407-2972272CC6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{18A3AD8D-DBF6-4489-A407-2972272CC6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{18A3AD8D-DBF6-4489-A407-2972272CC6CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4B2CE997-8157-40B4-B42F-51CE33954AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4B2CE997-8157-40B4-B42F-51CE33954AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4B2CE997-8157-40B4-B42F-51CE33954AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\dnlib\src\dnlib.csproj" />
|
||||
<ProjectReference Include="..\Confuser.UnitTest\Confuser.UnitTest.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
1
dnlib
1
dnlib
|
@ -1 +0,0 @@
|
|||
Subproject commit a42ef1eda187cae5920e59856009510b66b97a97
|
Загрузка…
Ссылка в новой задаче