认识js vmp
js vmp其实就是一个微型解释器,然后传入一串很长的字符串或者指令集映射为原生 JS 逻辑然后进行加密,也是相混淆一样对代码进行保护的作用,他总体代码如下:
javascript
// 1. VM核心
function VM() {
this.stack = [];
this.ip = 0;
this.run = function(bytecode) {
while (this.ip < bytecode.length) {
const op = bytecode[this.ip];
switch(op) {
case 0x01: this.stack.push(bytecode[++this.ip]); this.ip++; break;
case 0x02:
const a = this.stack.pop();
const b = this.stack.pop();
this.stack.push(a + b);
this.ip++;
break;
}
}
return this.stack.pop();
};
}
// 2. 字节码(业务逻辑:输入值+10)
function genBytecode(input) {
return [0x01, input, 0x01, 10, 0x02];
}
// 3. 沙箱
const sandbox = { Math: { random: () => Math.random() } };
// 4. 桥接层
function bridge(input) {
antiDebug(); // 先执行反逆向
const bytecode = genBytecode(Number(input));
const vm = new VM();
return vm.run(bytecode);
}
// 5. 反逆向层
function antiDebug() {
if (window.outerHeight - window.innerHeight > 200) {
throw new Error("禁止调试!");
}
}
// 测试调用
try {
console.log(bridge(20)); // 输出30
} catch (e) {
console.log(e.message);
}
当我们遇到长字符串然后有个大循环里面还有switch case 语句(或 if 嵌套)时很可能就是JS vmp,给大家看一个典型的jsvmp的例子(X日头条):



解决办法:当你有很强的js代码阅读能力时可以跟下来然后扣代码或者纯算,要不就直接全扣然后补环境
小结
本文到此结束,JS VMP本人理解其实就是混淆加强版,看不懂就去全扣补环境就行,加油加油