frida / frida-tools

Frida CLI tools
Other
338 stars 95 forks source link

Cannot access variables in scripts in the interactive shell #110

Closed Apeng7364 closed 2 years ago

Apeng7364 commented 2 years ago

After upgrade to frida-tools 11.0.0, cannot access variables in scripts in the interactive shell script:

var a = 0;
console.log(a);

run frida and print variable a in the interactive shell:

❯ frida -f ./a -l ./a.js
     ____
    / _  |   Frida 15.2.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)
Spawning `./a`...
0
Spawned `./a`. Use %resume to let the main thread start executing!
[Local::a ]-> a
ReferenceError: 'a' is not defined
oleavr commented 2 years ago

This is now accomplished by explicitly adding properties to globalThis. E.g. to expose a function as a:

globalThis.a = function () {
};

And to expose more than one with minimal boilerplate you can do something like:

function a() {
}

function b() {
}

Object.assign(globalThis, { a, b });