[英]CompileAssemblyFromSource + Obfuscation = don't work
我有工作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();
}
}
}
對不起,我的問題。 我只是理解為什么會發生)這是示例代碼。 我從服務器獲取的代碼存在的主要問題。 因此,當我混淆我的變量時,我不會在與CompileAssemblyFromSource一起使用的“在線”代碼中混淆它們。 所以這根本行不通。 因為var沒有相同的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.