Git Product home page Git Product logo

frida-node's Introduction

frida-node

NPM version NPM Downloads

Node.js bindings for Frida.

Depends

  • Node.js 8.x or newer

Install

Install from binary:

$ npm install frida

Install from source:

$ make
$ npm install

Build for Electron:

$ ./configure --with-runtime=electron --with-target=27.0.0
$ make
$ npm install

Examples

  • Follow Setting up the experiment to produce a binary.
  • Run the binary.
  • Take note of the memory address the binary gives you when run.
  • Run any of the examples, passing the name of the binary as a parameter, and the memory address as another.

(Note: only some examples use the memory address)

Developing

To recompile only the C++ files that have changed, first run the "Install from source" step above, then simply run make again.

Packaging

$ ./configure --with-runtime=electron --with-target=27.0.0
$ make prebuild

frida-node's People

Contributors

chichou avatar dependabot[bot] avatar dweinstein avatar greenkeeperio-bot avatar mrmacete avatar oleavr avatar ralphtheninja avatar someoneweird avatar superpaintman avatar zachqin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frida-node's Issues

Backtrace absent from thrown errors

So I just learned this, but apparently, in nodejs, the code

async function run() {
  throw "Random error.";
}
function onError(err) {
  console.error(`[*] Fatal Error: ${err.message}`);
  console.trace(err);
}
run().catch(onError);

will produce a trace as follows:

