[Magisk] zgfg:
Continuing on the previous talk about /system/bin

That folder provides pre-installed Linux binaries and utilities (many are needed by the system itself like during the booting to System), and that includes also the toybox tool-box, ie, the toybox binary and its applets (Linux utilities to be executed by the toybox binary and linked to the toybox binary)

If I recall correctly, toybox comes already as part of AOSP, those utilities that are needed to run the AOSP build scripts (except for the compiler, linker, and so)

Hence the pre-installed toybox with its applets built into the AOSP are self-sufficient to rebuild AOSP (that was like the agenda behind)

Now, I'd like to ask those of you who are not afraid of Terminal emulator, to run the following commands to find about the toybox preinstalled to your ROMs

Commands must be executed in the given order, since I define some variable ($TB), switch to a particular directory, and use them all till the end

First we look if the toybox binary is preinstalled, where (full path), and for its version:

su
TB=toybox
which $TB
ls -l $(which $TB)
$TB --version

# to learn more, read:
$TB --help

Expected output will be: /system/bin/toybox (maybe on some older ROMs /sbin/toybox ?!), v0.8.4-android or so (on my two phones)

Btw the latest toybox is v0.8.9 from Jan 2023, see the official ToyBox site https://landley.net/toybox

Now we extract the system folder/path where the toybox is installed, change to that directory and print the current path (pwd):

cd $(which $TB | sed "s,/$TB$,,")
pwd

Now we look for the expected toybox utilities to be installed to the same directory (I'm looking for the utilities I'm just using: cut, grep, ls, pwd, sed, wc, which; the others like cd and rev are provided by the shell itself, hence I don't need an additional tool-box like busybox and its applets)

ls -l cut
ls -l grep
ls -l ls
ls -l pwd
ls -l sed
ls -l wc
ls -l which

They are expected to be linked to the toybox binary with chmod 755 or 744 (executable files), like:

lrwxrwxrwx 1 root root 6 1971-07-07 12:40 cut -> toybox
lrwxrwxrwx 1 root root 6 1971-07-07 12:40 grep -> toybox
lrwxrwxrwx 1 root root 6 1971-07-07 12:40 ls -> toybox
lrwxrwxrwx 1 root root 6 1971-07-07 12:40 pwd -> toybox
lrwxrwxrwx 1 root root 6 1971-07-07 12:40 sed -> toybox
lrwxrwxrwx 1 root root 6 1971-07-07 12:40 wc -> toybox
lrwxrwxrwx 1 root root 6 1971-07-07 12:40 which -> toybox

Hence they can be called two ways, like:

toybox cut --help

# or shorter, just:
cut --help

Now we list all files in this directory (line by line), grep (filter) for those having toybox in the line/string (either the toybox binary itself or applets linked to the toybox binary) and additionally filter from them those being the executable links (lrwx), and count the number of these filtered lines:

ls -l | grep $TB | grep ^lr.x | wc -l

Expected result will be like 174 (latest toybox v0.8.9 can provide many more, 233 applets), meaning that we have the toybox binary with eg 174 its applets

To summarize, we will use the trick with reversing the lines/strings and cutting out their third fields (applet names) but counting the field ordinals from the (reversed) beginning, since the cut utility cannot count and cut from the end :)

Eg, we have to extract the third field/word (applet name) counting from the end, say: pwd, from the ls -l line/string ending with the known end part of the format like:

... pwd -> toybox

hence we execute:

ls -l | grep $TB | grep ^lr.x | rev | cut -d ' ' -f 3 | rev

Expected list of the pre-installed toybox applets will include: [ (aka the test utility), test, utilities mentioned above, and more like cat, chmod, echo, find, ln, gunzip, gzip, kill, mkdir, mount, printf, rm, rmdir, sleep, sort, touch, tar and so on:

Spoiler content hidden.

---

Finally, I would be interested to see from your ROMs - thanks in advance:

- do you have toybox pre-installed

- is it pre-installed to /system/bin or some other directory

- which version (couple of years ago old v0.8.4 or maybe newer)

- how many toybox executables are preinstalled in your ROM (174 or more or less)