diff --git a/.gitmodules b/.gitmodules
index 235b722db..e69de29bb 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +0,0 @@
-[submodule "dnlib"]
- path = dnlib
-url=../dnlib.git
\ No newline at end of file
diff --git a/Confuser.Core/Confuser.Core.csproj b/Confuser.Core/Confuser.Core.csproj
index a804950dd..becce7afe 100644
--- a/Confuser.Core/Confuser.Core.csproj
+++ b/Confuser.Core/Confuser.Core.csproj
@@ -17,10 +17,7 @@
-
-
-
-
+
diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs
index 2034a37c3..8749b498d 100644
--- a/Confuser.Core/ConfuserEngine.cs
+++ b/Confuser.Core/ConfuserEngine.cs
@@ -94,11 +94,12 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token)
var asmResolver = new AssemblyResolver();
asmResolver.EnableTypeDefCache = true;
asmResolver.DefaultModuleContext = new ModuleContext(asmResolver);
+ asmResolver.EnableFrameworkRedirect = false;
context.Resolver = asmResolver;
context.BaseDirectory = Path.Combine(Environment.CurrentDirectory, context.Project.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
context.OutputDirectory = Path.Combine(context.Project.BaseDirectory, context.Project.OutputDirectory.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
foreach (string probePath in context.Project.ProbePaths)
- asmResolver.PostSearchPaths.Insert(0, Path.Combine(context.BaseDirectory, probePath));
+ asmResolver.PreSearchPaths.Add(Path.Combine(context.BaseDirectory, probePath));
context.CheckCancellation();
@@ -384,6 +385,8 @@ static void EndModule(ConfuserContext context) {
if (!Path.IsPathRooted(output))
output = Path.Combine(Environment.CurrentDirectory, output);
output = Utils.GetRelativePath(output, context.BaseDirectory);
+ if (Path.IsPathRooted(output))
+ output = Path.GetFileName(output);
}
else {
output = context.CurrentModule.Name;
diff --git a/Confuser.Core/Helpers/InjectHelper.cs b/Confuser.Core/Helpers/InjectHelper.cs
index cc86ad740..b84008dc5 100644
--- a/Confuser.Core/Helpers/InjectHelper.cs
+++ b/Confuser.Core/Helpers/InjectHelper.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
@@ -59,10 +60,9 @@ static FieldDefUser Clone(FieldDef origin) {
/// The new TypeDef.
static TypeDef PopulateContext(TypeDef typeDef, InjectContext ctx) {
TypeDef ret;
- IDnlibDef existing;
- if (!ctx.Map.TryGetValue(typeDef, out existing)) {
+ if (!ctx.MemberMap.TryGetValue(typeDef, out var existing)) {
ret = Clone(typeDef);
- ctx.Map[typeDef] = ret;
+ ctx.MemberMap[typeDef] = ret;
}
else
ret = (TypeDef)existing;
@@ -71,10 +71,10 @@ static TypeDef PopulateContext(TypeDef typeDef, InjectContext ctx) {
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.MemberMap[method] = Clone(method)));
foreach (FieldDef field in typeDef.Fields)
- ret.Fields.Add((FieldDef)(ctx.Map[field] = Clone(field)));
+ ret.Fields.Add((FieldDef)(ctx.MemberMap[field] = Clone(field)));
return ret;
}
@@ -85,12 +85,12 @@ static TypeDef PopulateContext(TypeDef typeDef, InjectContext ctx) {
/// The origin TypeDef.
/// The injection context.
static void CopyTypeDef(TypeDef typeDef, InjectContext ctx) {
- var newTypeDef = (TypeDef)ctx.Map[typeDef];
+ var newTypeDef = (TypeDef)ctx.MemberMap[typeDef];
- newTypeDef.BaseType = (ITypeDefOrRef)ctx.Importer.Import(typeDef.BaseType);
+ 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)));
}
///
@@ -99,7 +99,7 @@ static void CopyTypeDef(TypeDef typeDef, InjectContext ctx) {
/// The origin MethodDef.
/// The injection context.
static void CopyMethodDef(MethodDef methodDef, InjectContext ctx) {
- var newMethodDef = (MethodDef)ctx.Map[methodDef];
+ var newMethodDef = (MethodDef)ctx.MemberMap[methodDef];
newMethodDef.Signature = ctx.Importer.Import(methodDef.Signature);
newMethodDef.Parameters.UpdateParameterTypes();
@@ -151,7 +151,7 @@ static void CopyMethodDef(MethodDef methodDef, InjectContext ctx) {
foreach (ExceptionHandler eh in methodDef.Body.ExceptionHandlers)
newMethodDef.Body.ExceptionHandlers.Add(new ExceptionHandler(eh.HandlerType) {
- CatchType = eh.CatchType == null ? null : (ITypeDefOrRef)ctx.Importer.Import(eh.CatchType),
+ CatchType = eh.CatchType == null ? null : ctx.Importer.Import(eh.CatchType),
TryStart = (Instruction)bodyMap[eh.TryStart],
TryEnd = (Instruction)bodyMap[eh.TryEnd],
HandlerStart = (Instruction)bodyMap[eh.HandlerStart],
@@ -169,7 +169,7 @@ static void CopyMethodDef(MethodDef methodDef, InjectContext ctx) {
/// The origin FieldDef.
/// The injection context.
static void CopyFieldDef(FieldDef fieldDef, InjectContext ctx) {
- var newFieldDef = (FieldDef)ctx.Map[fieldDef];
+ var newFieldDef = (FieldDef)ctx.MemberMap[fieldDef];
newFieldDef.Signature = ctx.Importer.Import(fieldDef.Signature);
}
@@ -192,8 +192,8 @@ static void Copy(TypeDef typeDef, InjectContext ctx, bool copySelf) {
foreach (FieldDef field in typeDef.Fields)
CopyFieldDef(field, ctx);
- }
-
+ }
+
///
/// Injects the specified TypeDef to another module.
///
@@ -204,9 +204,22 @@ public static TypeDef Inject(TypeDef typeDef, ModuleDef target) {
var ctx = new InjectContext(typeDef.Module, target);
PopulateContext(typeDef, ctx);
Copy(typeDef, ctx, true);
- return (TypeDef)ctx.Map[typeDef];
- }
-
+ return (TypeDef)ctx.MemberMap[typeDef];
+ }
+
+ ///
+ /// Imports a as a . This will be either
+ /// a or a .
+ ///
+ /// The source module.
+ /// The method
+ /// The imported method or null if is invalid
+ /// or if we failed to import the method
+ public static IMethod Import(ModuleDef target, MethodBase methodBase) {
+ var ctx = new InjectContext(null, target);
+ return ctx.Importer.Import(methodBase);
+ }
+
///
/// Injects the specified MethodDef to another module.
///
@@ -215,9 +228,9 @@ public static TypeDef Inject(TypeDef typeDef, ModuleDef target) {
/// The injected MethodDef.
public static MethodDef Inject(MethodDef methodDef, ModuleDef target) {
var ctx = new InjectContext(methodDef.Module, target);
- ctx.Map[methodDef] = Clone(methodDef);
+ ctx.MemberMap[methodDef] = Clone(methodDef);
CopyMethodDef(methodDef, ctx);
- return (MethodDef)ctx.Map[methodDef];
+ return (MethodDef)ctx.MemberMap[methodDef];
}
///
@@ -229,20 +242,20 @@ public static MethodDef Inject(MethodDef methodDef, ModuleDef target) {
/// Injected members.
public static IEnumerable Inject(TypeDef typeDef, TypeDef newType, ModuleDef target) {
var ctx = new InjectContext(typeDef.Module, target);
- ctx.Map[typeDef] = newType;
+ ctx.MemberMap[typeDef] = newType;
PopulateContext(typeDef, ctx);
Copy(typeDef, ctx, false);
- return ctx.Map.Values.Except(new[] { newType });
+ return ctx.MemberMap.Values.Except(new[] { newType }).OfType();
}
///
/// Context of the injection process.
///
- class InjectContext : ImportResolver {
+ class InjectContext : ImportMapper {
///
/// The mapping of origin definitions to injected definitions.
///
- public readonly Dictionary Map = new Dictionary();
+ public readonly Dictionary