Code Virtualization

发布于 2 天前  13 次阅读


Information about Code is scattered across the web, so I compiled this guide for reference.

Ready to learn more? Subscribe to our newsletter for weekly tutorials and tips.

正文

The Common Intermediate Language (CIL) is a set of platform-independent instructions generated by the language-specific compiler (C#, VB.NET...) from the source code. The CIL is platform-independent and can be executed on any Common Language Infrastructure supported environments such as the .NET runtime or Mono.

The way how the CIL and other metadata is stored must follow a specific standard (ECMA-335). This way tools like .NET Reflector or ILSpy can read the CIL instructions and translate the code back to its source language (C#, VB.NET...).

Code Virtualization converts the CIL code into a set of randomized instructions which are interpreted at runtime by our virtual machine. As there is no standardized procedure to interpret the new instruction set correctly, the original CIL instructions can't be reconstructed. Consequently, the virtualized code can't be translated back to its source language.

As the performance of virtualized methods is significantly decreased, code virtualization should only be applied to selected methods.

To enable code virtualization you need to decorate the corresponding methods with the following attribute:

[System.Reflection.ObfuscationAttribute(Feature = "Virtualization", Exclude = false)]

[System.Reflection.Obfuscation(Feature = "Virtualization", Exclude = false)]

public void CreateFile(string filename, string content)

string directory = Path.GetDirectoryName(filename) ;

StreamWriter streamWriter = new StreamWriter(File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)); streamWriter .Write(content);

The remaining stub code executes the virtual machine. Compress & Encrypt Resources

More Details

There are a few more points worth noting. First, browser compatibility varies across different browsers. Second, performance optimization is crucial when handling large amounts of data. Finally, key management is also an important consideration.

Due to length constraints, I'll wrap up here. More practical examples coming soon. Leave a comment if you have questions!

Reference: Code Virtualization


点击体验一键VMP加密 |下滑查看JSVMP相关文章