C# 混淆 .NET 可执行文件破坏了加载程序集的使用

如何解决C# 混淆 .NET 可执行文件破坏了加载程序集的使用

我正在尝试为我的 .NET 4.7.2 Framework 应用编写插件系统。

我已经写了代码但是有一个问题,当应用程序被混淆时,插件系统在启动时抛出错误

下面两张图片很可能可以解释错误,但我也会提供文本的复制和粘贴。

Error Part 1

Error Part 2

错误文本:

   System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at @ӛ.<>c.<Loadplugins>b__4_0(Assembly a)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at @ӛ.@ӗ()
   at @Ӗ..ctor()
   at @Ӕ.<checkForPrevIoUsLogin>d__2.MoveNext()
   at System.Runtime.CompilerServices.AsyncmethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)

加载插件代码段:

public class PluginLoader
    {
        public static List<IPlugin> Plugins { get; set; }

        public void Loadplugins()
        {
            Plugins = new List<IPlugin>();

            //Load the DLLs from the Plugins directory
            if (Directory.Exists(Constants.folderName))
            {
                string[] files = Directory.GetFiles(Constants.folderName);
                foreach (string file in files)
                {
                    if (file.EndsWith(".dll"))
                    {
                        Constants.raidTool.log("Loading Plugin File: " + Path.GetFullPath(file));
                        Assembly.LoadFile(Path.GetFullPath(file));
                    }
                }
            }

            Type interfaceType = typeof(IPlugin);
            //Fetch all types that implement the interface IPlugin and are a class
            Type[] types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(a => a.GetTypes())
                .Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass)
                .ToArray();
            foreach (Type type in types)
            {
                //Create a new instance of all found types
                Plugins.Add((IPlugin)Activator.CreateInstance(type));
            }
            
            foreach (IPlugin plugin in Plugins)
            {
                plugin.Start();
            }
        }
        public void ShutdownPlugins()
        {
            foreach (IPlugin plugin in Plugins)
            {
                plugin.Shutdown();
            }
        }
        public void WebRequestPlugin(HttpWebRequest request)
        {
            foreach (IPlugin plugin in Plugins)
            {
                plugin.OnNetworkRequest(request);
            }
        }
    }

请记住此错误不会在应用程序未混淆时发生。

我还尝试了不同的混淆器,例如 ConfuserEx 或 this "free obfuscator"

我也肯定这些错误是由插件系统引起的,因为当没有插件加载混淆版本时,这样做没有问题。

如果您需要我澄清或解释某些事情,请告诉我!

我还会向其他免费的混淆器推荐一些长期,因为它们可以很好地保护我的代码并且可以很好地使用此插件加载设置(顺便说一句,Constants.Foldername 只是“插件”) >

我对堆栈溢出还是很陌生,所以如果我搞砸了,我真的很抱歉!

解决方法

我会避免在任何使用混淆的项目上使用反射。反射查看组件的方式与您试图阻止人们查看您的组件的方式相同。换句话说,如果反射工作得很好,那么你就没有保护你的代码。

相关阅读: Should you obfuscate a commercial .Net application?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?