// Root Detection Bypass — RootBeer, SafetyNet basics, su/magisk file checks, Runtime.exec
// Usage: frida -U -f com.target.app -l root-bypass.js --no-pause

Java.perform(function() {
    // --- RootBeer ---
    try {
        var RootBeer = Java.use('com.scottyab.rootbeer.RootBeer');
        RootBeer.isRooted.implementation = function() { return false; };
        RootBeer.isRootedWithoutBusyBox.implementation = function() { return false; };
        RootBeer.checkForSuBinary.implementation = function() { return false; };
        RootBeer.detectRootManagementApps.implementation = function() { return false; };
        RootBeer.detectPotentiallyDangerousApps.implementation = function() { return false; };
        console.log('[+] RootBeer bypassed');
    } catch(e) {}

    // --- File-based su/magisk/busybox checks ---
    try {
        var File = Java.use('java.io.File');
        File.exists.implementation = function() {
            var name = this.getAbsolutePath();
            if (name.indexOf('su') !== -1 || name.indexOf('magisk') !== -1 || name.indexOf('busybox') !== -1) {
                console.log('[+] File.exists blocked: ' + name);
                return false;
            }
            return this.exists();
        };
    } catch(e) {}

    // --- Runtime.exec su ---
    try {
        var Runtime = Java.use('java.lang.Runtime');
        Runtime.exec.overload('java.lang.String').implementation = function(cmd) {
            if (cmd.indexOf('su') !== -1) {
                console.log('[+] Runtime.exec(su) blocked');
                throw Java.use('java.io.IOException').$new('Permission denied');
            }
            return this.exec(cmd);
        };
    } catch(e) {}

    // --- System Properties ---
    try {
        var SystemProperties = Java.use('android.os.SystemProperties');
        SystemProperties.get.overload('java.lang.String').implementation = function(key) {
            if (key === 'ro.debuggable') return '0';
            if (key === 'ro.secure') return '1';
            return this.get(key);
        };
    } catch(e) {}

    // --- PackageManager root app detection ---
    try {
        var PackageManager = Java.use('android.app.ApplicationPackageManager');
        var rootPkgs = ['com.topjohnwu.magisk', 'eu.chainfire.supersu', 'com.koushikdutta.superuser'];
        PackageManager.getPackageInfo.overload('java.lang.String', 'int').implementation = function(pkg, flags) {
            if (rootPkgs.indexOf(pkg) !== -1) {
                console.log('[+] PackageManager blocked: ' + pkg);
                throw Java.use('android.content.pm.PackageManager$NameNotFoundException').$new();
            }
            return this.getPackageInfo(pkg, flags);
        };
    } catch(e) {}

    console.log('[RTExit] Root bypass loaded.');
});
