Android Question Magisk alternative to SuperUser and Shell

seskindell

Active Member
Licensed User
Longtime User
Does anybody know how to route a shell command to Magisk?

With Superuser I use to set the date:
B4X:
    Dim command, runner As String
        Dim stdout, stderr As StringBuilder
        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", "date -s " & todate & "." & totime & "; \n" & CRLF & "exit")
        ph.Shell("sh", Array As String(runner), stdout, stderr)

What would I replace "su < " for magisk?

Thank you for any help!

- Steve
 

JohnK

Active Member
Licensed User
Longtime User
Does anybody know how to route a shell command to Magisk?

With Superuser I use to set the date:
The code you use for Magisk and/or SuperUser should be the same.

One thing to be careful of with Magisk is that it is still in development, and a lot of users are using Beta versions, which do have bugs.

On a side, the script file you are running does not have the bang operator at the top of the file
B4X:
#!/system/bin/sh
setting the date, is a dangerous thing in that it has effects beyond an actual root check, if you get it wrong; and I know I would personally not want any app trying this on my phone! There are many other commands to run requiring SU without making permanent changes on a device.

Generally, on a personal preference level, I would not use the SU with a "<". I would prefer a
B4X:
su -c myrootcommnd;
and even better in my personal view (ie what I use personally use) is
B4X:
Ph.Shell("su", Array As String("-c", sToRun), StdOut, StdErr)
 
Upvote 0
Top