Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit: All version of codes below DOES NOT mount system as RW.</strong> *Read comments below to see why. Solution of this is not a simple command. </p> <p>Edit1: I went on Super User apk, Settings tab, and "tapped" at the last item, to update the su binary. With that update, everything below isnt working.</p> <p>Edit2: started a whole conversation with my self here. Fix for the current latest binary is at the bottom of the post</p> <p>==================================================================================</p> <p>Found out how to do it! Second day of efforts, and finally found it!!!!! Tried several things, and answer was to a simple change mode,</p> <p>what i have done:</p> <p><em><strong>First Version Code:(doesnt work)</em></strong></p> <pre><code>String[] mountRW = { "su", "-c", "chmod 777 /system/etc/build.prop"}; String[] mountRO = {"su", "-c", "chmod 755 /system/etc/build.prop"}; //TODO REMOVE testing purposes File file2 = new File("/system/build.prop"); //Make file Read-Write process = Runtime.getRuntime().exec(mountRW); process.waitFor(); //TODO REMOVE testing purposes Log.d("MOUNT RW?", "RW WRITABLE? "+ file2.canWrite()); /////////////////////// // process the file ////////////////////// // After editing finish, //make Read Only file again process = Runtime.getRuntime().exec(mountRO); process.waitFor(); //TODO REMOVE Log.d("MOUNT RO?", "RO WRITABLE? "+ file2.canWrite()); </code></pre> <p>I didnt paste some try catch cases. Also i got another problem.. And i solved it in Version 2. THe little problem was, that, i was asking for a specific for a su command, and the user, had to accept SU cmd for RO, SU cmd for RW.. and another time for other stuff in my program. In 2nd version i m using the generic su command, so user has to accept SU privileges only ONE time, and i m using output stream.</p> <p><em><strong>Code Version 2(Recomended) (doesnt work)</em></strong>:</p> <pre><code>String mountRW = "chmod 777 /system/build.prop"; String mountRO = "chmod 755 /system/build.prop"; //TODO REMOVE File file2 = new File("/system/build.prop"); //Make file Read-Write process = Runtime.getRuntime().exec("su"); //Generic SU Command os = new DataOutputStream(process.getOutputStream()); os.writeBytes(mountRW + " \n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); //TODO REMOVE Log.d("MOUNT RW?", " RW WRITABLE? "+ file2.canWrite()); //////////////////////////// /// mod the file /////////////////////////// // After editing finish, make Read Only file again process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(mountRO + " \n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); //TODO REMOVE Log.d("MOUNT RO?", "RO WRITABLE? "+ file2.canWrite()); </code></pre> <ul> <li><strong>Both codes require Root on your device.</strong></li> <li><strong>Both versions doesnt include catch cases. (Eclpise will found them for you)</strong></li> <li><strong>Check out your logcat(adb logcat), to see that indeed it works!</strong></li> <li><strong>With latest su binary, this code changes slightly. The change mode command requires 4 digits. 0777 for rw permissions, and 0755 for ro permissions!</strong></li> <li><strong>This code by its own, it does nothing to your device.</strong></li> </ul> <p><strong>Only it mounts built.prop RW, and then mounts it back to RO. Although if you change it, you may brick your device! Take care!</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COYou are not "mounting" anything, and as a result this code will not normally work. Ordinarily, you must remount the /system partition writeable, probably you did in a previous try. Your command strings that you erroneously term "mountRW" & "mountRO" do not accomplish mounting, but instead change the file permissions so the non-root process running your java code can change the file. You should re-name these to "chmodRW" or something like that. And if you want it to be generally useful (to the extent anything requiring root can be general) you will need to handle the remounting of /system
      singulars
    2. COHello Chris! Thanks for spending your time answering. The Ver2, worked well on the su binary version i had on my superuser.apk on my device. But i update the su binary to the latest, and it failed. Now i figured out again. The chmod cmd needs 4 digits to work. eg "0777" for mounting. This code it's like a prototype, that i want to share, because it took me lot of time and effort to figure. It's not what i m actually doing in my program. Isnt it good, that i m not mounting RW the whole system, but a specific file i want to mod? And then give back RO permission? I'd like to have your opinion!:)
      singulars
    3. CO@Psachialis. You are mistaken. "chmod" does not "mount" anything. Your code solves a different problem of letting a non-root process modify a protected file on an already writeable file system, and is only sufficient because you have already mounted the entire /system writeable at some previous time since the last reboot. Power cycle your device you should find that it will then fail (unless you have a nonstandard and poorly designed device that normally has /system mounted writeable)
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload