Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
99 views
in Technique[技术] by (71.8m points)

android - Check if device is rooted using /system

Is there any way to get these filesystems mounted with the "rw" flag.

I am trying to detect if the device is rooted or not by Checking for writable partitions and system directories in files of android devices.

Thanks in advance for your helping :).

question from:https://stackoverflow.com/questions/65921440/check-if-device-is-rooted-using-system

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, what else can I say.

Test 1

File dir = new File("/system");
if(dir.canRead() && dir.canWrite()) {
   System.out.println("Can read and write in this directory. (rw)");
} else if(dir.canRead()) {
    System.out.println("Can read in this directory (r)");
} else if(dir.canWrite()) {
    System.out.println("Can write in this directory (w).");
} 

Output

Can read in this directory (r)
$ mount | grep '/system'
/dev/block/platform/13540000.dwmmc0/by-name/SYSTEM /system ext4 ro,seclabel,relatime,norecovery 0 0

Test 2

dir = new File("/storage/emulated/0");
if(dir.canRead() && dir.canWrite()) {
   System.out.println("Can read and write in this directory. (rw)");
} else if(dir.canRead()) {
   System.out.println("Can read in this directory (r)");
} else if(dir.canWrite()) {
   System.out.println("Can write in this directory (w).");
} 

Output

Can read and write in this directory. (rw)
$ mount | grep '/storage/emulated'
/data/media /storage/emulated sdcardfs rw,seclabel,nosuid,nodev,noexec,relatime,low_uid=1023,low_gid=1023,gid=9997,multi_user,mask=0007,reserved=20MB 0 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...