How to check if the mobile device is running in root mode?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jedzkie

As the title says, is it possible? or is there a built-in function for it?

:bust_in_silhouette: Reply From: Wakatta

Check for the su binary usually in “/sbin/su” or “/system/bin/su” however with all of the exploits today it’s possible for it to be in other locations. And The /system partition is unaccessible by default. So use.

var process_id = OS.execute("su", [], false)
if process_id:
    #rooted
    pass

Thanks Wakatta, I’ll let you know later the results.

Jedzkie | 2021-09-14 03:55

Hi Wakatta, It’s not working on my side. Not sure if I done it correctly, but my plan is checking if the phone is rooted, then the game will not run else continue.

Jedzkie | 2021-09-14 04:34

Understood.

The only other idea that comes to mind is to use the which command which is used to locate the executable su file. Since that command isn’t part of Android by default if it completes successfully then the device is rooted.

As mentioned before there are just too many rooting exploits and you most likely will have to consistently upgrade your app to match them. One way to do that is to keep a list of applications related to rooting and test to see in any are installed using the pm (package manager) command

Wakatta | 2021-09-14 05:09

Thanks Wakatta!

Jedzkie | 2021-09-16 17:01