shell root

fpdianzen

Member
Licensed User
Longtime User
hi good day.

im confused, with the existing tutorials with shell root command...
i want to execute this actions.
by the way. it has also a directory
and it has a directory of "/system/bin/"
B4X:
#su
# setprop ctl.stop adbd
please help me guys. :sign0104:
 

joseluis

Active Member
Licensed User
Longtime User
I'm not very familiar with this subject but I don't understand what is exactly the problem you encounter.

¿Could you upload an example so it's easier to help you?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
haha...i didnt realize that :sign0142:
i just wanted to keep him busy for a few hours!

okay, try this:
B4X:
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
StdOut.Initialize
StdErr.Initialize
Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "cd /system/bin" & CrLf & "setprop ctl.stop adbd" & CrLf & "exit") 'Any commands via crlf, and exit at end 
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Msgbox(StdOut.tostring, "")
 
Last edited:
Upvote 0

nachoap10

Member
Licensed User
Longtime User
Hi!

I've a little lost with rooted devices.

I've rooted mi Sony RS T1 ebook reader, and I'm trying to make my lipapa app in a way it can run in this device. I'm having a lot of problems with its android, but worst is I can copy a simple file in a folder.

In this device folders in external sd have root permissions to read, write and execute, and group permissions are the same, but other permissions can't write. I can't change these, nor by the Root Explorer app, nor by Terminal Emulator, nor by B4A and this shell example, making a "chmod 777 /mnt/extsd/folder" in the same way I can launch other commands.

This device has other hell problem: if you try to put in it larger collections of books, it explores every book and, over about 2,000 books, it crashes or makes inestable. So, in order to put all my books (about 14,000), I have to hide them (in a folder with a dot before the name, i.e. ".BOOKS"). But when I try to call my app reader (cool reader), it can't find the book because it's in a hidden folder :BangHead:, so I've to move the selected book to other "visible" folder... But I can't :BangHead::BangHead::BangHead:

The code you have written works with some commands. For example, I can create a new folder (as root; if I try to create it with normal B4A commands it fails, because SD is a rooted device and I can't change it, or I don't know how to change it :signOops:), but it fails with a simple copy command.

I'll show my code:

My "Execute as root" routine. It should execute a single line command passed in the "comando" parameter:

B4X:
Sub EjecutarRoot (comando As String)
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
   

   Runner = File.Combine(File.DirInternalCache, "runner")
   Command = File.Combine(File.DirInternalCache, "command")
   File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
   File.WriteString(File.DirInternalCache, "command", comando & CRLF & "exit") 'Any commands via crlf, and exit at end 
   StdOut.Initialize
   StdErr.Initialize
   Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
   Msgbox(StdOut.tostring, "")
End Sub

Now, my calling routine:

B4X:
Sub Test
   ' First command runs perfectly
   EjecutarRoot("mkdir /mnt/extsd/MISLIBROS")

   ' Second command is ignored
   EjecutarRoot("cp /mnt/extsd/kkk.fb2 /mnt/extsd/MISLIBROS/kkk.fb2")
End Sub

File kkk.fb2 exists in /mnt/extsd, and has got read and execution permissions for all users, and write permissions for root and group. Case is correct, file is correct... but Second command doesn't work.

I'm desesperated. Almost every thing I try is wrong with this device, and I don't know too much of linux world nor android world.

Well, I would like to put here my question: Is there a way to execute all the app as root, in order every File.Copy (for example) executes as root as well? If there is, could you be so kind to tell me how could I program it? If it's not possible, could anyone tell me if I'm making any stupid mistake I can't see?

Thank you in advance.

Edit: I forgot mentioning it: If I try a File.MkDir, it doesn't work. The only way I've found to create a folder from B4A in this device is using the EjecutarRoot routine
 
Last edited:
Upvote 0

corsaro

Member
Licensed User
Longtime User
I made this B4A library to execute su commands. Join it

B4X:
import java.io.DataOutputStream;
import java.io.IOException;

import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;



@ShortName("SuCommand")
@Permissions(values={"android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS" })
@Author("corsaro")
@Version(1)

public class SuCommand 
{
    /**
     * insert the su command as string.
     * Example:
     * Dim su As SuCommand
     *  su.SuCommand("chmod 777 /data/data/destination")
     * 
     *
     */
   
       public void SuCommand (String command){
   
          {
                Process chperm;
                
                try {
                   
                   
                    chperm=Runtime.getRuntime().exec("su");
                      DataOutputStream os = 
                          new DataOutputStream(chperm.getOutputStream());
                      
                      os.writeBytes(command+"\n");
                        os.flush();
                       
                                            
              

                          os.writeBytes("exit\n");
                          os.flush();

                          chperm.waitFor();
                      //    Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                   //Toast.makeText(getApplicationContext(), "IOException", Toast.LENGTH_SHORT).show();
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InterruptedException e) {
                   //Toast.makeText(getApplicationContext(), "InterruptedException", Toast.LENGTH_SHORT).show();
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
          }
          
       }
       
}


usage example

B4X:
 Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   Dim su As SuCommand
   
   su.SuCommand("chmod 777 /data/data/destination")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Attachments

  • SuCommand.zip
    2.3 KB · Views: 863
Last edited:
Upvote 0

corsaro

Member
Licensed User
Longtime User
Good work.
You dont need to add those contacts permissions in the library?

Hello.
thanks for your message.

Yes, contacts permissions are not needed. They was there, from a precedent experiment. I forgot to remove them.

Anyway, probably depending from what kind of su command you pass to the library, appropriate permissions could be needed....

With the attached library, I was success changing permissions (chmod) and owner (chown) to /data/data files

for /system files, obviously you need before to remount system partition as read write, using a sucommand like
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system

Using the source code I attached, everyone can try to recompile the suCommand library, using appropriate permissions.

I think we have to wait for more experience from other users before making a perfect library....
 
Last edited:
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
I have removed the "Contacts" permission and added "android.permission.ACCESS_SUPERUSER"

:)
 

Attachments

  • SuCommandFixed.zip
    2.4 KB · Views: 677
Upvote 0
Top