Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frida-compile does not work with external modules #61

Open
Ouroboros opened this issue Jan 30, 2023 · 6 comments
Open

frida-compile does not work with external modules #61

Ouroboros opened this issue Jan 30, 2023 · 6 comments

Comments

@Ouroboros
Copy link

Ouroboros commented Jan 30, 2023

frida-compile version:

16.1.5

OS:

Windows 11

test.ts

https://www.npmjs.com/package/json5

import { parse } from 'json5';

console.log(parse);

compile cmd:

frida-compile test.ts -o test.js

frida output

SyntaxError: Could not find export 'parse' in module '/node_modules/json5/dist/index.mjs'

This code works on frida-compile 10.2.5

@kursattkorkmazzz
Copy link

kursattkorkmazzz commented Nov 26, 2024

same problem :(

I fixed it using esbuild instead frida-compile.

@rubenvereecken
Copy link

@kursattkorkmazzz what does your esbuild config look like? I'm struggling to get frida to handle my generated import/requires for libraries. Looks like frida has its own ESM bundle format.

@kursattkorkmazzz
Copy link

kursattkorkmazzz commented Dec 3, 2024

@rubenvereecken
I just install using npm i -D esbuild

My tsconfig look like;

{
  "compilerOptions": {
    "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include 
    "module": "CommonJS",                                /* Specify what module code is generated. */
    "rootDir": "./src",                                  /* Specify the root folder within your source files. */
     "resolveJsonModule": true,                        /* Enable importing .json files. */
     "allowJs": true,                                  /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get
     "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */
     "outDir": "./dist",                                   /* Specify an output folder for all emitted files. */
     "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. 
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}

My package.json scripts look likse;

  "scripts": {
    "build": "esbuild ./src/main.ts --bundle  --platform=node --outfile=./dist/main-esbuild.js",
    "watch": "esbuild ./src/main.ts --bundle --platform=node --outfile=./dist/main-esbuild.js --watch",
    "frida": "frida -U -f re.frida.Gadget -l ./dist/main-esbuild.js"
  }

And it just worked. But don't forget the --platform=node and --bundle parameters for esbuild.

@rubenvereecken
Copy link

@kursattkorkmazzz I'm really surprised you got that to work – what do your imports get compiled to?

Because reusing your tsconfig and esbuild command, I still get requires in the final script, which frida doesn't like:

ReferenceError: 'require' is not defined
    at <eval> (dist/esbuild.js:3110)

I also tried --runtime=v8, but same problem. That's on frida v16.5.6.

Wondering whether it's got something to do with you loading re.frida.Gadget rather than injecting. That's the only difference I can see (assuming your compiled script still uses require).

@kursattkorkmazzz
Copy link

kursattkorkmazzz commented Dec 9, 2024

@rubenvereecken Firstly, sorry for late answering.

Actually my output doesn't contain any import or require terms. All codes are built into one file.

This is my example output file how looks like: Drive


Because my device is not rooted, I prefer to choose gadget. I know that (not sure), even I use re.frida.gadget, It uses script for injecting. Also, your build file shouldn't contain any import or require statment as mine. You may need to adjust your configuration.


You use esbuild with --bunde and --platform parameters, right?

@rubenvereecken
Copy link

@kursattkorkmazzz amazing, thanks for all this help and input!

I should have dug deeper. Yes, I'm using --bundle, which apparently really should combine everything into one self-contained JS file. But on closer inspection, two modules are resisting this: common/file.ts from frida itself and frida-fs. All the others are successfully compiled without require. I'll do a bit more digging later to see what I can do about these!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants