首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CompileAssemblyFromSource +混淆=不工作

CompileAssemblyFromSource +混淆=不工作
EN

Stack Overflow用户
提问于 2015-08-24 23:27:57
回答 1查看 170关注 0票数 1

我有工作的CompileAssemblyFromSource代码。但是当我使用RedGate、SmartAssembly或Themida这样的代码保护程序时,它就停止工作了,并且我得到了错误,“无法加载文件或程序集或它的依赖项之一”。你能帮我一下吗?

代码语言:javascript
复制
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.CSharp;

namespace stringToCode
{
    public class Program
    {
        public static int q = 0;
        static void Main(string[] args)
        {
            try
            {
                string source = "namespace stringToCode { public class FooClass { public void Execute() { Program.q = 1; } } }";

                Console.WriteLine("q=" + q);
                using (var foo = new CSharpCodeProvider())
                {
                    var parameters = new CompilerParameters();
                    parameters.GenerateInMemory = true;

                    foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        try
                        {
                            string location = assembly.Location;
                            if (!String.IsNullOrEmpty(location))
                            {
                                parameters.ReferencedAssemblies.Add(location);
                            }
                        }
                        catch (NotSupportedException)
                        { }
                    }

                    var res = foo.CompileAssemblyFromSource(parameters, source);
                    var type = res.CompiledAssembly.GetType("stringToCode.FooClass");
                    var obj = Activator.CreateInstance(type);
                    var output = type.GetMethod("Execute").Invoke(obj, new object[] { });

                    Console.WriteLine("q=" + q);
                }
            }
            catch (Exception e)
            {
               Console.WriteLine(e.Message);;
            }
            Console.ReadLine();
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-24 23:57:19

很抱歉回答我的问题。我只是理解为什么会发生这种情况),这是代码的例子。我从服务器获得的代码存在的主要问题。因此,当我混淆我的vars时,我不会在我与CompileAssemblyFromSource一起使用的“在线”代码中混淆它们。所以这是行不通的。因为vars没有相同的名字。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32193302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档