From 276208c472dfa6a0425589790d699ed02e9e4774 Mon Sep 17 00:00:00 2001 From: hyugogirubato <65763543+hyugogirubato@users.noreply.github.com> Date: Sat, 20 Apr 2024 15:55:35 +0200 Subject: [PATCH] update mkshrc - add busybox env - fix user - add sudo - update man - frida in dev --- docs/shell.sh | 102 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/docs/shell.sh b/docs/shell.sh index d67e9c4..10be495 100644 --- a/docs/shell.sh +++ b/docs/shell.sh @@ -1,36 +1,96 @@ -# Env -export PATH='/sbin:/system/sbin:/product/bin:/apex/com.android.runtime/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin' +#!/system/bin/sh -# Path -export TMP='/data/local/tmp/' -export APP='/data/data' -export LOCAL='/storage/emulated/0' -export WIFI='/data/misc/wifi' +# ==UserScript== +# @name mkshrc +# @namespace https://github.com/hyugogirubato/KeyDive +# @version 0.1 +# @description null +# @author hyugogirubato +# @match Android +# ==/UserScript== -# Color -alias ls='ls --color=auto' -alias grep='grep --color=auto' -alias fgrep='fgrep --color=auto' -alias egrep='egrep --color=auto' -alias logcat='logcat -v color' -alias ip='ip -c' -# Custom +# Set hostname based on device serial number +export HOSTNAME=$(getprop ro.boot.serialno) + +# Determine if the script is running as root +export USER=$(id -u -n) +export LOGNAME=$USER + +frida="${TMPDIR:-/data/local/tmp}/frida-server" +if [ ! -f "$frida" ]; then + version='16.2.1' + url="https://github.com/frida/frida/releases/download/$version/frida-server-$version-android-arm.xz" + # TODO: detect binary abi +fi + + +# Define and check the existence of BusyBox +busybox="${TMPDIR:-/data/local/tmp}/busybox" +if [ ! -f "$busybox" ]; then + url='https://busybox.net/downloads/binaries/1.26.2-defconfig-multiarch' + abi=$(getprop ro.product.cpu.abi) + binary=$(echo "$abi" | grep -q 'arm' && echo 'busybox-armv6l' || echo 'busybox-x86_64') + echo "Downloading BusyBox binary for $abi from $url/$binary" + curl -o "$busybox" "$url/$binary" || { + echo "ERROR: Failed to download BusyBox binary: $busybox" + return 1 + } +fi + +# Ensure BusyBox binary is executable +chown shell:shell "$busybox" +chmod +x "$busybox" + +# Alias all available BusyBox functions if not already in PATH +for func in $( $busybox --list ); do + if ! which "$func" >/dev/null 2>&1 && [ "$func" != 'man' ]; then + alias "$func"="$busybox $func" 2>/dev/null + fi +done + +# Enhance shell commands with color support if available +if ls --color=auto > /dev/null 2>&1; then + alias ls='ls --color=auto' + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' + alias logcat='logcat -v color' + alias ip='ip -c' +fi + +# Define commonly used aliases alias ll='ls -alF' alias la='ls -A' - alias l='ls -CF' alias ipa='ip a' alias rm='rm -rf' -# Extra +# Define a function to display a directory tree tree() { - path=${1:-.} - find ${path} -print | sort | sed 's;[^/]*/;|---;g;s;---|; |;g' + local path=${1:-.} + find "$path" -print | sort | sed 's;[^/]*/;|---;g;s;---|; |;g' } +# Simulate 'man' command using help option for commands man() { - ${1} --help + if [ -z "$1" ]; then + echo "What manual page do you want?" + echo "For example, try 'man ls'." + return 1 + else + "$1" --help + fi } -clear +# Define a sudo-like function +sudo() { + if [ "$(id -u)" -eq 0 ]; then + $* + elif which su >/dev/null 2>&1; then + su -c "$*" + else + echo 'ERROR: su binary not found' + return 127 + fi +} \ No newline at end of file