// Ripped from https://github.com/Ch0pin/medusa/ and modified to fit Androguard packets

colorLog('[+] LOADING HELPER/ANTIDEBUG/PACKAGE.JS',{c: Color.Red});

var PackageManager = Java.use("android.app.ApplicationPackageManager");

var RootPackages = [
    "com.noshufou.android.su", 
    "com.noshufou.android.su.elite",
    "eu.chainfire.supersu",
    "com.koushikdutta.superuser",
    "com.thirdparty.superuser",
    "com.yellowes.su",
    "com.koushikdutta.rommanager",
    "com.koushikdutta.rommanager.license",
    "com.dimonvideo.luckypatcher",
    "com.chelpus.lackypatch",
    "com.ramdroid.appquarantine",
    "com.ramdroid.appquarantinepro",
    "com.devadvance.rootcloak",
    "com.devadvance.rootcloakplus",
    "de.robv.android.xposed.installer",
    "com.saurik.substrate",
    "com.zachspong.temprootremovejb",
    "com.amphoras.hidemyroot",
    "com.amphoras.hidemyrootadfree",
    "com.formyhm.hiderootPremium",
    "com.formyhm.hideroot",
    "me.phh.superuser",
    "eu.chainfire.supersu.pro",
    "com.kingouser.com",
    "com.android.vending.billing.InAppBillingService.COIN",
    "com.android.vending.billing.InAppBillingService.LUCK",
    "com.chelpus.luckypatcher",
    "com.blackmartalpha",
    "org.blackmart.market",
    "com.allinone.free",
    "com.repodroid.app",
    "org.creeplays.hack",
    "com.baseappfull.fwd", 
    "com.zmapp",
    "com.dv.marketmod.installer",
    "org.mobilism.android",
    "com.android.wp.net.log", 
    "com.android.camera.update",
    "cc.madkite.freedom",
    "com.solohsu.android.edxp.manager", 
    "org.meowcat.edxposed.manager",
    "com.xmodgame",
    "com.cih.game_cih",
    "com.kingroot.kinguser", 
    "com.charles.lpoqasert",
    "catch_.me_.if_.you_.can_",
    "com.topjohnwu.magisk",
    "com.kingo.root",
    "com.smedialink.oneclickroot",
    "com.zhiqupk.root.global",
    "com.alephzain.framaroot"
];

PackageManager.getPackageInfo.overloads[0].implementation = function(pname, flags) {
    agPacket({pname: pname, flags: flags}).send();

    var shouldFakePackage = (RootPackages.indexOf(pname) > -1);
    if (shouldFakePackage) {
        agSysPacket({information: "bypass", package: pname}).send();
        pname = "set.package.name.to.a.fake.one.so.we.can.bypass.it";
    }
    return this.getPackageInfo.call(this, pname, flags);
};



PackageManager.getPackageInfo.overloads[1].implementation = function(sname, flags) {
    agPacket({sname: sname, flags: flags}).send();

    var shouldFakePackage = (RootPackages.indexOf(sname) > -1);
    if (shouldFakePackage) {
        agSysPacket({information: "bypass", package: sname}).send();
        sname = "set.package.name.to.a.fake.one.so.we.can.bypass.it";
    }

    return this.getPackageInfo.call(this, sname, flags);
};