【问题标题】:C# Member 'System.Char[] System.String::ToCharArray()' is declared in another module and needs to be imported in Mono.CecilC# Member 'System.Char[] System.String::ToCharArray()' 在另一个模块中声明,需要在 Mono.Cecil 中导入
【发布时间】:2017-01-30 03:12:55
【问题描述】:

我使用 Mono.Cecil 在我的程序集中加密我的字符串。

但在

myAssemblyDefinition.Write(myAssemblyPath);

我收到一个错误:

成员 'System.Char[] System.String::ToCharArray()' 在 另一个模块,需要导入

我尝试使用所有这些行导入 String.ToCharArray 方法:

myAssemblyDefinition.MainModule.Import(stringTypeReference.Resolve());
myAssemblyDefinition.MainModule.Import(stringTypeReference.Resolve().Module.Types.Where(x => x.Name == "String").First());
MethodDefinition toCharArrayMethod = stringTypeReference.Resolve().Module.Types.Where(x => x.Name == "String").First().Methods.Where(x => x.Name == "ToCharArray").First();
myAssemblyDefinition.MainModule.Import(toCharArrayMethod);
myAssemblyDefinition.MainModule.Import(typeof(System.String));

但我的问题仍然存在。 我使用ToCharArray 方法将decryptMethod 注入我的程序集。 任何人都可以帮我解决这个问题或 是否有使用 Mono.Cecil 0.9.5 版本加密字符串的示例代码?

【问题讨论】:

    标签: c# obfuscation mono.cecil


    【解决方案1】:

    如果您的目标程序集的运行时版本与您的注入代码的运行时版本相同。 尝试以下几行。

    var toCharArray =
     asm.MainModule.Import(typeof(string).GetMethod("ToCharArray", new Type[] { }));
    proccer.Emit(OpCodes.Callvirt, toCharArray);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 2016-04-23
    • 2022-09-26
    • 1970-01-01
    • 2021-11-28
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多