From:
https://www.b4x.com/android/forum/threads/check-if-device-rooted.127150/
I have this bit of code:
To make it harder for a miscreant to decompile and work out what I have done I would like to pass:
String[] places = {"/sbin/",
"/system/bin/",
"/system/xbin/",
"/data/local/xbin/",
"/data/local/bin/",
"/system/sd/xbin/",
"/system/bin/failsafe/",
"/data/local/"};
into the inline java from the B4A code, something like:
but I'm getting totally lost - even with lots of googling.
Can anyone steer me to the correct syntax?
Thanks in anticipation...
PS I would also like to pass in the "su" string.
https://www.b4x.com/android/forum/threads/check-if-device-rooted.127150/
I have this bit of code:
B4X:
Private Sub Activity_Create(FirstTime As Boolean)
'Check if device is rooted
Private jo As JavaObject
jo.InitializeContext
Private rooted As Boolean = jo.RunMethod("isRooted", Null)
If rooted Then ExitApplication
...
#If Java
import java.io.*;
public static boolean isRooted() {
return findBinary("su");
}
public static boolean findBinary(String binaryName) {
boolean found = false;
if (!found) {
String[] places = {"/sbin/",
"/system/bin/",
"/system/xbin/",
"/data/local/xbin/",
"/data/local/bin/",
"/system/sd/xbin/",
"/system/bin/failsafe/",
"/data/local/"};
for (String where : places) {
if (new File(where + binaryName).exists()) {
found = true;
break;
}
}
}
return found;
}
#End If
To make it harder for a miscreant to decompile and work out what I have done I would like to pass:
String[] places = {"/sbin/",
"/system/bin/",
"/system/xbin/",
"/data/local/xbin/",
"/data/local/bin/",
"/system/sd/xbin/",
"/system/bin/failsafe/",
"/data/local/"};
into the inline java from the B4A code, something like:
B4X:
Private Sub Activity_Create(FirstTime As Boolean)
'Check if device is rooted
Private jo As JavaObject
jo.InitializeContext
Private rooted As Boolean = jo.RunMethod("isRooted", Array( & _
"/sbin/", & _
"/system/bin/", & _
"/system/xbin/", & _
"/data/local/xbin/", & _
"/data/local/bin/", & _
"/system/sd/xbin/", & _
"/system/bin/failsafe/", & _
"/data/local/"))
If rooted Then ExitApplication
...
#If Java
import java.io.*;
public static boolean isRooted(String[] places) {
return findBinary("su");
}
public static boolean findBinary(String binaryName) {
boolean found = false;
if (!found) {places};
for (String where : places) {
if (new File(where + binaryName).exists()) {
found = true;
break;
}
}
}
return found;
}
#End If
but I'm getting totally lost - even with lots of googling.
Can anyone steer me to the correct syntax?
Thanks in anticipation...
PS I would also like to pass in the "su" string.