[*] Fatal Error: undefined
Trace: Random error.
    at onError (./errtest.js:6:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

The problem being, the stack trace does not include the frame at which the error occurred (in this case, line 2). This makes it extremely difficult to debug complex apps.

Apparently, the solution is to, instead of:

throw "Random error.";

.. use:

throw new Error("Random error.");

This produces the following backtrace:

[*] Fatal Error: Random error.
Trace: Error: Random error.
    at run (./errtest.js:2:9)
    at Object.<anonymous> (./errtest.js:8:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
    at onError (./errtest.js:6:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

.. which is infinitely more helpful.

Currently, this package uses the (v8 equivalent of the) first syntax.

Due to frida/frida#592, I currently cannot test this out, but it would seem that this is an easy fix:
Given, say:

Nan::ThrowTypeError("Bad argument, expected Buffer");

.. instead use:

Nan::ThrowTypeError(new Nan::TypeError("Bad argument, expected Buffer"));

Could this change be made globally in this repo?

Official TypeScript support

I came across a project for adding definitions for TypeScript here. However, I'm not sure if/how much it's out of date, and it also isn't published under the npm @types org so consuming the definitions is not the most straightforward thing. Has there been any discussion around adding official typings or - perhaps eventually - even a typescript rewrite?

npm install fails on macOS

I use Node v11.11.0 on macOS Mojave. Doing npm i frida gives below error

[email protected] install /Users/mustafa/Downloads/mplus-master/node_modules/frida
prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=11.11.0 runtime=node arch=x64 libc= platform=darwin)
gyp: binding.gyp not found (cwd: /Users/mustafa/Downloads/mplus-master/node_modules/frida) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:197:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/Cellar/node/11.11.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/mustafa/Downloads/mplus-master/node_modules/frida
gyp ERR! node -v v11.11.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mustafa/.npm/_logs/2019-05-28T21_15_38_202Z-debug.log

What is the function of require('frida-load');

Question_01:

const frida_load = require('frida-load');
frida_load("example.js");
fs.readFileSync("example.js", 'utf8');

What is the difference between the above two way ?

Question_02:
where can I find the api document for frida-node?

Java.enumerateLoadedClasses throws an error (access violation)

While trying to use Java.enumerateLoadedClasses I get the following error:

{ type: 'error',
description: 'Error: access violation accessing 0x0',
stack: 'Error: access violation accessing 0x0\n at _enumerateLoadedClasses (frida/node_modules/frida-java/index.js:98:30)\n at Runtime.value [as enumerateLoadedClasses] (frida/node_modules/frida-java/index.js:145:7)\n at agent.js:446:8\n at VM.perform (frida/node_modules/frid
a-java/lib/vm.js:35:7)\n at performPending (frida/node_modules/frida-java/index.js:221:14)\n at frida/node_modules/frida-java/index.js:196:15\n at VM.perform (frida/node_modules/frida-java/lib/vm.js:35:7)\n at Runtime.perform (frida/node_modules/frida-java/index.js:191:14)\n at Object
.1 (agent.js:5:7)\n at s (node_modules/frida-load/node_modules/browserify/node_modules/browser-pack/_prelude.js:1:1)',
fileName: 'frida/node_modules/frida-java/index.js',
lineNumber: 98,
columnNumber: 30 }

I remember using this function at the beginning of the year and it worked.

My device is a Samsung Note 3 rooted running android 4.3

I also tested with an emulator and I got the same error.

Correct way to get args in onLeave?

The testMethod has a pointer argument which will be modified in the method. I need to read its value in onLeave. Right now I had to store the variable in onEnter then read it in onLeave.

I'm wondering if there's a better way to do that? It's not healthy for multithread programs.

    let data = null
    Interceptor.attach(testMethod, {
        onEnter: function (args) {
            data = args[4]
        },
        onLeave: function (retval) {
            console.log(Memory.readInt(data))           
        }
    });

Requesting linux-musl build

Hi, I'm failed to install frida inside alpine docker, I see the verbose log:

npm ERR! prebuild-install http request GET https://github.com/frida/frida/releases/download/15.2.2/frida-v15.2.2-node-v88-linuxmusl-x64.tar.gz
npm ERR! prebuild-install http 404 https://github.com/frida/frida/releases/download/15.2.2/frida-v15.2.2-node-v88-linuxmusl-x64.tar.gz
npm ERR! prebuild-install warn install No prebuilt binaries found (target=15.10.0 runtime=node arch=x64 libc=musl platform=linux)

Are there any plans to provide the musl rebuild binary? Thanks very much.

frida/frida#556
node-gfx/node-canvas-prebuilt#77

frida-v12.5.6-electron-v70 Incorrect NODE_MODULE_VERSION

This issue is related to:
#40

When trying to integrate frida with electron I am getting the following error message:

node_modules\frida\build\Release\frida_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 47. This version of Node.js requires
NODE_MODULE_VERSION 70.

Repro

Install a simple boilerplate like so:

set npm_config_runtime=electron
set npm_config_target=5.0.0
npm init
npm install [email protected]
npm install frida

Fill in some basic elements in the core JS to spawn a Window and then include a JS file that has:

const frida = require('frida');

Notes

I have only tested this on Windows (which is where I am developing), please take this into account. I assume here that there is just a bug where the package is reporting the wrong NODE_MODULE_VERSION number as that package should support "70".

Electron NODE_MODULE_VERSION mismatch

I tried to incorporate Frida into electron, I am using npm for installation:

C:\.........\frida-test>npm view electron version
5.0.1

C:\.........\frida-test>npm view frida version
12.5.6

But on launch I am getting a NODE_MODULE_VERSION mismatch.

......\node_modules\frida\build\Release\frida_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 70.

Looking at the Frida releases I see electron v70 should supported right?
https://github.com/frida/frida/releases

Am I missing something here (I am a bit new to node still..).

Build failed on Node v12

frida-node build failed on Node V12, below is the make error:

make node-macos

> [email protected] install /Users/gebing/frida/frida-node
> prebuild-install || node-gyp rebuild

  CXX(target) Release/obj.target/frida_binding/src/addon.o
In file included from ../src/addon.cc:1:
In file included from ../src/application.h:4:
In file included from ../src/glib_object.h:4:
../src/runtime.h:22:41: error: no template named 'Handle' in namespace 'v8'
  v8::Local<v8::String> ValueToJson(v8::Handle<v8::Value> value);
                                    ~~~~^
../src/runtime.h:23:42: error: no template named 'Handle' in namespace 'v8'
  v8::Local<v8::Value> ValueFromJson(v8::Handle<v8::String> json);
                                     ~~~~^
../src/runtime.h:25:31: error: no template named 'Handle' in namespace 'v8'
  static bool ValueToStrv(v8::Handle<v8::Value> value, gchar*** strv,
                          ~~~~^
../src/runtime.h:29:31: error: no template named 'Handle' in namespace 'v8'
  static bool ValueToEnvp(v8::Handle<v8::Value> value, gchar*** envp,
                          ~~~~^
../src/runtime.h:33:31: error: no template named 'Handle' in namespace 'v8'
  static bool ValueToEnum(v8::Handle<v8::Value> value, GType type,
                          ~~~~^
In file included from ../src/addon.cc:1:
../src/application.h:13:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:2:
../src/child.h:12:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:3:
../src/crash.h:12:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:4:
../src/device.h:13:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:5:
../src/device_manager.h:12:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:7:
../src/icon.h:13:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:8:
../src/process.h:12:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:10:
../src/script.h:13:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:11:
../src/session.h:13:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:12:
../src/signals.h:15:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
In file included from ../src/addon.cc:13:
../src/spawn.h:12:24: error: no template named 'Handle' in namespace 'v8'
  static void Init(v8::Handle<v8::Object> exports, Runtime* runtime);
                   ~~~~^
../src/addon.cc:19:11: error: no member named 'Handle' in namespace 'v8'
using v8::Handle;
      ~~~~^
../src/addon.cc:27:13: error: variable has incomplete type 'void'
static void InitAll(Handle<Object> exports,
            ^
../src/addon.cc:27:28: error: 'Object' does not refer to a value
static void InitAll(Handle<Object> exports,
                           ^
/Users/gebing/.node-gyp/12.1.0/include/node/v8.h:3356:17: note: declared here
class V8_EXPORT Object : public Value {
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [Release/obj.target/frida_binding/src/addon.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:256:12)
gyp ERR! System Darwin 18.5.0
gyp ERR! command "/usr/local/Cellar/node/12.1.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/gebing/frida/frida-node
gyp ERR! node -v v12.1.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gebing/.npm/_logs/2019-05-16T03_35_51_904Z-debug.log
make[1]: *** [build/frida-macos-x86_64/lib/node_modules/frida] Error 1
make: *** [node-macos] Error 2

I am using MacOSx 10.14.4, Xcode 9.4.1, Node.js 12.1.0.

I google the error and it says it is becuase Node.js v12's v8.h is incompatiable with old version.

Require in electron failed

First of all stable electron (1.7.9) is based on nodeJS 7.9 so I'm using electron 1.8.1 beta which is based in node 8.2.1.

Steps to reproduce:

  1. Download some electron-quickstart (and make sure it works)
  2. Put this code at the end of the entry javascript file:
//TODO: Why this breaks?!
console.log(process.version);
try{
    console.log('1');
    const j = require('./frida/frida.js');
    console.log(j);
} catch (e){
    console.log('2');
    console.log(e);
} finally {
    console.log('3')
}
console.log('4');
  1. Enjoy the disappearance of the application and this output:
➜  src git:(ui) ✗ node_modules/.bin/electron main.js
v8.2.1
1

It imports fine in vanilla Node 8.2.1 without electron.
[Might be an electron issue]

Cannot install prebuilt frida-node on linux

On Debian 8 x64, nodejs 0.12.9, when doing npm install frida the procedure fails by missing the "frida-core.h":

user@hhvm1:/tmp$ npm install frida
|
> [email protected] install /tmp/node_modules/frida
> prebuild --download

prebuild WARN install connect ECONNREFUSED
make: Entering directory '/tmp/node_modules/frida/build'
  CXX(target) Release/obj.target/frida_binding/src/addon.o
In file included from ../src/runtime.h:4:0,
                 from ../src/glib_object.h:4,
                 from ../src/application.h:4,
                 from ../src/addon.cc:1:
../src/glib_context.h:4:24: fatal error: frida-core.h: No such file or directory
 #include <frida-core.h>
                        ^
compilation terminated.
frida_binding.target.mk:114: recipe for target 'Release/obj.target/frida_binding/src/addon.o' failed
make: *** [Release/obj.target/frida_binding/src/addon.o] Error 1
make: Leaving directory '/tmp/node_modules/frida/build'
prebuild ERR! build error
prebuild ERR! stack Error: `make` failed with exit code: 2
prebuild ERR! stack     at ChildProcess.onExit (/tmp/node_modules/frida/node_modules/prebuild/node_modules/node-gyp/lib/build.js:276:23)
prebuild ERR! stack     at ChildProcess.emit (events.js:110:17)
prebuild ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1075:12)
prebuild ERR! not ok
prebuild ERR! build Error: `make` failed with exit code: 2
prebuild ERR! build     at ChildProcess.onExit (/tmp/node_modules/frida/node_modules/prebuild/node_modules/node-gyp/lib/build.js:276:23)
prebuild ERR! build     at ChildProcess.emit (events.js:110:17)
prebuild ERR! build     at Process.ChildProcess._handle.onexit (child_process.js:1075:12)
npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "frida"
npm ERR! node v0.12.9
npm ERR! npm  v2.14.9
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `prebuild --download`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] install script 'prebuild --download'.
npm ERR! This is most likely a problem with the frida package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     prebuild --download
npm ERR! You can get their info via:
npm ERR!     npm owner ls frida
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /tmp/npm-debug.log

Could you please comment whether frida-node bindings can be used this way or they must always be built from full Frida source tree?

TlsSetValue equivalent

What is equivalent to TlsSetValue() in Frida?

Since this pointer in onEnter/onLeave will not work across Interceptor hooks, what do you suggest?

Crash on node.js v14 in v8::ArrayBuffer::GetBackingStore()

[email protected]

Reproduction:

const frida = require('frida');

async function main() {
    console.log(await frida.enumerateDevices());
    console.log(await frida.enumerateDevices()); // crash
}

main();

Crash log:

#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 000000850F12A700
 1: 00007FF649891DDF napi_wrap+109135
 2: 00007FF6497C4F7F std::basic_ostream<char,std::char_traits<char> >::operator<<+56895
 3: 00007FF64A4035E2 V8_Fatal+162
 4: 00007FF649EA5BFD v8::internal::BackingStore::Reallocate+653
 5: 00007FF64A0ED089 v8::ArrayBuffer::GetBackingStore+137
 6: 00007FF6497133CD v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsIndex+33693
 7: 00007FF64985292C v8::internal::Malloced::operator delete+6124
 8: 00007FF64A0B35FF v8::internal::Builtins::builtin_handle+321615
 9: 00007FF64A0B2B8E v8::internal::Builtins::builtin_handle+318942
10: 00007FF64A0B2E87 v8::internal::Builtins::builtin_handle+319703
11: 00007FF64A0B2CD3 v8::internal::Builtins::builtin_handle+319267
12: 00007FF64A18F0FD v8::internal::SetupIsolateDelegate::SetupHeap+464173
13: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
14: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
15: 00007FF64A121639 v8::internal::SetupIsolateDelegate::SetupHeap+14953
16: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
17: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
18: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
19: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
20: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
21: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
22: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
23: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
24: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
25: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
26: 00007FF64A121639 v8::internal::SetupIsolateDelegate::SetupHeap+14953
27: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
28: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
29: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
30: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
31: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
32: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
33: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
34: 00007FF64A121639 v8::internal::SetupIsolateDelegate::SetupHeap+14953
35: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
36: 00007FF64A121639 v8::internal::SetupIsolateDelegate::SetupHeap+14953
37: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
38: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
39: 00007FF64A121639 v8::internal::SetupIsolateDelegate::SetupHeap+14953
40: 00007FF64A1256BE v8::internal::SetupIsolateDelegate::SetupHeap+31470
41: 00007FF64A1252AC v8::internal::SetupIsolateDelegate::SetupHeap+30428
42: 00007FF649FF5959 v8::internal::Execution::CallWasm+1657
43: 00007FF649FF51BF v8::internal::Execution::Call+191
44: 00007FF64A0E0797 v8::Function::Call+615
45: 00007FF64973770C std::basic_ostream<char,std::char_traits<char> >::put+46316
46: 00007FF64A0B35FF v8::internal::Builtins::builtin_handle+321615
47: 00007FF64A0B2B8E v8::internal::Builtins::builtin_handle+318942
48: 00007FF64A0B2E87 v8::internal::Builtins::builtin_handle+319703
49: 00007FF64A0B2CD3 v8::internal::Builtins::builtin_handle+319267
50: 00007FF64A18F0FD v8::internal::SetupIsolateDelegate::SetupHeap+464173
51: 00007FF64A127A02 v8::internal::SetupIsolateDelegate::SetupHeap+40498
52: 00007FF64A1547F0 v8::internal::SetupIsolateDelegate::SetupHeap+224288
53: 00007FF64A1D0BEE v8::internal::SetupIsolateDelegate::SetupHeap+733214
54: 00007FF64A14796D v8::internal::SetupIsolateDelegate::SetupHeap+171421
55: 00007FF64A1255AC v8::internal::SetupIsolateDelegate::SetupHeap+31196
56: 00007FF649FF5A17 v8::internal::Execution::CallWasm+1847
57: 00007FF649FF5B1B v8::internal::Execution::CallWasm+2107
58: 00007FF649FF656A v8::internal::Execution::TryCall+378
59: 00007FF649FD6C65 v8::internal::MicrotaskQueue::RunMicrotasks+501
60: 00007FF649FD69C0 v8::internal::MicrotaskQueue::PerformCheckpoint+32
61: 00007FF6498B5A70 node::CallbackScope::~CallbackScope+672
62: 00007FF6498B5E6B node::CallbackScope::~CallbackScope+1691
63: 00007FF6498B62B1 node::MakeCallback+209
64: 00007FFD0C9AA4FE g_win32_run_session_bus+234175
65: 00007FF6498E612B uv_async_send+331
66: 00007FF6498E58BC uv_loop_init+1292
67: 00007FF6498E5A5A uv_run+202
68: 00007FF6497F0495 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9477
69: 00007FF6498651C7 node::Start+311
70: 00007FF6496C67CC RC4_options+339660
71: 00007FF64A66B1EC v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152748
72: 00007FFD8C747034 BaseThreadInitThunk+20
73: 00007FFD8D0DCEC1 RtlUserThreadStart+33

Tested on both node.js v14.15.0 (x64) & node.js v15.8.0 (Apple Silicon)

Arguments Problems

Hi, I have some questions.
When Objc.classes has the method, for example "[- initWithText:subject:]", how can I call this function by JavaScript.
And how can I pass nil as argument?

plz, Thanks

Cannot install frida-node on mac

Hi, me again, After I install frida, I can use python to debug process. But when I reading and trying the demos, ZeroNights2015. Most of them are written in javascript, so I installed Node.js and going to try the demo.

const frida = require('frida');
const load = require('frida-load');
const co = require('co');

got Error: Cannot find module 'frida'

Then I believe that frida-node is needed, so I try to get the module from that. But got the following error:

$ npm install

> [email protected] install frida-master/frida-node
> prebuild --install

  CXX(target) Release/obj.target/frida_binding/src/addon.o
In file included from ../src/addon.cc:1:
In file included from ../src/application.h:4:
In file included from ../src/glib_object.h:4:
In file included from ../src/runtime.h:4:
../src/glib_context.h:4:10: fatal error: 'frida-core.h' file not found
#include <frida-core.h>
         ^
1 error generated.
make: *** [Release/obj.target/frida_binding/src/addon.o] Error 1
prebuild ERR! build error 
prebuild ERR! stack Error: `make` failed with exit code: 2
prebuild ERR! stack     at ChildProcess.onExit (frida-master/frida-node/node_modules/node-gyp/lib/build.js:276:23)
prebuild ERR! stack     at emitTwo (events.js:100:13)
prebuild ERR! stack     at ChildProcess.emit (events.js:185:7)
prebuild ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
prebuild ERR! not ok 
prebuild ERR! build Error: `make` failed with exit code: 2
prebuild ERR! build     at ChildProcess.onExit (frida-master/frida-node/node_modules/node-gyp/lib/build.js:276:23)
prebuild ERR! build     at emitTwo (events.js:100:13)
prebuild ERR! build     at ChildProcess.emit (events.js:185:7)
prebuild ERR! build     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)

npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.5.0
npm ERR! npm  v3.5.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `prebuild --install`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] install script 'prebuild --install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the frida package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     prebuild --install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs frida
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls frida
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     frida-master/frida-node/npm-debug.log

Wish your kind help :)

Frida hook to locally running Node server

I'm trying to hook up Frida to a Node server using the CLI. I'm able to connect to the Node process but unable to hook to functions I've defined in the server
The command I'm using is frida-trace -i 'helloworld' <node-pid> and it returns "Started tracing 0 functions" even though the Node server has the helloworld function.

I'm new to Frida so might be doing something wrong. What is the best way to trace functions running on a Node server with Frida?

Can't use frida with electron

Hi ! I'm trying to use frida in my electron app but I get this error when starting the app :

(node:21768) UnhandledPromiseRejectionWarning: Error: The module '/home/alexis/perso/dofus-kraken/node_modules/frida/build/Release/frida_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing

Here are the version of the packages I use :

"electron": "^9.2.0",
"frida": "^12.11.11"

I'm on ubuntu 18.04 if it can help !

Thank you !

Question: how to know when spawned process exited?

Here's the example similar to frida-node/examples/interactive.js:

async function spawnExample() {
  const pid = await frida.spawn(['/bin/sleep', '10']);

  console.log(`[*] Spawned pid=${pid}`);

  // This is where you could attach (see below) and instrument APIs before you call resume()
  await frida.resume(pid);
  console.log('[*] Resumed');

  // TODO: wait until the process exited, and get exit code, stdout, stderr
}

Is there any thing similar to node:child_process.spawnSync?

[Error: GDBus.Error:re.frida.Error.InvalidArgument: Script(line 5): SyntaxError: parse error ]

I am trying to learn how frida-node is working. I tried sample source code from Frida Presentations. The code I use is https://github.com/frida/frida-presentations/tree/master/NcN2015/02-ios-crypto When I run node app.js App Store App launches and I get following output on console

hi
[Error: GDBus.Error:re.frida.Error.InvalidArgument: Script(line 5): SyntaxError: parse error ]

App Store app hangs for a while then it quits.

What I am trying to do is attach multiple script file to single process. Since I hook lots of functions, it is very hard to type frida-trace and function names.

OS: El Capitan 10.11.4 (15E65)
iOS: 9.0.2
Frida: 7.0.11

Automatically reload script on change

I'm using frida-trace like this

frida-trace -H 172.16.177.51 -n XX.exe -S XXX.js

How can I reload the script automatically when it's changed?
Can you add support of fsevents/inotify/... to frida?

spawn gating issue

I took this as start point https://gist.github.com/oleavr/ae7bcbbb9179852a4731.

Here is the code

gating.js

'use strict';

const co = require('co');
const frida = require('frida');
const load = require('frida-load');

let target, device;

co(function*() {
    device = yield frida.getUsbDevice();
    device.events.listen('spawned', onSpawned);
    device.enableSpawnGating();
    const pending = yield device.enumeratePendingSpawns();
    pending.forEach(function(spawn, i) {
      console.log('pending[' + i + ']=', spawn, ' Resuming!');
      device.resume(spawn.pid);
    });
    console.log('ready');
  })
  .catch(function(error) {
    console.log('mmm error here');
    console.error(error.message);
    process.exitCode = 1;
  });

function onSpawned(spawn) {
  console.log('onSpawned:', spawn);
  co(function*() {
      if (spawn.identifier === 'com.android.insecurebankv2') {
        const session = yield device.attach(spawn.pid);
        const source = yield load(require.resolve('./agent.js'));
        const script = yield session.createScript(source);
        script.events.listen('message', function(message, data) {
          onMessage(spawn, message, data);
        });
        yield script.load();
        const exports = yield script.getExports();
        yield exports.init();
        yield device.resume(spawn.pid);
      } else {
        yield device.resume(spawn.pid);
      }

    })
    .catch(function(error) {
      console.error(error.message);
    });
}

function onMessage(spawn, message, data) {
  console.log(message);
  console.log('onMessage:', spawn, message, data);
}

agent.js

rpc.exports = {
  init: function() {
    'use strict';
    Java.perform(function() {
      var javaFile = Java.use("java.io.File");
      javaFile.exists.implementation = function() {
        console.log('File exists called');
        return this.exists.apply(this, arguments);
      }
    });
  }
};

But I am getting this

air:helper alvaro$ node gating.js
ready
onSpawned: Spawn { identifier: 'com.android.insecurebankv2', pid: 17454 }
onMessage: Spawn { identifier: 'com.android.insecurebankv2', pid: 17454 } { type: 'error',
  description: 'Error: access violation accessing 0x6f0056',
  stack: 'Error: access violation accessing 0x6f0056\n    at frida/node_modules/frida-java/lib/env.js:206\n    at apply (native)\n    at frida/node_modules/frida-java/lib/env.js:201\n    at frida/node_modules/frida-java/lib/class-factory.js:113\n    at frida/node_modules/frida-java/lib/class-factory.js:1621\n    at call (native)\n    at getPackageInfoNoCheck (input:1)\n    at apply (native)\n    at r (frida/node_modules/frida-java/lib/class-factory.js:842)\n    [...]',
  fileName: 'frida/node_modules/frida-java/lib/env.js',
  lineNumber: 206,
  columnNumber: 1 } null

FWIW I've not been able to make spawn, attach and resume to work. I am doing the following being spawn-agent.js the same agent without rpc.exports.

'use strict';

const co = require('co');
const frida = require('frida');
const load = require('frida-load');

let session, script;

co(function *() {
  const device = yield frida.getUsbDevice();
  const pid = yield device.spawn(['com.android.insecurebankv2']);
  session = yield device.attach(pid);
  const source = yield load(
      require.resolve('./spawn-agent.js'));
  script = yield session.createScript(source);
  script.events.listen('message', message => {
    if (message.type === 'send' && message.payload.event === 'ready')
      device.resume(pid);
    else
      console.log(message);
  });
  yield script.load();
})
.catch(console.error);

Here an asciinema https://asciinema.org/a/539my8j4jrmkghbgrdbtb3pdt

Am i doing it wrong ?

RPC function never resolved in jest

When call rpc function in jest, the promise will never resolve.
Finally found the cause of the problem:
jestjs/jest#2549
payload instanceof Array in isRpcSendMessage function returns false, because the payload is not created as the same context as jest. The problem can be solved by using Array.isArray(payload) instead.

Error occurred when import frida

I am using frida with electron, when import frida I got this

Uncaught TypeError: Cannot read property 'indexOf' of undefined
    at Function.getFileName (bindings.js?dfc1:178)
    at bindings (bindings.js?dfc1:82)
    at eval (native.js?1459:4)
    at Object../node_modules/frida/dist/native.js (app.js:3721)
    at __webpack_require__ (app.js:727)
    at fn (app.js:101)
    at eval (cancellable.js?607d:3)
    at Object../node_modules/frida/dist/cancellable.js (app.js:3661)
    at __webpack_require__ (app.js:727)
    at fn (app.js:101)

[Feature Request / Bug] script.load() doesn't throw error

[email protected]

const frida = require('frida');

async function main() {
	const dev = await frida.getLocalDevice();
	const pid = await dev.spawn('/bin/sh')
	const session = await dev.attach(pid)
	const script = await session.createScript(`console.log(1); throw 1;`) // <--- better raise an exception or something
	await script.load()
	await dev.resume(pid)
	await session.detach()
	await dev.kill(pid)
}

main()

await script.load() doesn't throw error, making it harder to debug complex agent scripts.

I want to use frida in electron, /frida_binding.node, 1): Symbol not found: _X509_INFO_free

I am looking for a hook tool for my electron application, I found frida, I like it very much, but I don't have much experience.
I am in the electron application, just a simple const frida = require('frida');
I got it 1): Symbol not found: _X509_INFO_free
The version of my electron is 7.0.0, but I also tried electron 5.0.0, the same issue.
I am operating on a macos 10.14.6 system

