Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 13 Dec 2019, 11:44
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Listing all used/unused Busybox applets
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [12 Posts]  
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1944
Location: Japan

PostPosted: Fri 22 Feb 2019, 12:07    Post subject:  Listing all used/unused Busybox applets  

The file /bin/busybox contains dozens of utilities (busybox calls them applets) which can all be executed in one way or another, no matter if their more powerful GNU cousins are installed or not.

If no GNU equivalents exist, busybox applets are normally installed as symlink, e.g. /usr/bin/beep => /bin/busybox.

If GNU equivalents exist, busybox symlinked applets may still exist but with a -BB-NOTUSED suffix, making it impossible to invoke the busybox applet by just using its original name.

A few applets have equivalents in bash shell builtins or keywords (e.g. the echo command). Bash will always use its builtin utilities instead of using busybox or GNU applets (unless builtins are deactivated, but there is hardly a good reason to do that). Still busybox links are usually provided as well (e.g. /bin/echo => /bin/busybox) and the user *can* use them if he really needs to.

Above 3 possibilities should account for all applets compiled into busybox and the command "type -a appletname" should find at least one executable location for each applet. If not - and this is the reason why I created the script - the applet can not be invoked merely by its name. The command "which appletname" will produce no result and it appears as if the applet is not installed. I experienced this with the very useful strings utility. Only when checking the busybox list of all included applets I realized that it's there.

I wanted to know if more such "stealth utilities" exist.
The script lists all busybox applet names in the 2nd column and indicates in the 1st column if installed as

builtin   bash builtin
keyword bash keyword
bb    symlink to busybox
gnu    GNU utility
script  script, usually a wrapper for either bb or gnu
BBNU  symlink to busybox with -BB-NOTUSED suffix
FULL  GNU utility or symlink to GNU utility with -FULL suffix
-----  "stealth" applet which can't be invoked merely by its name

Script execution takes a few second and outputs to leafpad. Be patient Wink
Code:
#!/bin/bash
LANG=C LF=$'\n' TB=$'\t' IFS=$LF SEP=..............
OUT="Type${TB}Applets in current $(/bin/busybox | grep -om1 '^[^(]*')
------------------------------------------"
gxmessage -fn 'bold 14' -bg forestgreen -fg white -bu '' -bo -c  $'\n   Please wait ... ' &
for applet in $(busybox --list); do
  locations=$(type -a ${applet} ${applet}-FULL ${applet}-BB-NOTUSED 2>&1)
  for item in $locations; do
    unset category hint mime real path
    case $item in
     *[DL]:*) continue ;;                   #ex: "bash: type: echo-FULL: not found"
  *$applet:*) category=----                 #ex: "bash: type: strings: not found"
              hint="${SEP:${#applet}}( \"$applet\" not in \$PATH )" ;;
    *'is /'*) path=/${item#*/}              #ex: "echo is /bin/echo"
              real=$(realpath "$path")
              mime=$(file "$real")
              case $path$mime in
              *-FULL*   ) category=FULL   ;;
              *-NOTUSED*) category=BBNU   ;;
              *busybox* ) category=bb     ;;
              *script*  ) category=script ;;
              *         ) category=gnu    ;;
              esac
              [[ $real = $path ]] && hint=$path || hint="$path => $real"
              hint="${SEP:${#applet}}$hint" ;;
    *'is a'*) category=${item##* } ;;       #ex: "echo is a shell builtin"
           *) continue ;;
    esac
    OUT="${OUT}${LF}$category${TB}$applet $hint"
  done
done
busybox pkill -n gxmessage
echo "$OUT" |awk 'NR<=3{v=$2;print;next} v!=$2{print ""} v=$2{print}' | leafpad &

PS: Above script will not work with busybox versions older than 1.17.0 (2010-7-6) as they lack the --list option (see following post). The script might work with any version when replacing
   $(busybox --list)
with
   $(busybox | sed '1,/:$/d' | tr -s ' \t,' '\n')

