Skip to content

Commit 980aa2a

Browse files
committed
Cleanup old Frida server downloads from computer cache
1 parent ad959e1 commit 980aa2a

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/dynamic-dep-store.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,25 @@ export async function getDependencyStream<K extends readonly string[]>(options:
5151
});
5252

5353
return resultStream;
54+
}
55+
56+
export async function cleanupDependencies(options: {
57+
config: HtkConfig,
58+
keyPrefix: string,
59+
versionToKeep: string,
60+
ext: `.${string}`
61+
}) {
62+
const depFiles = await fs.readDir(options.config.configPath);
63+
64+
await Promise.all(depFiles.map(async (depFile) => {
65+
if (
66+
depFile.startsWith(options.keyPrefix + '-') &&
67+
(depFile.endsWith(options.ext) || depFile.includes(`${options.ext}.tmp-`)) &&
68+
!depFile.includes(options.versionToKeep)
69+
) {
70+
await fs.deleteFile(path.join(options.config.configPath, depFile)).catch((e) => {
71+
console.warn(`Failed to delete old dependency file ${depFile}:`, e);
72+
});
73+
}
74+
}));
5475
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Interceptor } from "..";
66
import { HtkConfig } from '../../config';
77

88
import { createAdbClient } from '../android/adb-commands';
9-
import { FridaHost, FridaTarget, killProcess } from './frida-integration';
9+
import { cleanupOldFridaServers, FridaHost, FridaTarget, killProcess } from './frida-integration';
1010
import {
1111
getAndroidFridaHosts,
1212
getAndroidFridaTargets,
@@ -101,6 +101,8 @@ export class FridaAndroidInterceptor implements Interceptor {
101101
}
102102

103103
async deactivateAll(): Promise<void | {}> {
104+
cleanupOldFridaServers(this.config).catch(console.warn);
105+
104106
const allPorts = new Set([
105107
...Object.keys(this.fridaServers),
106108
...Object.keys(this.interceptedApps)

src/interceptors/frida/frida-integration.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ export const getFridaServer = (
6868
});
6969
}
7070

71+
export const cleanupOldFridaServers = async (config: HtkConfig) => {
72+
await dynamicDeps.cleanupDependencies({
73+
config,
74+
keyPrefix: 'frida-server',
75+
versionToKeep: FRIDA_VERSION,
76+
ext: '.bin'
77+
} as const);
78+
};
79+
7180
class FridaScriptError extends CustomError {
7281
constructor(
7382
message: FridaJs.ScriptAgentErrorMessage

0 commit comments

Comments
 (0)