vfsfitvnm / frida-il2cpp-bridge

A Frida module to dump, trace or hijack any Il2Cpp application at runtime, without needing the global-metadata.dat file.
https://github.com/vfsfitvnm/frida-il2cpp-bridge/wiki
MIT License
1.03k stars 202 forks source link

TypeScript error after transpiling #155

Closed carlosotgz closed 2 years ago

carlosotgz commented 2 years ago

Hello,

It's been a while that I haven't used this project. I've been trying to create a dummy agent to start playing with the library again but I'm getting an error message during compilation, even with the examples provided in the Snippets section of the Wiki. More details below.

Creating a new Frida project:

$ frida-create -n test -o agent agent
Created agent/package.json
Created agent/tsconfig.json
Created agent/agent/index.ts
Created agent/agent/logger.ts
Created agent/.gitignore

Run `npm install` to bootstrap, then:
- Keep one terminal running: npm run watch
- Inject agent using the REPL: frida Calculator -l _agent.js
- Edit agent/*.ts – REPL will live-reload on save

Tip: Use an editor like Visual Studio Code for code completion, inline docs,
     instant type-checking feedback, refactoring tools, etc.

I replaced the default agent.ts with the following:

import "frida-il2cpp-bridge";

Il2Cpp.perform(() => {
    // code here
    console.log(Il2Cpp.unityVersion);
});

And then I just follow the steps described above (I tried using the tsconfig.json file provided in the docs here to no avail):

$ cd agent; npm install
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.

> test-agent@1.0.0 prepare
> npm run build

> test-agent@1.0.0 build
> frida-compile agent/index.ts -o _agent.js -c

npm install
added 257 packages, and audited 258 packages in 14s

45 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
 %

Finally, I install frida-il2cpp-bridge

$ npm install --save frida-il2cpp-bridge

added 4 packages, and audited 262 packages in 3s

45 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

And here is where things fail:

$ npm run watch

> test-agent@1.0.0 watch
> frida-compile agent/index.ts -o _agent.js -w

Compilation failed: TypeScript error: .../agent/node_modules/frida-il2cpp-bridge/dist/il2cpp/api.d.ts(4,26): Error TS2315: Type 'NativeFunction' is not generic.

And, just in case it's useful, this is my package.json file after all the previous commands are run:

{
  "name": "test-agent",
  "version": "1.0.0",
  "description": "Frida agent written in TypeScript",
  "private": true,
  "main": "agent/index.ts",
  "scripts": {
    "prepare": "npm run build",
    "build": "frida-compile agent/index.ts -o _agent.js -c",
    "watch": "frida-compile agent/index.ts -o _agent.js -w"
  },
  "devDependencies": {
    "@types/frida-gum": "^16.2.0",
    "@types/node": "^14.14.10",
    "frida-compile": "^10.0.0"
  },
  "dependencies": {
    "frida-il2cpp-bridge": "^0.7.9"
  }
}

Is this maybe a bug in the latest version?

vfsfitvnm commented 2 years ago

Hi, it looks like both yours frida-compile and @types/frida-gum are outdated, they are at 10.2.5 and 18.0.0, respectively

carlosotgz commented 2 years ago

Oh, that did the trick. Thanks a lot! I guess my version of frida-compile is using outdated versions of those libs? I'm quite unfamiliar with the Node/npm/TypeScript ecosystem 🤦