【问题标题】:CompileAssemblyFromSource + Obfuscation = don't workCompileAssemblyFromSource + 混淆 = 不起作用
【发布时间】:2015-08-24 23:27:57
【问题描述】:

我有工作 CompileAssemblyFromSource 代码。但是,当我使用 RedGate SmartAssembly 或 Themida 等任何代码保护器时,它会停止工作,并且出现错误“无法加载文件或程序集或其依赖项之一”。你能帮帮我吗?

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();
        }
    }
}

【问题讨论】:

    标签: c# obfuscation compileassemblyfromsource


    【解决方案1】:

    对不起我的问题。我只是明白为什么会这样) 这是代码示例。我从服务器获取的代码的主要问题。 因此,当我混淆我的变量时,我不会在我与 CompileAssemblyFromSource 一起使用的“在线”代码中混淆它们。所以这根本行不通。因为 var 没有相同的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      相关资源
      最近更新 更多