How does Android SuperUser app detect that an app requests root?

前端 未结 3 1841
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 23:15

I\'m writing an app that will use su to execute some commands in the linux kernel. I was wondering how SuperUser figures out that the application is asking for root

3条回答
  •  轮回少年
    2021-02-01 23:32

    When you run this:

    Process p = Runtime.getRuntime().exec("su");
    

    You are trying to execute "su" which only an app with superuser permissions can do! So whenever Android detects that you are trying to run "su" It will get that the App will need superuser permissions.

    Also, Android has some area reserved which only Android system can access. If your app is trying to access something there, Android will understand that superuser is needed.

    For example, say you are trying to modify the host file or modify some network configurations like DHCP. Or you are trying to access files from system area e.g. /data Android will check if the app has superuser permissions, and then only will grant it access to such things.

    About malicious software, whenever an app needs superuser access, system will prompt user to grant or deny superuser permissions to the app. Only then the app can get root access. So it's up to the user to decide, whether to accept or deny root access for any app. (System will prompt user every time an app is trying to access something that needs root access, UNLESS you tell system to remember your choice of acceptance or denial for a particular app.)

    PS: You might consider checking out website for Superuser app.

提交回复
热议问题