最近在逆 瑞数6VMP 扣出来的代码需要补环境
使用GPT4o生成了个自吐脚本后稍加修改了下
将其放在代码头运行,会在本地生成log.js,里面有结构化后需要补充的环境

package.json
{
  "dependencies": {
    "rwlock": "^5.0.0"
  }
}
script.js
function getEnvironment(proxyArray) {
    const fs = require("fs");
    const util = require("util");
    const RWLock = require("rwlock");

    const lock = new RWLock();
    const environmentDetails = {};

    proxyArray.forEach((proxyItem) => {
        if (!global[proxyItem]) {
            global[proxyItem] = {};
        }

        const details = (environmentDetails[proxyItem] = {});

        const handler = {
            get(target, property, receiver) {
                const value = target[property];
                if (property == "top") return value;

                if (typeof value == "function") {
                    return function (...args) {
                        if (args[0]?.length > 100) {
                            details[property] = `function('已省略 ${args[0]?.length}') {}`;
                        } else {
                            const formatArgs = args.map((arg, i) => `_${i}_${typeof arg} = ${formatArg(arg)}`);
                            details[property] = `function (${formatArgs.join(", ")}) {}`;
                        }
                        writeToFile(environmentDetails);
                        return value.apply(this, args);
                    };
                } else {
                    details[property] = formatArg(value);
                    writeToFile(environmentDetails);
                    return value;
                }
            },
            set(target, property, value, receiver) {
                details[property] = formatArg(value);
                writeToFile(environmentDetails);
                return Reflect.set(...arguments);
            },
        };
        global[proxyItem] = new Proxy(global[proxyItem], handler);
    });

    function formatArg(arg) {
        if (typeof arg === "function") {
            return arg.toString();
        } else if (typeof arg === "object") {
            return util.inspect(arg, { depth: null, colors: false });
        } else {
            return JSON.stringify(arg);
        }
    }

    function writeToFile(details) {
        const data = "_ = " + util.inspect(details, { depth: null, colors: false });
        lock.writeLock((release) => {
            fs.writeFile("./log.js", data, "utf8", (err) => {
                if (err) {
                    console.error("Error writing file:", err);
                }
                release();
            });
        });
    }
}

getEnvironment(["window", "document", "location", "navigator", "history", "screen", "target"]);