使用dnlib启用不安全的代码 [英] Enable unsafe code with dnlib
本文介绍了使用dnlib启用不安全的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢!!
我尝试过:
试图找到如何使用dnlib声明模块将包含不安全的代码。我在文档中找不到任何内容。
解决方案
我不能代表dnlib,但标准编译器标记了不安全的模块 [System.Security.UnverifiableCodeAttribute()]
最简单的检测就像
private void SafeOrUnsafe(程序集asm){
foreach(模块m in asm.GetModules(true)){
Debug.Print({0} Unsafe:{1},m.Name,m.IsDefined(typeof( System.Security.UnverifiableCodeAttribute),true));
}
}
Alan。
经过多次挖掘,我发现你可以标记使用以下代码的dnlib模块不安全:
ModuleDefMD module = ModuleDefMD.Load( < span class =code-string> theModuleYouWantToMarkAsUnsafe.exe);
module.CustomAttributes.Add( new CustomAttribute( new MemberRefUser(module, 。ctor,MethodSig.CreateInstance(module.CorLibTypes.Void),module.CorLibTypes.GetTypeRef( System.Security, < span class =code-string> UnverifiableCodeAttribute))));
我非常感谢@Alan指出工作需要什么属性!
Hello ! I am coding an obfuscator using C# and dnlib. At some point i need to inject unsafe code in the executable but this should end up in an app crash, if you don't "declare" it . Is there a way to declare(with or without dnlib) that a selected module will contain unsafe code ?
Thanks!!
What I have tried:
Tried to find how to declare that a module will contain unsafe code using dnlib. I couldn't find anything in the docs.
解决方案
I can't speak for dnlib but the standard compiler marks unsafe modules with the [System.Security.UnverifiableCodeAttribute()]
The simplest detection would be something like
private void SafeOrUnsafe(Assembly asm) { foreach (Module m in asm.GetModules(true)) { Debug.Print("{0} Unsafe : {1}", m.Name, m.IsDefined(typeof(System.Security.UnverifiableCodeAttribute), true)); } }
Alan.
After some more digging, i found out that you can mark a module as unsafe with dnlib with the following code:
ModuleDefMD module = ModuleDefMD.Load("theModuleYouWantToMarkAsUnsafe.exe"); module.CustomAttributes.Add(new CustomAttribute(new MemberRefUser(module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), module.CorLibTypes.GetTypeRef("System.Security", "UnverifiableCodeAttribute"))));
I thank very much @Alan for pointing out what attribute is needed for the job !
这篇关于使用dnlib启用不安全的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文