Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,734,168 Members 50,689 Now Online
XDA Developers Android and Mobile Development Forum

[Shell][mksh][Scripting][Tweaks-Upgrade][flash.zip][bins]::mksh-FULL:::grep:::busybox

Tip us?
 
7175
Old
(Last edited by 7175; 20th July 2014 at 05:26 AM.) Reason: update
#1  
7175's Avatar
Senior Member - OP
Thanks Meter 228
Posts: 189
Join Date: Feb 2013
Default [Shell][mksh][Scripting][Tweaks-Upgrade][flash.zip][bins]::mksh-FULL:::grep:::busybox

:::BRIEF DESCRIPTION:::
mksh is the official, currently-developed shell used for android. It is not an app nor a virus (lol) like some people seem to think, looking at a quick xda search. And as the core shell for android, it is used to shell superuser, so if you're rooted and get a message saying "mksh requests root", that basically just means that superuser is being run correctly and is using the default Android shell that is in every android device. (GOOD)
If you get a message saying bash(or any other shell) requested root, and you're NOT in the terminal interactively. That most likely is NOT GOOD! Almost all bash scripts I've seen will run shelled with mksh, so be safe and shebang with mksh. You'll have better performance and features, and when you see bash requesting root, you'll know your security is likely compromised if you allow it, instead of sitting there wandering whether to allow/block it.


::: mksh Resources/links :::

mirbsd mksh main page: https://www.mirbsd.org/mksh.htm

mksh man page: https://www.mirbsd.org/htman/i386/man1/mksh.htm


Now that that's out of the way, I've attached a recovery flash zip to this post containing a full mksh(R48 August 2013 from CFX ROM), full mkshrc modded for android, bunch of fpath functions like a much needed basic sudo, parallel sudo(sexe), required libc.so and libc_malloc*.so libs, and alternate busybox.ndk and standalone grep bins. The pexec, grep bins are from alireza7991. The mksh binary was compiled with O3 aliasing, Clanged CodeSourcery toolchain by CFX. It's very stable. An R49 variant would be nice if I could get someone to compile it.

(Installer uses a modded version of Chainfire's great no-edify script.)


Features scripted into mkshrc:

--sudo: auto detects supersu for mount master (highly recommended) or CWM su
e.g.:
Code:
sudo mount -o rw,remount -t f2fs /system /system
sudo cat <<< $'\n' >> /system/build.prop
sudo 'sysrw; for i in /system/*; do chown 0 "$i" ; done; sysro'
--suid: (set user id) Uses chpst to run a prog setsuid, this is broken in most busyboxes so I included one with a working chpst. "suid" is probably needed as much or even more than a sudo. Hopefully it gets added to the two "superuser" programs sometime. Usage:::
e.g.:
Code:
suid 1000 sh
--Better tab completion: unjams clustered words:
e.g.: <[cursor]> is cursor position
Code:
ec<[cursor]>12345 + tab ---> echo 12345
--Added "control + u" to "cut-to-beginning of line" like bash.

--TMPDIR: mounts a tmpdir at /tmp for all users and random generates subdirs for individual secured tmpdirs. This fixes here-docs, here-strings, and here-executions. To get a /tmp directory mounted, you need to run su once upon booting android. Just type "ss" upon first starting up terminal emulator.
e.g.:
Code:
su << 'eeooff'
sysrw; chgrp 2000 /system/bin; sysro
! (( $? )) && print -- -changed them bin group-
eeooff
--Basic "help" command: Android lacks this and the doc is still under development I believe. I added all the basic info(cmd forms) for mksh bultins to a command help(aliased to h):
e.g.:
Code:
help mkn
> mknod [-m mode] name b|c major minor
> mknod [-m mode] name p
or
Code:
h ''
(all help is printed, grep from here if you want)

--Very complicated-programmed and colorful PS1 prompt, it looks good and I thought it through. Programming shows mksh potential for rich shell programming. It auto-turns off xtrace within itself so that 50 lines don't get printed each return with set -x. mksh small will be autodetected and give a different white and black classic ksh prompt.

--ton of ultra lazy aliases, got my android scripting speed up to ~70% my normal pc speed.

--full mkshrc functions from official mkshrc like pulld,popd,dirs,more,hd,64encode,64decode,hashopti mizations


The latest full R49 source with original mkshrc and complete mksh manual is completed. It'll be installed to /system/etc/mksh...zip and /system/etc/mksh...pdf. I use Document Viewer from fdroid to view it.


The scripting in this is very sophisticated and complex, especially the inherent full mkshrc functions. It would make a good scripting learning tool to say the least. I know I've learned twice what I knew from bash scripting back 3 months ago.


I've been working on modding the full mkshrc a while, so I appreciate any error reports. Shouldn't be any problems though.

Modifying the mkshrc file / mksh shell has system-wide effects, so PLEASE nandroid backup as usual!!! This should be COMPATIBLE with all androids, but has only been tested on my Galaxy Nexus thus far.


EDIT: It appears the libc required for full mksh isnt always friendly with a few apps like GTA SA, so I made it so that mksh small is installed to system, and I added a function to run full mksh installed to /data/media/shell. Just type:
"mkmk" or "mkmksh" for full mksh. This is added as an fpath function now so any *ksh can run it that has FPATH defaulted or set to /etc/fpath.

Also reprogrammed sudo with pexec, so it can do parallel executions. pexec, grep, and a full busybox are included.

For Jack Palevich's terminal emulator or connectbot, telnet, etc, I use this as my su'd "shell" command under >>Options>>Shell:
Code:
/system/xbin/su --shell /system/bin/mksh --command exec /system/bin/pexec -z -15 --shell /system/bin/mksh -m 'export LD_LIBRARY_PATH=/data/media/shell:"$LD_LIBRARY_PATH"; export PATH=/data/media/shell:"$PATH"; mksh'
What's safer though is to just use a non-su shell command:
Code:
/system/bin/mksh -c 'export LD_LIBRARY_PATH=/data/media/shell:"$LD_LIBRARY_PATH"; export PATH=/data/media/shell:"$PATH"; mksh'
...and then use sudo (also aliased as "xx" for ease) for your su commands. This is more linux'y.
Attached Files
File Type: zip mkmksh_07_17_2014.zip - [Click for QR Code] (3.62 MB, 2 views)
The Following User Says Thank You to 7175 For This Useful Post: [ Click to Expand ]
 
7175
Old
#2  
7175's Avatar
Senior Member - OP
Thanks Meter 228
Posts: 189
Join Date: Feb 2013
reserved
 
7175
Old
#3  
7175's Avatar
Senior Member - OP
Thanks Meter 228
Posts: 189
Join Date: Feb 2013
reserved
|Device| = Galaxy Nexus 'toro' |Batt's| =3800, 1850, 2100b (NFC-stripped) |Radio's| = FK-LTE/FA-cdma
|Bootloader| = PRIMEMD04
|ROM's| = Carbon(d.d. f2fs) + PAC |RECOVERY| = TWRP 2.7.x.x |SU| = SuperSU!
|Kernels| = Dirty V, Fancy, Grakern --- FIOPS'd BFQ; Core:307; VAUX3:2500; COLOR:[Contrast=-2;Gamma=-4;+{-8; -5; -5}; x{175; 175; 200}]


Excellent GNEX[Ref][Guide] -- ART-compatible Apps -- Xposed Repo -- [Tweak]mksh/-rc FULL+ installer -- init.d && cron
Tags
busybox, grep, ksh, mksh, shell
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes