frida / frida-compile

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

"Require is not defined" #56

Closed Areizen closed 2 years ago

Areizen commented 2 years ago

Hi,

I'm trying to use frida-compile, when compiling binaries and then executing them with frida i'm getting the error require is not defined It seems like require() functions are not removed from the compiled sources ?

Reproduction

main.js

const a = require("./lib")
console.log(a())

lib.js

export default {
    a : function(){
        return 1;
    }
}

execution :

➜  test-frida-compile $ frida-compile test.js -o test-compiled.js
➜  test-frida-compile $ frida -l test-compiled.js -f /bin/ls 
     ____
    / _  |   Frida 16.0.2 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to Local System (id=local)
Spawned `/bin/ls`. Resuming main thread!                                
ReferenceError: 'require' is not defined
    at <anonymous> (test.js:1)

Versions

node : v16.17.1 frida-compile : v16.1.3 frida : 16.0.2

londek commented 2 years ago

Hey, please use import statement - require is stricte runtime function in node (frida doesn't integrate node environment, it's just V8/qjs). import is processed compile-time and therefore is used by frida-compile + frida itself (as a result of frida-compile).

Areizen commented 2 years ago

Thank you :)