[Update 2019-2-28]: Now also lists scripts with same name as applet, GNU utilities renamed as appletname-FULL and busybox symlinks named appletname-BB-NOTUSED. Adds "Wait" message and blank lines for better readability. Outputs to leafpad to allow search.
busybox_applets.png
 Description   Updated script now contains more types and outputs to leafpad instead of gxmessage
 Filesize   41.97 KB
 Viewed   488 Time(s)

busybox_applets.png


Last edited by MochiMoppel on Thu 28 Feb 2019, 08:44; edited 3 times in total
Back to top
View user's profile Send private message 
tallboy


Joined: 21 Sep 2010
Posts: 1572
Location: Drøbak, Norway

PostPosted: Sun 24 Feb 2019, 00:29    Post subject:  

Thank you for the script, MochiMoppel, it will be very useful.
Hmm, is applet a word that BB have used in earlier versions too, or is it just list? It seems list is not in the earlier version. If I want a list of applets, I only use the command busybox, whitout options. But that doesn't work in the script. I can search for bb-notused in pFind, but the result does not include builtins.
bb-list-result.jpg
 Description   
 Filesize   21.99 KB
 Viewed   417 Time(s)

bb-list-result.jpg


_________________
True freedom is a live Puppy on a multisession CD/DVD.
Back to top
View user's profile Send private message 
oldaolgeezer

Joined: 03 Dec 2006
Posts: 59

PostPosted: Sun 24 Feb 2019, 16:14    Post subject: Listing all used/unused Busybox applets  

MochiMoppel, I also thank you for the interesting script.

MochiMoppel's script "Listing all used/unused Busybox applets"
shows in my xenial-7.5 (32 bit) that the "strings" command is only available
via busybox as:
busybox strings foo.txt

(not as: strings foo.txt )


So, my question is why are some puppy commands available via busybox but not linked from /usr/bin ?

Thanks for any comments.
strings_only_in_busybox.png
 Description   
 Filesize   32.61 KB
 Viewed   371 Time(s)

strings_only_in_busybox.png

Back to top
View user's profile Send private message 
rufwoof


Joined: 24 Feb 2014
Posts: 3676

PostPosted: Mon 25 Feb 2019, 04:12    Post subject: Re: Listing all used/unused Busybox applets  

oldaolgeezer wrote:
So, my question is why are some puppy commands available via busybox but not linked from /usr/bin ?

I guess a similar reason to why your version of busybox has telnet, but mine doesn't. Developers drop in a version of busybox, maybe a upgraded version that contains different sets than before, but don't bother going through the laborious process of ensuring all of the commands (applets) links are updated within /bin

I believe that busybox is used to 'get things going' but the busybox commands are more limited than full(er) versions, so in some cases once things have got going may have fuller versions replacing (being used instead of) the busybox command/applet version. Somewhat like /bin (/sbin) and /usr/bin (/usr/sbin) ... where /bin (/sbin) contains the statics that are needed to boot the system (prior to /usr being mounted/available) and /usr/bin (/usr/sbin) contain the binaries once the system is up (/usr available).

_________________
( ͡° ͜ʖ ͡°) :wq
Fatdog multi-session usb

echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14542
Location: Gatineau (Qc), Canada

PostPosted: Mon 25 Feb 2019, 14:52    Post subject:  

MochiMoppei,

With all due respect, IMO, that is another waste of your formidable talent.
But it's yours to waste, not mine.

As for me, when I need this type of information, I type the following in terminal:
Code:
ls --file-type -Algorh | awk '$NF ~ /busybox/ { print $7,$8,$9 }' | sort | more
If I need it more that once, I recall it with the up arrow in terminal.

(Edit: $NF; thanks to Fabrice for noticing.)

Best regards nevertheless.
busybox-applets.jpg
 Description   Beginning of list created by above one-liner.
 Filesize   161.11 KB
 Viewed   306 Time(s)

busybox-applets.jpg


_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)

Last edited by musher0 on Tue 26 Feb 2019, 04:24; edited 1 time in total
Back to top
View user's profile Send private message 
fabrice_035


Joined: 28 Apr 2014
Posts: 656
Location: Bretagne / France

PostPosted: Tue 26 Feb 2019, 02:21    Post subject:  

Hello,

@musher0



