frida / frida-compile

Compile a Frida script comprised of one or more Node.js modules
Other
190 stars 48 forks source link

`session.create_script(path)` fails when importing from node_modules #78

Open Myles1 opened 1 year ago

Myles1 commented 1 year ago

I'm using typescript for a frida module that's being loaded on Android.

Reproduction steps: git clone https://github.com/oleavr/frida-agent-example.git cd frida-agent-example npm install npm run build

Create this python file:

import frida
import pathlib
process_name: str = "My android app"
def main():
    device: frida.core.Device = frida.get_usb_device()
    sess: frida.core.Session
    sess = device.attach(process_name)
    script_path: pathlib.Path = pathlib.Path("_agent.js")
    assert script_path.exists()
    script: frida.core.Script = sess.create_script(script_path.read_text())
    script.load()
if __name__ == "__main__":
    main()

That all works, but when I add a package: npm install --save rxjs Then import that package in index.ts:

import {Observable} from "rxjs";
let observable = new Observable();

Then build again npm run build The build step completes, but when I try to load the script through python I'm getting this error:

Traceback (most recent call last):
  File "/home/myles/frida-agent-example/frida-gadget-main.py", line 13, in <module>
    main()
  File "/home/myles/frida-agent-example/frida-gadget-main.py", line 10, in main
    script: frida.core.Script = sess.create_script(script_path.read_text())
  File "/home/myles/frida-agent-example/venv/lib/python3.10/site-packages/frida/core.py", line 86, in wrapper
    return f(*args, **kwargs)
  File "/home/myles/frida-agent-example/venv/lib/python3.10/site-packages/frida/core.py", line 628, in create_script
    return Script(self._impl.create_script(source, **kwargs))  # type: ignore
frida.InvalidArgumentError: could not load module '/node_modules/rxjs/dist/esm5/internal/Observable'

Any ideas on what I'm doing wrong here? How can I get it to pick up imports from node_modules?

Myles1 commented 1 year ago

Side-note, esbuild seems to work correctly as a replacement in this case