I am trying to run in node mode

Const frida = require('frida');
Console.log(frida)

Normal output as follows

{
  DeviceManager: [Function: DeviceManager],
  Device: [Function: Device],
  DeviceType: { Local: 'local', Remote: 'remote', Usb: 'usb' },
  Stdio: { Inherit: 'inherit', Pipe: 'pipe' },
  Session: [Function: Session],
  SessionDetachReason: {
    ApplicationRequested: 'application-requested',
    ProcessReplaced: 'process-replaced',
    ProcessTerminated: 'process-terminated',
    ServerTerminated: 'server-terminated',
    DeviceLost: 'device-lost'
  },
  Script: [Function: Script],
  ScriptRuntime: { Default: 'default', Duk: 'duk', V8: 'v8' },
  MessageType: { Send: 'send', Error: 'error' },
  LogLevel: { Info: 'info', Warning: 'warning', Error: 'error' },
  IOStream: [Function: IOStream],
  Cancellable: [Function: Cancellable],
  ChildOrigin: { Fork: 'fork', Exec: 'exec', Spawn: 'spawn' },
  spawn: [AsyncFunction: spawn],
  resume: [AsyncFunction: resume],
  kill: [AsyncFunction: kill],
  attach: [AsyncFunction: attach],
  injectLibraryFile: [AsyncFunction: injectLibraryFile],
  injectLibraryBlob: [AsyncFunction: injectLibraryBlob],
  enumerateDevices: [AsyncFunction: enumerateDevices],
  getDeviceManager: [Function: getDeviceManager],
  getLocalDevice: [Function: getLocalDevice],
  getRemoteDevice: [Function: getRemoteDevice],
  getUsbDevice: [Function: getUsbDevice],
  getDevice: [Function: getDevice]
}

