安装frida-il2cpp-bridge模块遇错求助:ReferenceError: 'exports'未定义
解决frida-il2cpp-bridge启动时
ReferenceError: 'exports' is not defined报错 问题复现
执行Frida脚本时触发如下报错:
Spawned `com.games`. Resuming main thread! ReferenceError: 'exports' is not defined at <anonymous> (/node_modules/frida-il2cpp-bridge/dist/index.js:2)
环境信息:
- Node.js v16.16.0
- npm 8.14.0
解决方案
1. 调整TypeScript编译配置
修改项目根目录的tsconfig.json,适配Frida的V8运行环境(不兼容Node.js的CommonJS模块规范):
{ "compilerOptions": { "target": "ES6", "module": "ESNext", "moduleResolution": "node", "outDir": "./dist", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "include": ["src/**/*"] }
module设为ESNext/ES6:Frida环境支持ES模块语法,避免生成CommonJS的exports代码target设为ES6:保证语法与目标环境兼容
2. 修正脚本引入逻辑
不要使用Node.js的require语法,改用ES模块导入或直接调用全局Il2Cpp对象:
// src/script.ts import * as Il2Cpp from 'frida-il2cpp-bridge'; async function main() { await Il2Cpp.initialize(); // 你的业务逻辑代码 } main().catch(console.error);
编译后用Frida加载编译产物:
frida -U -f com.games -l dist/script.js
3. 直接使用Frida专用预编译脚本
若自行编译仍有问题,可跳过本地编译,直接使用适配Frida的预编译文件:
- 从
node_modules/frida-il2cpp-bridge/dist目录复制index.js到脚本目录 - 在主脚本中通过
script.load加载:
// script.js Il2Cpp = {}; await script.load('./index.js'); await Il2Cpp.initialize(); // 后续业务逻辑
4. 校验Frida版本兼容性
确保Frida与frida-il2cpp-bridge版本匹配:
- 执行
frida --version查看当前版本,建议使用v15.0及以上 - 版本过低则执行更新:
npm install -g frida-tools
验证方法
编译并重新运行脚本,若不再出现exports未定义报错,且能正常调用Il2Cpp相关API,则问题解决。
内容的提问来源于stack exchange,提问作者john whynot
相关产品推荐
相关产品推荐

