Bypassing Root Detection and Emulator Checks on Android
- Android Pentest Lab Build
- Android SSL Pinning Bypass with Burp Suite
- Frida Method Hooking for Android App Analysis
- Hooking Native Libraries with Frida Interceptor
- From APK to Source: Complete Android Reverse Engineering Workflow
- Bypassing Root Detection and Emulator Checks on Android
- Attacking Android IPC: Intents, Content Providers, and Broadcast Receivers
- Automating Android App Analysis with Frida and Objection
This is part six of my Android pentest series. We’ve covered the lab, SSL pinning, method hooking, native hooking, and APK reverse engineering. Now let’s deal with the thing that stops most of those techniques from working in the first place — root detection and emulator checks.
Almost every app I assess on mobile engagements has some form of environment detection. Banking apps, healthcare apps, anything handling sensitive data. The app launches, detects you’re on a rooted device or emulator, and either exits or degrades functionality. This is annoying when you need to actually test the app.
Let’s break all of it.
How Root Detection Works
Root detection isn’t one technique — it’s a pile of heuristics. Apps check multiple indicators and combine the results. Here’s what they typically look for.
File-Based Checks
The most common approach. Apps look for files that exist on rooted devices:
// Typical root detection code you'll find when decompiling
private boolean isRooted() {
String[] paths = {
"/system/app/Superuser.apk",
"/system/xbin/su",
"/system/bin/su",
"/sbin/su",
"/data/local/xbin/su",
"/data/local/bin/su",
"/data/local/su",
"/su/bin/su",
"/system/bin/.ext/.su",
"/system/etc/.has_su_daemon",
"/system/etc/.installed_su_daemon"
};
for (String path : paths) {
if (new File(path).exists()) return true;
}
return false;
}
Package-Based Checks
Apps query the package manager for known root management apps:
private boolean hasRootPackages() {
String[] packages = {
"com.topjohnwu.magisk",
"eu.chainfire.supersu",
"com.koushikdutta.superuser",
"com.thirdparty.superuser",
"com.yellowes.su",
"com.noshufou.android.su"
};
PackageManager pm = getPackageManager();
for (String pkg : packages) {
try {
pm.getPackageInfo(pkg, 0);
return true;
} catch (NameNotFoundException e) {}
}
return false;
}
Command Execution
Some apps try to actually run su:
private boolean canRunSu() {
try {
Runtime.getRuntime().exec("su");
return true;
} catch (Exception e) {
return false;
}
}
System Properties
Checking build properties for test-keys, custom ROMs, or debug builds:
private boolean hasTestKeys() {
String buildTags = android.os.Build.TAGS;
return buildTags != null && buildTags.contains("test-keys");
}
private boolean isDebuggable() {
return (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
SafetyNet / Play Integrity
The nuclear option. Google’s server-side attestation checks device integrity, bootloader status, and software state. This is the hardest to bypass because the attestation happens server-side.
Emulator Detection
Apps use overlapping techniques to detect emulators:
Build Properties
private boolean isEmulator() {
return Build.FINGERPRINT.contains("generic")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| Build.BRAND.startsWith("generic")
|| Build.DEVICE.startsWith("generic")
|| Build.HARDWARE.contains("goldfish")
|| Build.HARDWARE.contains("ranchu")
|| Build.PRODUCT.contains("sdk")
|| Build.PRODUCT.contains("vbox86p");
}
Hardware Indicators
// Sensor check - emulators have fewer/fake sensors
SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
int sensorCount = sm.getSensorList(Sensor.TYPE_ALL).size();
// Real devices typically have 15+ sensors, emulators have < 5
// Telephony check
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String phoneNumber = tm.getLine1Number();
// Emulators often return "15555215554" or similar
// Battery check - emulators report specific battery states
Timing and Performance Checks
Some sophisticated apps measure execution timing. Emulators are slower at certain operations like floating point math or file I/O, giving them away.
Bypassing Everything with Frida
Now the fun part. We have a few approaches depending on how much time you want to spend.
Quick Win: Hook the Detection Methods Directly
If you’ve decompiled the APK and found the detection methods, just override them:
Java.perform(function() {
var rootCheck = Java.use("com.target.security.RootDetector");
rootCheck.isRooted.implementation = function() {
console.log("[*] isRooted() called - returning false");
return false;
};
rootCheck.isEmulator.implementation = function() {
console.log("[*] isEmulator() called - returning false");
return false;
};
});
This works when the detection is in one class. But most serious implementations spread checks across multiple classes or use obfuscated names.
Comprehensive: Hook the Underlying APIs
Instead of finding each detection method, hook the system APIs that all detection relies on:
File.exists() bypass:
Java.perform(function() {
var File = Java.use("java.io.File");
// Match su as its own path segment. A substring search for "su"
// also hits legitimate paths such as /system/bin/surfaceflinger.
var markers = [
"Superuser.apk", "magisk", "busybox",
".has_su_daemon", ".installed_su_daemon"
];
File.exists.implementation = function() {
var path = this.getAbsolutePath();
var hide = /\/su$/.test(path) || path.indexOf("/su/") !== -1;
for (var i = 0; i < markers.length && !hide; i++) {
hide = path.indexOf(markers[i]) !== -1;
}
if (hide) {
console.log("[*] File.exists(" + path + ") -> false");
return false;
}
return this.exists();
};
});
PackageManager bypass:
Java.perform(function() {
var PM = Java.use("android.app.ApplicationPackageManager");
var blockedPkgs = [
"com.topjohnwu.magisk",
"eu.chainfire.supersu",
"com.koushikdutta.superuser",
"com.noshufou.android.su",
"com.thirdparty.superuser"
];
PM.getPackageInfo.overload("java.lang.String", "int").implementation = function(pkg, flags) {
if (blockedPkgs.indexOf(pkg) !== -1) {
console.log("[*] Hiding package: " + pkg);
throw Java.use("android.content.pm.PackageManager$NameNotFoundException").$new(pkg);
}
return this.getPackageInfo(pkg, flags);
};
});
API 33 added getPackageInfo(String, PackageInfoFlags). A hook on the int overload misses callers of the new one. Wrap a second overload in try/catch so older devices, where that signature does not exist, still load the script.
Build properties bypass:
Java.perform(function() {
var Build = Java.use("android.os.Build");
// Spoof to look like a real device
Build.FINGERPRINT.value = "google/walleye/walleye:11/RP1A.200720.009/6720564:user/release-keys";
Build.MODEL.value = "Pixel 2";
Build.MANUFACTURER.value = "Google";
Build.BRAND.value = "google";
Build.DEVICE.value = "walleye";
Build.PRODUCT.value = "walleye";
Build.HARDWARE.value = "walleye";
Build.TAGS.value = "release-keys";
console.log("[*] Build properties spoofed to Pixel 2");
});
Runtime.exec bypass (block su execution):
Java.perform(function() {
var Runtime = Java.use("java.lang.Runtime");
// Match the su token. indexOf("su") also matches dumpsys.
function isSuExec(cmd) {
return /(^|\s)su(\s|$)/.test(cmd) || cmd.indexOf("magisk") !== -1;
}
Runtime.exec.overload("java.lang.String").implementation = function(cmd) {
if (isSuExec(cmd)) {
console.log("[*] Blocked exec: " + cmd);
throw Java.use("java.io.IOException").$new("Permission denied");
}
return this.exec(cmd);
};
// Also catch the String[] overload
Runtime.exec.overload("[Ljava.lang.String;").implementation = function(cmds) {
var cmdStr = cmds.join(" ");
if (isSuExec(cmdStr)) {
console.log("[*] Blocked exec: " + cmdStr);
throw Java.use("java.io.IOException").$new("Permission denied");
}
return this.exec(cmds);
};
});
The Combined Script
In practice I use a single script that combines all these bypasses. Save this as bypass-detection.js:
Java.perform(function() {
console.log("[*] Root/Emulator detection bypass loaded");
// ===== File.exists bypass =====
var File = Java.use("java.io.File");
var markers = [
"superuser", "magisk", "busybox", "daemonsu",
".has_su_daemon", ".installed_su_daemon", "supersu",
"frida-server", "frida-agent", "re.frida", "xposed"
];
File.exists.implementation = function() {
var path = this.getAbsolutePath();
var lower = path.toLowerCase();
var hide = /\/su$/.test(lower) || lower.indexOf("/su/") !== -1;
for (var i = 0; i < markers.length && !hide; i++) {
hide = lower.indexOf(markers[i]) !== -1;
}
if (hide) {
console.log("[*] Hiding file: " + path);
return false;
}
return this.exists();
};
// ===== Build property spoofing =====
var Build = Java.use("android.os.Build");
Build.FINGERPRINT.value = "google/walleye/walleye:11/RP1A.200720.009/6720564:user/release-keys";
Build.MODEL.value = "Pixel 2";
Build.MANUFACTURER.value = "Google";
Build.BRAND.value = "google";
Build.DEVICE.value = "walleye";
Build.PRODUCT.value = "walleye";
Build.HARDWARE.value = "walleye";
Build.TAGS.value = "release-keys";
Build.HOST.value = "wphr1.hot.corp.google.com";
console.log("[*] Build properties spoofed");
// ===== Package manager bypass =====
var PM = Java.use("android.app.ApplicationPackageManager");
var hiddenPkgs = [
"com.topjohnwu.magisk", "eu.chainfire.supersu",
"com.koushikdutta.superuser", "com.noshufou.android.su",
"com.thirdparty.superuser", "com.yellowes.su",
"com.zachspong.temprootremovejb", "com.ramdroid.appquarantine",
"de.robv.android.xposed.installer", "com.saurik.substrate"
];
PM.getPackageInfo.overload("java.lang.String", "int").implementation = function(pkg, flags) {
if (hiddenPkgs.indexOf(pkg) !== -1) {
console.log("[*] Hiding package: " + pkg);
throw Java.use("android.content.pm.PackageManager$NameNotFoundException").$new(pkg);
}
return this.getPackageInfo(pkg, flags);
};
try {
var flagsType = "android.content.pm.PackageManager$PackageInfoFlags";
PM.getPackageInfo.overload("java.lang.String", flagsType).implementation = function(pkg, flags) {
if (hiddenPkgs.indexOf(pkg) !== -1) {
throw Java.use("android.content.pm.PackageManager$NameNotFoundException").$new(pkg);
}
return this.getPackageInfo(pkg, flags);
};
} catch (e) {}
// ===== Runtime.exec bypass =====
var Runtime = Java.use("java.lang.Runtime");
var blockedCmds = ["busybox", "magisk"];
function isBlockedExec(cmd) {
if (/(^|\s)su(\s|$)/.test(cmd)) return true;
for (var i = 0; i < blockedCmds.length; i++) {
if (cmd.indexOf(blockedCmds[i]) !== -1) return true;
}
return false;
}
Runtime.exec.overload("java.lang.String").implementation = function(cmd) {
if (isBlockedExec(cmd)) {
console.log("[*] Blocked exec: " + cmd);
throw Java.use("java.io.IOException").$new("Permission denied");
}
return this.exec(cmd);
};
// ro.* lives in android.os.SystemProperties, not java.lang.System.
var SP = Java.use("android.os.SystemProperties");
SP.get.overload("java.lang.String").implementation = function(key) {
if (key === "ro.debuggable") return "0";
if (key === "ro.secure") return "1";
return this.get(key);
};
SP.get.overload("java.lang.String", "java.lang.String").implementation = function(key, def) {
if (key === "ro.debuggable") return "0";
if (key === "ro.secure") return "1";
return this.get(key, def);
};
console.log("[*] All bypasses active");
});
Run it. Current Frida resumes a spawned app on its own and rejects --no-pause. Pass --pause only when you need the process frozen until you type %resume.
frida -U -f com.target.app -l bypass-detection.js
Dealing with Commercial Frameworks
When you run into apps that use commercial protection SDKs, the generic bypass above might not cut it. Here’s what to look for.
RootBeer
Popular open-source root detection library. Easy to spot because the package name is com.scottyab.rootbeer. Several checks have a String[] overload, so assign .overload() or Frida throws. isSelinuxFlagInEnabled was never a RootBeer method. It lived on com.scottyab.rootbeer.util.Utils and RootBeer 0.1.1 removed it. It was not part of isRooted().
Java.perform(function() {
var RootBeer = Java.use("com.scottyab.rootbeer.RootBeer");
var methods = [
"isRooted",
"isRootedWithBusyBoxCheck",
"isRootedWithoutBusyBoxCheck",
"detectRootManagementApps",
"detectPotentiallyDangerousApps",
"detectTestKeys",
"checkForBusyBoxBinary",
"checkForSuBinary",
"checkSuExists",
"checkForRWPaths",
"checkForDangerousProps",
"checkForRootNative",
"detectRootCloakingApps",
"checkForMagiskBinary"
];
methods.forEach(function(name) {
try {
RootBeer[name].overload().implementation = function() { return false; };
} catch (e) {
console.log("[*] skip " + name + ": " + e);
}
});
console.log("[*] RootBeer hooks installed");
});
ProGuard/R8 Obfuscated Detection
When root detection is obfuscated, you won’t find obvious class names. The approach changes:
- Search for string constants. Decompile with jadx and grep for
"/system/xbin/su"or"test-keys". Even with obfuscated method names, the strings are usually still there. - Trace File.exists. Run the comprehensive File.exists hook and watch what paths get checked at startup. The detection code will reveal itself.
- Hook at the decision point. Find where the app shows the “rooted device detected” dialog or calls
finish(). Hook that and prevent it.
// Find the kill switch
Java.perform(function() {
var Activity = Java.use("android.app.Activity");
Activity.finish.implementation = function() {
console.log("[!] finish() blocked on: " + this.getClass().getName());
console.log(Java.use("android.util.Log").getStackTraceString(
Java.use("java.lang.Exception").$new()
));
// Don't call finish - keep the app alive
};
});
The stack trace will show you exactly which class triggered the kill, even if it’s obfuscated.
Frida Detection
Some apps detect Frida itself. Common methods:
-
Scanning
/proc/self/mapsfor frida libraries -
Checking for frida-server on default port (27042)
-
Looking for frida-agent in memory
-
Checking for the frida thread name
The snippet below only logs open() of a maps file. It does not rewrite the bytes the app reads, so it will not hide Frida. Frida 17 removed Module.findExportByName(module, export). Android usually reaches maps through openat, so a hook on open alone misses a lot of those reads.
var libc = Process.findModuleByName("libc.so");
var openPtr = libc ? libc.findExportByName("open") : null;
if (openPtr) {
Interceptor.attach(openPtr, {
onEnter: function(args) {
var path = args[0].readUtf8String();
if (path && path.indexOf("/maps") !== -1) {
console.log("[*] open(" + path + ")");
}
}
});
}
// frida-server on a non-default port:
// ./frida-server -l 0.0.0.0:1337
// Then connect: frida -H 127.0.0.1:1337 -f com.target.app
For stubborn anti-Frida checks, start frida-server with a renamed binary:
# On the device
cp frida-server /data/local/tmp/myserver
chmod 755 /data/local/tmp/myserver
/data/local/tmp/myserver &
MagiskHide and Shamiko
If you’re on a real rooted device (not an emulator), Magisk’s built-in hide features handle a lot of this automatically.
MagiskHide was removed in Magisk 24. Zygisk and the DenyList replaced it.
Zygisk + DenyList (Magisk 24+):
-
Enable Zygisk in Magisk settings
-
Add the target app to the DenyList
-
With “Enforce DenyList” on, Magisk unmounts its own files from that process
Shamiko (Magisk module):
-
Reads the DenyList as its hide list
-
“Enforce DenyList” has to be off. If enforcement is on, Shamiko does not apply
-
Hides Magisk and Zygisk beyond the stock unmount
For most assessments I use Magisk + Shamiko as the baseline and layer Frida hooks on top for anything that gets through.
Practical Workflow
Here’s how I approach root/emulator detection on a real engagement:
- Install the app and launch it. See what happens. Does it crash? Show a warning? Silently degrade?
- Decompile and search.
grep -rE "isRooted|rootbeer|safetynet|isEmulator" jadx-output/to find the detection logic. - Try the generic bypass script. Run
bypass-detection.js. This handles a lot of apps. - If that fails, trace the APIs. Hook
File.exists,Runtime.exec,PackageManager.getPackageInfoand log everything at startup. You’ll see exactly what the app checks. - Hook the decision point. Find where the app acts on the detection result and neutralize it there.
- For SafetyNet/Play Integrity. Use a real rooted device with Magisk + Shamiko. Emulators can’t pass hardware attestation.
Most apps fall to step 3 or 4. The rest require targeted hooking but the techniques above give you everything you need to find the right hooks.
The short versions of these hooks are on the Frida cheat sheet.
If you enjoyed this post please consider subscribing to the feed!