CaptainBeyondDS8/text-editor-8000

Replace rootfw with something better

CaptainBeyondDS8 opened this issue · 4 comments

Currently TE8k ships with a stale version of rootfw which was patched to work around some bug, I think.

The library isn't particularly dead (it got some updates since I forked from Turbo Editor) but it may be worthwhile to switch to libsu instead, which is by the developer of Magisk and is used in Magisk Manager. This library comes with its own bundled busybox which can work around issues where the system busybox is broken or missing.

libsu is nice because it mirrors the Java IO classes and also somewhat simplifies the process of setting up the shell (whereas RootFW requires you to connect and disconnect whenever you need to use it). I haven't gotten around to testing it but it should work well.

If necessary we could enable the bundled busybox but I imagine we won't have to.

I have observed that:

  • Directory listing works fine
  • Saving files works fine as long as the file-system is writable
  • On a read-only file-system, as expected, saving files does not work. However, for some reason, it fails to throw an exception and returns successfully. Log is below:
06-24 20:15:26.667  8801  9003 D SHELL_IN: FILE='/etc/hosts'
06-24 20:15:26.667  8801  9003 D SHELL_IN: rm -f "$FILE" || rmdir -f "$FILE" >/dev/null 2>&1 && echo true || echo false
06-24 20:15:26.667  8801  9003 D SHELL_IN: FILE=; CFILE=
06-24 20:15:26.678  2791  6110 W InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@940671f attribute=null, token = android.os.BinderProxy@1535b56
06-24 20:15:26.687  8801  8970 D SHELLOUT: rm: /etc/hosts: Read-only file system
06-24 20:15:26.706  8801  8968 D SHELLOUT: false
06-24 20:15:26.707  8801  9003 D SHELLIMPL: runSyncTask
06-24 20:15:26.707  8801  9003 D SHELLIMPL: runCommands
06-24 20:15:26.707  8801  9003 D SHELL_IN: FILE='/etc/hosts'
06-24 20:15:26.707  8801  9003 D SHELL_IN: [ -e "$FILE" ] >/dev/null 2>&1 && echo true || echo false
06-24 20:15:26.707  8801  9003 D SHELL_IN: FILE=; CFILE=
06-24 20:15:26.708  8801  8968 D SHELLOUT: true
06-24 20:15:26.708  8801  9003 D SHELLIMPL: runSyncTask
06-24 20:15:26.709  8801  9003 D SHELLIMPL: runCommands
06-24 20:15:26.709  8801  9003 D SHELL_IN: FILE='/etc/hosts';CFILE="`readlink -f '/etc/hosts'`"
06-24 20:15:26.709  8801  9003 D SHELL_IN: [ -b "$FILE" ] && blockdev --getsize64 "$FILE" || stat -c '%s' "$CFILE"
06-24 20:15:26.709  8801  9003 D SHELL_IN: FILE=; CFILE=
06-24 20:15:26.736  8801  8968 D SHELLOUT: 56
06-24 20:15:26.738  8801  9003 D SHELLIO : dd bs=57 count=1 >> '/etc/hosts' 2>/dev/null; echo done

It encounters a "read-only file system" error several times and seems to disregard it. I need to figure out if I can test for this beforehand, or see if it's actually a bug in libsu.

Still keeping it unmerged for now because I feel a false positive here is a dealbreaker.

Also should investigate issues such as this where quote marks were being escaped inappropriately.

Also https://github.com/vmihalachi/turbo-editor/issues/133 https://github.com/vmihalachi/turbo-editor/issues/98 and such

I seem to recall running into this same issue, but it seems to be inconsistent so it may be a problem specific to device or OS (e.g. busybox version, etc). It doesn't occur to me with libsu but I haven't tested rootfw recently so I don't know if that's a factor.

I should test it on my tablet as that's where I may have been running into issues.

I can recreate the quote marks being escaped issue on my tablet, with both Turbo Editor/rootfw and Text Editor 8000/libsu. So it may unfortunately be a problem with the busybox on the tablet. I'll test it out with the embedded busybox from libsu and see if it still occurs.

Also tried to test out 920 Text Editor (which also should be able to write as root) to see if it has the same issue, and it keeps crashing.