diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index 96401c98..ba1799a4 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -263,13 +263,10 @@ static void Inspection(ConfuserContext context) { context.Logger.Info("Resolving dependencies..."); foreach (var dependency in context.Modules .SelectMany(module => module.GetAssemblyRefs().Select(asmRef => Tuple.Create(asmRef, module)))) { - try { - context.Resolver.ResolveThrow(dependency.Item1, dependency.Item2); - } - catch (AssemblyResolveException ex) { - context.Logger.ErrorException("Failed to resolve dependency of '" + dependency.Item2.Name + "'.", ex); - throw new ConfuserException(ex); - } + var resolved = context.Resolver.Resolve(dependency.Item1, dependency.Item2); + if (resolved == null) + context.Logger.WarnFormat("Failed to resolve dependency '{0}' of '{1}'. Some protections may not work correctly.", + dependency.Item1.FullName, dependency.Item2.Name); } context.Logger.Debug("Checking Strong Name..."); diff --git a/Confuser.Core/DnlibUtils.cs b/Confuser.Core/DnlibUtils.cs index 42d0ba43..7570da94 100644 --- a/Confuser.Core/DnlibUtils.cs +++ b/Confuser.Core/DnlibUtils.cs @@ -209,15 +209,12 @@ public static bool IsDelegate(this TypeDef type) { /// The full name of base type. /// true if the specified type is inherited from a base type; otherwise, false. public static bool InheritsFromCorlib(this TypeDef type, string baseType) { - if (type.BaseType == null) - return false; - - TypeDef bas = type; - do { - bas = bas.BaseType.ResolveTypeDefThrow(); + var bas = type.BaseType?.ResolveTypeDef(); + while (bas != null && bas.DefinitionAssembly.IsCorLib()) { if (bas.ReflectionFullName == baseType) return true; - } while (bas.BaseType != null && bas.BaseType.DefinitionAssembly.IsCorLib()); + bas = bas.BaseType?.ResolveTypeDef(); + } return false; } @@ -228,15 +225,12 @@ public static bool InheritsFromCorlib(this TypeDef type, string baseType) { /// The full name of base type. /// true if the specified type is inherited from a base type; otherwise, false. public static bool InheritsFrom(this TypeDef type, string baseType) { - if (type.BaseType == null) - return false; - - TypeDef bas = type; - do { - bas = bas.BaseType.ResolveTypeDefThrow(); + var bas = type.BaseType?.ResolveTypeDef(); + while (bas != null) { if (bas.ReflectionFullName == baseType) return true; - } while (bas.BaseType != null); + bas = bas.BaseType?.ResolveTypeDef(); + } return false; } @@ -247,18 +241,12 @@ public static bool InheritsFrom(this TypeDef type, string baseType) { /// The full name of the type of interface. /// true if the specified type implements the interface; otherwise, false. public static bool Implements(this TypeDef type, string fullName) { - do { - foreach (InterfaceImpl iface in type.Interfaces) { - if (iface.Interface.ReflectionFullName == fullName) - return true; - } - - if (type.BaseType == null) - return false; - - type = type.BaseType.ResolveTypeDefThrow(); - } while (type != null); - throw new UnreachableException(); + while (type != null) { + if (type.Interfaces.Any(iface => iface.Interface.ReflectionFullName == fullName)) + return true; + type = type.BaseType?.ResolveTypeDef(); + } + return false; } /// @@ -451,8 +439,8 @@ public static bool IsImplicitImplementedInterfaceMember(this MethodDef method) { if (method.IsPublic && method.IsNewSlot) { foreach (var iFace in method.DeclaringType.Interfaces) { - var iFaceDef = iFace.Interface.ResolveTypeDefThrow(); - if (iFaceDef.FindMethod(method.Name, (MethodSig)method.Signature) != null) + var iFaceDef = iFace.Interface.ResolveTypeDef(); + if (iFaceDef != null && iFaceDef.FindMethod(method.Name, (MethodSig)method.Signature) != null) return true; } }