Design of WebAssembly-Based Virtual Interpreter

发布于 2023-08-07  197 次阅读


previous article:Instruction Encoding

The previous articles described the process of JavaScript code virtualization and provided examples of virtual instruction design and JavaScript implementation of the interpreter program. Code virtualization protection requires a special virtual interpreter at runtime to interpret bytecode programs and restore the functionality of the target code. In general, to enable the virtual machine protection module to run smoothly in the browser, a JavaScript implementation of the virtual interpreter can be used. However, in this case, the logic of the virtual interpreter is fully exposed to users, making its execution vulnerable.

WebAssembly also runs in the JavaScript virtual machine, but it offers performance closer to native code and can freely interact with JavaScript without conflict. Moreover, WebAssembly is a binary format, and its compilation process allows for optimization operations, making it difficult to reverse engineer business logic and thus providing more security. Therefore, this article adopts WebAssembly technology to implement the virtual interpreter module for JavaScript code virtualization protection. Currently, there are several languages that support compilation to WebAssembly, with C being the most commonly used. Therefore, this article uses C language to write the target structure code and compiles it into a WASM module using the Emscripten compiler.

However, JavaScript code contains a large number of DOM objects and properties not currently supported by WebAssembly, making it impossible to directly implement all critical data structures using C definitions. In the design, JavaScript code is used to participate in the implementation of these related data structures, such as Handler and VMcontext. This is primarily based on Emscripten's ability to allow C/C++ code to communicate with JavaScript. By using macros in the table below, we can inline JavaScript code in C to achieve the relevant operations. The following sections will provide a detailed introduction to the core component design, compilation, and invocation process of the virtual interpreter.

JS一键VMP加密 jsvmp.com


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