Code:
root# awk --version
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)


Regard.

_________________
xenialpup 7.5 / Linux Kernel: 4.4.95 / Window Manager: JWM v2.3.7
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 105

PostPosted: Tue 26 Feb 2019, 02:48    Post subject:  

@fabrice_035:
Nothing to do with the awk-version,
just more crap and mind-pollution from
Musher0.Wasting everybodys time.


@Musher0: Please stop posting in threads in the Programming Section,
which you have not created.
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 105

PostPosted: Tue 26 Feb 2019, 03:02    Post subject:  

@MochiMoppel: Nice. Try LANG=C - gave me 30%.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1944
Location: Japan

PostPosted: Tue 26 Feb 2019, 03:40    Post subject: Re: Listing all used/unused Busybox applets  

some1 wrote:
Try LANG=C - gave me 30%.
Thanks. Here real time closer to 20% but CPU time 50%. I don't like the current performance, and things will get worse because I have to add more types. Naming everything that is not busybox as "gnu" is wrong. Could be that this "gnu" is not a GNU binary at all. Could be a script....linking to busybox Crying or Very sad Oh boy.

oldaolgeezer wrote:
my question is why are some puppy commands available via busybox but not linked from /usr/bin ?.
Good question. Same as mine Laughing Let's call it bad system configuration.
For example I have 2 files, the first being a GNU binary, the second a symlink to busybox
/bin/grep
/bin/grep-BB-NOTUSED

The wisdom of these xxx-BB-NOTUSED files aside, this keeps both files neatly together. I see BB-NOTUSED as a mere reminder that a busybox applet exists.

In the case of /usr/bin/strings-BB-NOTUSED no GNU file exists, which would call for naming the bb symlink /usr/bin/strings. That's the way it is normally done. Why not here? I think the main reason is that GNU strings does exist. It is included in the devx sfs. If you load this sfs you will see
/usr/bin/strings
/usr/bin/strings-BB-NOTUSED
If the bb symlink in the main sfs would be named /usr/bin/strings, the GNU binary /usr/bin/strings of the devx sfs would not be "seen" by the system and would not be usable.

There would be several ways to avoid such conflicts. The cleanest way would be move the GNU binary to the main sfs. It's a tiny file and it is very useful even for non developers. Another way would be to keep conflicting files in different paths, putting the fully featured GNU utilities into a path with high priority and the busybox versions into a path with lower priority as a fallback (or is it backstop?).
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14542
Location: Gatineau (Qc), Canada

PostPosted: Tue 26 Feb 2019, 04:25    Post subject:  

fabrice_035 wrote:
Hello,

@musher0



Code:
root# awk --version
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)


Regard.

Corrected. Thanks for noticing.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
perdido


Joined: 09 Dec 2013
Posts: 1439
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Tue 26 Feb 2019, 11:53    Post subject:  

some1 wrote:

Nothing to do with the awk-version,
just more crap and mind-pollution from
Musher0.Wasting everybodys time.


@Musher0: Please stop posting in threads in the Programming Section,
which you have not created.


+1

.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1944
Location: Japan

PostPosted: Thu 28 Feb 2019, 02:52    Post subject:  

I have updated my script (see first post for new code and explanation)

It now lists applet scripts and applet names suffixed with -FULL and/or -BB-NOTUSED.
When an applet is listed multiple times, the first entry in the list is the one that will be executed when invoked with just the applet name.

For example the screenshot shows that a user who enters just ps into a terminal will start a script (= first item in the list). A GNU utility exists but can only be directly executed by entering ps-FULL. Users who need to directly start the busybox applet would have to enter busybox ps. The file /bin/ps-BB-NOTUSED is linked to busybox but, as all -BB-NOTUSED symlinks, is not valid and will cause busybox to trigger an error when executed.

Since some applet names appear more than once I find the list easier to read with blank lines before each new applet name. Removing the awk statement will prevent blank line creation.
busybox_applet_list.png
 Description   
 Filesize   54 KB
 Viewed   133 Time(s)

busybox_applet_list.png

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [12 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0723s ][ Queries: 13 (0.0095s) ][ GZIP on ]