Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request superuser rights to edit file

Tags:

android

I'm planing an app where i need to edit a system file.

I can only edit that file with root rights. I have a rooted dev phone with Superuser.apk installed. Other apps that require root do request root access on first start. I want to do the same but I can't find any hints on how to request superuser rights for my app.

I found something about an intent android.intent.action.superuser but when I try to launch an activity for that intent action I get an ActivityNotFoundException.

Any ideas?

like image 274
Goddchen Avatar asked Nov 05 '22 07:11

Goddchen


1 Answers

The intent does not actually get you superuser rights, it just interacts with the superuser app's permission granting mechanism.

The real key is to understand that android's underlying linux does not support escalation of a user's privileges. Instead, it supports (/has been modified to support) a mechanism for a user to request to run _some_other_process_ as the superuser.

What this means is that the actual root-rights task will have to be done by a different executable, probably a native 'command line' one which you will launch under delegation by the su command or whatever your particular modified android build supports. It will be easiest if you can figure out how to do the task using one of the built-in toolbox command line programs - for example, write the file somewhere else and then mv (and maybe chown) it to where you want. Also bear in mind that /system is typically mounted read-only, and you would have to remount it rw before you can write there.

Put a lot of thought into anything you try to do as the superuser... it's easy to make a mess or leave problems behind. If you are deploying the app to others, also think about security holes you will be creating.

like image 57
Chris Stratton Avatar answered Nov 09 '22 16:11

Chris Stratton