This phenomenon seems to be incompatible with electron? Did I miss something?

Install on ArchLinux - frida-core.h not exists

Hi, i've a problem with the installation of frida-node on ArchLinux x64. I'm running nodejs 5.6.0.

The problem is the same, both
npm install
using the binary
and using
npm install frida

The output is

[strano@stranobeast frida-node-master]$ npm install
npm WARN deprecated [email protected]: This package has been renamed. Use lodash.padstart@^4.0.0.
npm WARN deprecated [email protected]: This package has been renamed. Use lodash.padend@^4.0.0.
npm WARN deprecated [email protected]: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN prefer global [email protected] should be installed with -g
npm WARN prefer global [email protected] should be installed with -g

 > [email protected] install /home/strano/Sviluppo/Frida/Frida_JS/frida-node-master
 > prebuild --install

make: ingresso nella directory "/home/strano/Sviluppo/Frida/Frida_JS/frida-node-master/build"
  CXX(target) Release/obj.target/frida_binding/src/addon.o
In file included from ../src/runtime.h:4:0,
                 from ../src/glib_object.h:4,
                 from ../src/application.h:4,
                 from ../src/addon.cc:1:
../src/glib_context.h:4:24: fatal error: frida-core.h: No such file or directory
compilation terminated.
frida_binding.target.mk:115: recipe for target 'Release/obj.target/frida_binding/src/addon.o' failed
make: *** [Release/obj.target/frida_binding/src/addon.o] Errore 1
make: uscita dalla directory "/home/strano/Sviluppo/Frida/Frida_JS/frida-node-master/build"
prebuild ERR! build error 
prebuild ERR! stack Error: \`make\` failed with exit code: 2
prebuild ERR! stack     at ChildProcess.onExit (/home/strano/Sviluppo/Frida/Frida_JS/frida-node-master/node_modules/node-gyp/lib/build.js:276:23)
prebuild ERR! stack     at ChildProcess.emit (events.js:110:17)
prebuild ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
prebuild ERR! not ok 
prebuild ERR! build Error: \`make\` failed with exit code: 2
prebuild ERR! build     at ChildProcess.onExit (/home/strano/Sviluppo/Frida/Frida_JS/frida-node-master/node_modules/node-gyp/lib/build.js:276:23)
prebuild ERR! build     at ChildProcess.emit (events.js:110:17)
prebuild ERR! build     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)

npm ERR! Linux 4.3.3-2-ARCH
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.2
npm ERR! npm  v3.3.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: \`prebuild --install\`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] install script 'prebuild --install'.
npm ERR! This is most likely a problem with the frida package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     prebuild --install
npm ERR! You can get their info via:
npm ERR!     npm owner ls frida
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/strano/Sviluppo/Frida/Frida_JS/frida-node-master/npm-debug.log

I attach also the log file of npm.

npm-debug.log.zip

Tnx for the help!

npm ERR! gyp: binding.gyp not found while trying to load binding.gyp

node -v v16.15.0
node-gyp -v v9.0.0

> npm i frida

npm ERR! code 1
npm ERR! path D:\Desktop\node.js\my-project\node_modules\frida
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c prebuild-install || node-gyp rebuild
npm ERR! prebuild-install WARN install connect ETIMEDOUT 20.205.243.166:443
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.9.12 found at "C:\Users\Zoranner\AppData\Local\Programs\Python\Python39\python.exe"
npm ERR! gyp info find VS using VS2022 (17.1.32421.90) found at:
npm ERR! gyp info find VS "C:\Program Files\Microsoft Visual Studio\2022\Professional"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Users\Someone\AppData\Local\Programs\Python\Python39\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\\Users\\Someone\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'msvs',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'D:\\Desktop\\node.js\\my-project\\node_modules\\frida\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\Someone\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\Someone\\AppData\\Local\\node-gyp\\Cache\\16.14.2\\include\\node\\common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Someone\\AppData\\Local\\node-gyp\\Cache\\16.14.2',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\Someone\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\Someone\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\16.15.0\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=D:\\Desktop\\node.js\\my-project\\node_modules\\frida',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'D:\\Desktop\\node.js\\my-project\\node_modules\\frida\\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: binding.gyp not found (cwd: D:\Desktop\node.js\my-project\node_modules\frida) while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\Someone\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:261:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Windows_NT 10.0.22610
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Someone\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\Desktop\node.js\my-project\node_modules\frida
npm ERR! gyp ERR! node -v v16.15.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok

npm install frida failed

Describe the bug
When I use npm to install frida, it failed.

To Reproduce
npm install frida

Error Outputs

➜  frida-node git:(main) ✗ npm install frida
npm ERR! code 1
npm ERR! path /Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/frida
npm ERR! command failed
npm ERR! command sh -c -- prebuild-install || node-gyp rebuild
npm ERR! prebuild-install warn install No prebuilt binaries found (target=19.1.0 runtime=node arch=arm64 libc= platform=darwin)
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.10.8 found at "/opt/homebrew/opt/[email protected]/bin/python3.10"
npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.10
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/frida/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/admin/Library/Caches/node-gyp/19.1.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/admin/Library/Caches/node-gyp/19.1.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/admin/Library/Caches/node-gyp/19.1.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/frida',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: binding.gyp not found (cwd: /Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/frida) while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/node-gyp/lib/configure.js:284:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm ERR! gyp ERR! System Darwin 21.2.0
npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node/19.1.0/bin/node" "/Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/admin/Projects/SDKPrivacyGuidance/tools/frida-node/node_modules/frida
npm ERR! gyp ERR! node -v v19.1.0
npm ERR! gyp ERR! node-gyp -v v9.1.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/admin/.npm/_logs/2022-11-19T03_29_48_472Z-debug-0.log

Desktop (please complete the following information):

  • OS: Mac mini(m1, 2020), MacOS 12.1
  • nodejs: v19.1.0
  • npm: 8.19.3

NativeCallback type in @types/frida-gum is outdated (and maybe some other classes too)

In the docs, the NativeCallback class has the constructor like this:

new NativeCallback(func, returnType, argTypes[, abi])

But its type definition in @types/frida-gum is:

declare class NativeCallback extends NativePointer {
    constructor(func: NativeCallbackImplementation, retType: NativeType, argTypes: NativeType[]);
}

Can you update the type definition for NativeCallback?

Attaching script when spawning Android application

I am able to start an Android application and attach a script to it like this:

const device = await frida.getUsbDevice();
const pid = await device.spawn(packageName);
const session = await device.attach(pid);
const source = await fs.promises.readFile(scriptPath, { encoding: "utf8" });
const script = await session.createScript(source);
await script.load();
await device.resume(pid);

From my understanding this spawns the process and attaches the script while it's already running.

What I want to do, is the equivalent to the CLI command: frida -U --no-pause -l script.js -f com.package.
Is this possible?

I already looked into SpawnOptions for spawn(), but didn't manage to utilize them (e.g. getting errors like [Error: The 'argv' option is not supported when spawning Android apps] for most).

cannot use frida in childThread by 'worker_threads'

hi :)

I tried and failed to use frida in a worker_threads in node v12.16.1 with the following exception:

FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
 1: 0x100080c68 node::Abort() [/usr/local/bin/node]
 2: 0x100080dec node::errors::TryCatchScope::~TryCatchScope() [/usr/local/bin/node]
 3: 0x1001851de v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/bin/node]
 4: 0x1002d4869 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [/usr/local/bin/node]
 5: 0x1004be0eb v8::internal::JSReceiver::GetCreationContext() [/usr/local/bin/node]
 6: 0x1001a1e58 v8::Object::CreationContext() [/usr/local/bin/node]
 7: 0x100001c9e node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/bin/node]
 8: 0x105011e08  [/Users/clf/IdeaProjects/CryptoSevice/node_modules/frida/build/Release/frida_binding.node]
 9: 0x1008ba8a9 uv__async_io [/usr/local/bin/node]
10: 0x1008cb77f uv__io_poll [/usr/local/bin/node]
11: 0x1008bad36 uv_run [/usr/local/bin/node]
12: 0x1000b66fa node::NodeMainInstance::Run() [/usr/local/bin/node]
13: 0x10005dc1f node::Start(int, char**) [/usr/local/bin/node]
14: 0x7fff654eb7fd start [/usr/lib/system/libdyld.dylib]
zsh: abort      node getdevice.js

Reproducing code - getdevice.js:

const {Worker, isMainThread} = require('worker_threads');
const frida = require('frida');
if (isMainThread) {
    console.log('Main Thread');
    const worker = new Worker(__filename);
    worker.on('message', function () {
    });

} else {
    console.log(`in worker ${__filename}`);
}
 var device = frida.getUsbDevice();
console.log('[*]device:',device);

In Node.js 10.5.0 be able to use 'worker-thread' module that included in node as default,so I wonder if it works to use frida in a worker_threads ?if not ,can add support for it ?

spawn java.exe on Windows not working

I'm trying to spawn a java application on Windows, but its not working even with an hello world created like:

  cat<<"EOF"> Program.java
public class Program {
  public static void main(String[] args) {
    System.out.println("Hello, World");
  }
}
EOF

  javac Program.java
  jar -cfe Program.jar Program Program.class
  java -jar Program.jar

The node script is:

var frida = require("frida");
var which = require("which");

const JAVA_PATH = which.sync("java");

frida
  .spawn([JAVA_PATH, "-jar", "Program.jar"])
  .then(function(pid) {
    console.log('spawned:', pid);
    // This is where you could attach (see below) and instrument APIs before you call resume()
    return frida.resume(pid);
  })
  .then(function() {
    console.log('resumed');
  })
  .catch(function(error) {
    console.log('error:', error.message);
  });

It will error out with:

spawned: 5784
resumed
Error: Could not find or load main class '-jar'

Memory.readFloat returning a string but Memory.writeFloat not able to use a string

I'm trying to overwrite a section in memory that is defined as a Float, but it appears to be a 64-bit signed float. Using Memory.readFloat() I get values like -150525991776673600000 as a string. Then I'm attempting to use Memory.writeFloat() to overwrite it with a value like -7728003924733680089 but I get an error that it expects a number. Unfortunately those numbers are too big to be correctly represented using JavaScript floats. I've tried using Memory.readS64() and Memory.readLong() to make use of the Int64 value but I don't get correct values. Is there any way to prepare a value to be written in that fashion?

Invalid ELF header in `10.6.24`

Hey Ole,

I love your work with Frida.

I think there's an issue with the recent patch 4 days ago.

Environment: Debian OS.

/source/node_modules/bindings/bindings.js:88
        throw e
        ^

Error: /source/node_modules/frida/build/Release/frida_binding.node: invalid ELF header
    at Object.Module._extensions..node (module.js:653:18)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at bindings (/source/node_modules/bindings/bindings.js:81:44)
    at Object.<anonymous> (/source/node_modules/frida/lib/frida.js:56:34)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)

Port over to using NAN

Discussed on IRC, porting over to NAN will allow us to support future breaking V8 changes, and iojs immediately.

Block calls to original method conditionally

I'm trying to block calls to original method in onEnter(), something like

onEnter: (args) => {
  originalMethod = this.XXX

  if (condition) {
      this.originalMethod(args)
  } else {
      return retVal
  }
}

Is it supported by frida?

Rebuilding frida bindings

@oleavr I've developed a one-liner to get the proper binaries since it could be a bit tedious to manually find the frida dependency, delete it and set the environment variables:

https://www.npmjs.com/package/frida-rebuild

Usage: npx frida-rebuild --runtime=electron --target=16.0.0

It will locate frida automatically and climb the directories if used in a workspace / monorepo.
Creating an issue so future users can find it from Google :).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.