Skip to content

Commit

Permalink
Add support for connecting to Frida instances by address
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 2, 2023
1 parent 12e2789 commit e0ff0dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import WebSocket = require('isomorphic-ws');
import createWebSocketStream = require('@httptoolkit/websocket-stream');
import dbus = require('@httptoolkit/dbus-native');

const FRIDA_PORT = 27042;
const DEFAULT_FRIDA_PORT = 27042;

export async function connect() {
const socket = new WebSocket(`ws://localhost:${FRIDA_PORT}/ws`);
export async function connect(options: {
host?: string
} = {}) {
const fridaHost = options.host || `localhost:${DEFAULT_FRIDA_PORT}`;

const socket = new WebSocket(`ws://${fridaHost}/ws`);
socket.binaryType = 'arraybuffer';

await new Promise((resolve, reject) => {
Expand Down
16 changes: 16 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,20 @@ describe("Frida-JS", () => {
expect(resultingMessage).to.equal('INJECTED');
});

it("can connect to a Frida instance by address", async () => {
try {
await connect({ host: 'localhost:12345' });
throw new Error('Should not connect successfully');
} catch (e: any) {
// This is expected. We can only check the error in Node though, as browsers
// don't expose full network error details:
if (isNode) {
expect(e.message).to.include('ECONNREFUSED 127.0.0.1:12345');
}
}

const client = await connect({ host: 'localhost:27042' });
expect((await client.enumerateProcesses()).length).to.be.greaterThan(0);
});

})

0 comments on commit e0ff0dd

Please sign in to comment.