Skip to content

Commit ee50bde

Browse files
committed
Reuse parallel promise-combination to avoid dupe Frida scans
1 parent 7ac5656 commit ee50bde

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/interceptors/frida/frida-android-interceptor.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
launchAndroidHost,
1515
setupAndroidHost
1616
} from './frida-android-integration';
17+
import { combineParallelCalls } from '@httptoolkit/util';
1718

1819
export class FridaAndroidInterceptor implements Interceptor {
1920

@@ -26,16 +27,7 @@ export class FridaAndroidInterceptor implements Interceptor {
2627
private config: HtkConfig
2728
) {}
2829

29-
private _fridaTargetsPromise: Promise<Array<FridaHost>> | undefined;
30-
async getFridaHosts(): Promise<Array<FridaHost>> {
31-
if (!this._fridaTargetsPromise) {
32-
// We cache the targets lookup whilst it's active, so that concurrent calls
33-
// all just run one lookup and return the same result.
34-
this._fridaTargetsPromise = getAndroidFridaHosts(this.adbClient)
35-
.finally(() => { this._fridaTargetsPromise = undefined; });
36-
}
37-
return await this._fridaTargetsPromise;
38-
}
30+
getFridaHosts = combineParallelCalls(() => getAndroidFridaHosts(this.adbClient));
3931

4032
async isActivable(): Promise<boolean> {
4133
return (await this.getFridaHosts()).length > 0;

src/interceptors/frida/frida-ios-interceptor.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from 'lodash';
22
import { UsbmuxClient } from 'usbmux-client';
33
import * as FridaJs from 'frida-js';
4+
import { combineParallelCalls } from '@httptoolkit/util';
45

56
import { Interceptor } from "..";
67
import { HtkConfig } from '../../config';
@@ -23,16 +24,7 @@ export class FridaIosInterceptor implements Interceptor {
2324
private config: HtkConfig
2425
) {}
2526

26-
private _fridaTargetsPromise: Promise<Array<FridaHost>> | undefined;
27-
async getFridaHosts(): Promise<Array<FridaHost>> {
28-
if (!this._fridaTargetsPromise) {
29-
// We cache the targets lookup whilst it's active, so that concurrent calls
30-
// all just run one lookup and return the same result.
31-
this._fridaTargetsPromise = getIosFridaHosts(this.usbmuxClient)
32-
.finally(() => { this._fridaTargetsPromise = undefined; });
33-
}
34-
return await this._fridaTargetsPromise;
35-
}
27+
getFridaHosts = combineParallelCalls(() => getIosFridaHosts(this.usbmuxClient));
3628

3729
async isActivable(): Promise<boolean> {
3830
return (await this.getFridaHosts()).length > 0;

0 commit comments

Comments
 (0)