Skip to content

Commit 34c74c1

Browse files
committed
Tighten up 'su' file IO detection on Android anti-root detection
Previously this blocked all reads of any paths containing 'su', which has a lot of false positives (e.g. .../support-file) that will very plausibly cause problems.
1 parent 7eca725 commit 34c74c1

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

android/android-disable-root-detection.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,19 @@
196196
}
197197

198198
function bypassJavaFileCheck() {
199+
function isRootIndicatorFile(file) {
200+
const path = file.getAbsolutePath();
201+
const filename = file.getName();
202+
return ROOT_INDICATORS.paths.has(path) ||
203+
path.includes("magisk") ||
204+
filename === "su";
205+
}
206+
199207
const UnixFileSystem = Java.use("java.io.UnixFileSystem");
200208
UnixFileSystem.checkAccess.implementation = function(file, access) {
201-
const filename = file.getAbsolutePath();
202-
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
209+
if (isRootIndicatorFile(file)) {
203210
if (DEBUG_MODE) {
204-
console.debug(`Blocked possible root detection: filesystem access check for ${filename}`);
211+
console.debug(`Blocked possible root detection: filesystem access check for ${file.getAbsolutePath()}`);
205212
} else logFirstRootDetection();
206213
return false;
207214
}
@@ -210,21 +217,19 @@
210217

211218
const File = Java.use("java.io.File");
212219
File.exists.implementation = function() {
213-
const filename = this.getAbsolutePath();
214-
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
220+
if (isRootIndicatorFile(this)) {
215221
if (DEBUG_MODE) {
216-
console.debug(`Blocked possible root detection: file exists check for ${filename}`);
222+
console.debug(`Blocked possible root detection: file exists check for ${this.getAbsolutePath()}`);
217223
} else logFirstRootDetection();
218224
return false;
219225
}
220226
return this.exists();
221227
};
222228

223229
File.length.implementation = function() {
224-
const filename = this.getAbsolutePath();
225-
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
230+
if (isRootIndicatorFile(this)) {
226231
if (DEBUG_MODE) {
227-
console.debug(`Blocked possible root detection: file length check for ${filename}`);
232+
console.debug(`Blocked possible root detection: file length check for ${this.getAbsolutePath()}`);
228233
} else logFirstRootDetection();
229234
return 0;
230235
}
@@ -233,13 +238,11 @@
233238

234239
const FileInputStream = Java.use("java.io.FileInputStream");
235240
FileInputStream.$init.overload('java.io.File').implementation = function(file) {
236-
const path = file.getAbsolutePath();
237-
const filename = file.getName();
238-
if (ROOT_INDICATORS.paths.has(path) || path.includes("magisk") || filename.includes("su")) {
241+
if (isRootIndicatorFile(file)) {
239242
if (DEBUG_MODE) {
240-
console.debug(`Blocked possible root detection: file stream for ${path}`);
243+
console.debug(`Blocked possible root detection: file stream for ${file.getAbsolutePath()}`);
241244
} else logFirstRootDetection();
242-
throw Java.use("java.io.FileNotFoundException").$new(path);
245+
throw Java.use("java.io.FileNotFoundException").$new(file.getAbsolutePath());
243246
}
244247
return this.$init(file);
245248
};

0 commit comments

Comments
 (0)