Skip to content

Commit

Permalink
Add support for disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 2, 2023
1 parent e0ff0dd commit 77b3aa8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "^5.0.4"
},
"dependencies": {
"@httptoolkit/dbus-native": "^0.1.0",
"@httptoolkit/dbus-native": "^0.1.1",
"@httptoolkit/websocket-stream": "^6.0.1",
"isomorphic-ws": "^4.0.1"
}
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ interface AgentSession {
LoadScript(scriptId: [number]): Promise<void>;
}

class FridaSession {
export class FridaSession {

constructor(
private bus: dbus.DBusClient
) {}

async disconnect() {
return this.bus.disconnect();
}

private getHostSession() {
return this.bus
.getService('re.frida.HostSession16')
Expand Down
21 changes: 14 additions & 7 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { expect } from 'chai';
import { fetch } from 'cross-fetch';

import { delay, isNode } from './test-util';
import { connect } from '../src/index';
import { connect, FridaSession } from '../src/index';

const FIXTURES_BASE = isNode
? path.join(__dirname, 'fixtures')
: process.env.FIXTURES_PATH!;

describe("Frida-JS", () => {

let fridaClient: FridaSession;

afterEach(async () => {
await fridaClient?.disconnect();
(fridaClient as any) = undefined;
})

it("can connect to Frida and list targets", async () => {
const fridaClient = await connect();
fridaClient = await connect();
const processes = await fridaClient.enumerateProcesses();

expect(processes.length).to.be.greaterThan(0);
Expand Down Expand Up @@ -58,7 +65,7 @@ describe("Frida-JS", () => {
});

// Inject into it:
const fridaClient = await connect();
fridaClient = await connect();
await fridaClient.injectIntoProcess(childProc.pid!, `
const shouldContinue = DebugSymbol.fromName('should_continue');
Expand Down Expand Up @@ -109,7 +116,7 @@ describe("Frida-JS", () => {
});

// Inject into it:
const fridaClient = await connect();
fridaClient = await connect();
await fridaClient.injectIntoNodeJSProcess(
childNodeProc.pid!,
'console.log("Hello from injected script!"); process.exit(0);'
Expand All @@ -124,7 +131,7 @@ describe("Frida-JS", () => {

it("can launch a process with a hook script injected", async function() {
// Launch a server process with a script injected
const fridaClient = await connect();
fridaClient = await connect();
await fridaClient.spawnWithScript(
path.join(FIXTURES_BASE, `serve-${process.platform}-${process.arch}`),
['original', 'arguments'],
Expand Down Expand Up @@ -165,8 +172,8 @@ describe("Frida-JS", () => {
}
}

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

})

0 comments on commit 77b3aa8

Please sign in to comment.