From 1d2d1b356d070ee5b059f1d075e2493ee6b602c2 Mon Sep 17 00:00:00 2001 From: hyugogirubato <65763543+hyugogirubato@users.noreply.github.com> Date: Sun, 21 Apr 2024 16:34:02 +0200 Subject: [PATCH] remove mkshrc --- docs/MKSHRC.md | 83 ------------------------- docs/mkshrc | 161 ------------------------------------------------- 2 files changed, 244 deletions(-) delete mode 100644 docs/MKSHRC.md delete mode 100644 docs/mkshrc diff --git a/docs/MKSHRC.md b/docs/MKSHRC.md deleted file mode 100644 index e3a61a2..0000000 --- a/docs/MKSHRC.md +++ /dev/null @@ -1,83 +0,0 @@ -# mkshrc - Advanced Shell Environment for Android - -`mkshrc` is a script designed to enhance the shell environment on Android devices. It sets up a customized environment with advanced command line tools and utilities, improving the overall user experience for shell interaction, especially for developers and power users who need more robust tools than what the default Android shell offers. - -## Features - -- **Environment Customization**: Sets HOSTNAME, USER, LOGNAME, and TMPDIR environment variables based on the device properties. -- **Architecture Detection**: Automatically detects the device's CPU architecture to download appropriate binaries. -- **BusyBox Integration**: Downloads and aliases BusyBox utilities, providing a wide range of standard Unix tools missing from standard Android shells. -- **Frida Server Management**: Simplifies the installation and management of Frida, a dynamic instrumentation toolkit, for non-rooted environments without Magisk. -- **Enhanced Command Aliases**: Includes aliases for color support in command output and common command shortcuts to improve usability. -- **Custom Commands**: Includes custom functions such as `tree`, `cfind`, `man`, and `sudo`, enhancing the functionality available in a typical Android shell. -- **Dynamic Frida Control**: Allows starting, stopping, and checking the status of the Frida server directly from the shell. - -## Requirements - -- **Root Access**: Needed for certain operations like setting certain environment variables or running commands as superuser. -- **BusyBox**: Required for most of the enhanced commands and utilities. -- **Internet Connection**: Needed to download necessary binaries like BusyBox and Frida. -- **ADB Setup**: ADB must be set up on your computer to push the script to your Android device. - -## Installation - -1. **Push the Script to Your Device**: - Use ADB to push the `mkshrc` script to your device. Open your terminal or command prompt and run: - ```bash - adb push mkshrc /data/local/tmp/mkshrc - ``` - -2. **Access Your Device via ADB**: - Connect to your device shell using ADB: - ```bash - adb shell - ``` - -3. **Gain Superuser Access**: - If your device is rooted, you may need to switch to the superuser mode to allow the script to perform operations that require root privileges: - ```bash - su - ``` - -4. **Navigate to the Script Location**: - Change directory to where the script is located: - ```bash - cd /data/local/tmp - ``` - -5. **Source the Script**: - To apply the enhancements provided by `mkshrc`, you need to source it in the current shell session: - ```bash - source mkshrc - ``` - - **Note**: The `source` command needs to be run in each new shell session where you want the enhancements to be active. - -## Additional Functions - -- **`tree`**: Display a directory tree of the current or specified directory. -- **`cfind`**: Custom find command that outputs results with color support if available. -- **`man`**: Simulates the man command for built-in shell commands by showing command help. -- **`sudo`**: Function that tries to elevate privileges using `su` if not running as root. - -## Usage Notes - -## Usage Notes - -Due to the nature of the default Android shell, typical initialization files like `.bashrc` or `.profile` do not exist. To ensure the enhancements and functions provided by `mkshrc` are available across all shell sessions, you need to manually source the script each time you open a new shell session. Here's how you can do it: - -```bash -source /data/local/tmp/mkshrc -``` - -If you frequently use the shell on your Android device and want to automate the sourcing process, consider adding the source command to the shell's startup commands. This can often be achieved by modifying the shell's startup script if your device's shell environment allows it. For example, if using Termux or a similar terminal emulator app, you might be able to add the source command to its initialization script. - -Another approach is to create a shortcut command that you can easily type upon starting a shell session. For instance: - -```bash -alias startenv="source /data/local/tmp/mkshrc" -``` - -Then, whenever you start a new shell session, you simply type `startenv` to initialize your environment with `mkshrc` enhancements. - -This setup script is designed to make the shell experience on Android more powerful and user-friendly, particularly for developers and power users who require advanced command-line tools and functionality. Enjoy the improved productivity and enhanced capabilities that `mkshrc` brings to your Android device! \ No newline at end of file diff --git a/docs/mkshrc b/docs/mkshrc deleted file mode 100644 index 7cb58b3..0000000 --- a/docs/mkshrc +++ /dev/null @@ -1,161 +0,0 @@ -#!/system/bin/sh - -# ==UserScript== -# @name mkshrc -# @namespace https://github.com/hyugogirubato/KeyDive -# @version 2024.04.21 -# @description Make an advanced shell environment for Android devices -# @author hyugogirubato -# @match Android -# ==/UserScript== - - -# Set environment variables based on device properties -export HOSTNAME=$(getprop ro.boot.serialno) -export USER=$(id -u -n) -export LOGNAME=$USER -export TMPDIR=${TMPDIR:-/data/local/tmp} - - -# Find the architecture of the Android device using CPU ABI -find_arch() { - # Source: https://github.com/Magisk-Modules-Repo/busybox-ndk/blob/master/customize.sh#L314C1-L334C2 - local abi=$(getprop ro.product.cpu.abi) - case $abi in - arm64*) ARCH='arm64' ;; - arm*) ARCH='arm' ;; - x86_64*) ARCH='x86_64' ;; - x86*) ARCH='x86' ;; - mips64*) ARCH='mips64' ;; - mips*) ARCH='mips' ;; - *) echo "Unknown architecture: $abi" >&2; return 1 ;; - esac -} - - -# Initialize the architecture -find_arch - -# Define and verify the path to the BusyBox binary -busybox='/sbin/.magisk/busybox/busybox' -if [ ! -f "$busybox" ]; then - busybox="$TMPDIR/busybox" - - # Source: https://github.com/Magisk-Modules-Repo/busybox-ndk - url="https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-$ARCH" - [ -f '/sys/fs/selinux/enforce' ] && url+='-selinux' - curl -fs -o "$busybox" "$url" || { echo "Failed to download BusyBox from $url" >&2; return 1; } - - # Ensure BusyBox binary is executable - chmod 755 "$busybox" - chown shell:shell "$busybox" -fi - -# Create aliases for BusyBox commands -for bin in $($busybox --list); do - if [ "$bin" != 'man' ]; then - alias "$bin"="$busybox $bin" 2>/dev/null - fi -done - -# Handle Frida installation if Magisk is not installed -if [ ! -d '/sbin/.magisk/' ]; then - frida="$TMPDIR/frida-server" - - if [ ! -f "$frida" ]; then - # Source: https://github.com/frida/frida - version='16.2.1' - url="https://github.com/frida/frida/releases/download/$version/frida-server-$version-android-$ARCH.xz" - curl -fsL -o "$frida.xz" "$url" || { echo "Failed to download Frida from $url" >&2; return 1; } - $busybox xz -d "$frida.xz" - fi - - # Ensure Frida binary is executable - chmod 755 "$frida" - chown shell:shell "$frida" - alias 'frida-server'="$frida" -elif [ ! -d '/sbin/.magisk/modules/magisk-frida' ]; then - echo 'Install Frida using: https://github.com/ViRb3/magisk-frida' -fi - -# Enhance command output with color support if available -if ls --color=auto >/dev/null 2>&1; then - alias ls='ls --color=always' - 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' - -# Display directory tree -tree() { - # Source: https://stackoverflow.com/questions/18014779/similar-command-to-linux-tree-command-in-adb-shell - find "${1:-.}" -print | sort | sed 's;[^/]*/;|---;g;s;---|; |;g' -} - -# Custom find command that displays colored results -cfind() { - if ls --color=auto >/dev/null 2>&1; then - find "${1:-.}" -print0 | xargs -0 ls -d1 --color=auto - else - echo 'Unsupported XTerm environment' >&2; return 1 - fi -} - -# Simulate 'man' command -man() { - [ -z "$1" ] && { echo -e "What manual page do you want?\nFor example, try 'man ls'." >&2; return 1; } - "$1" --help -} - -# Define a sudo-like function -sudo() { - if [ "$(id -u)" -eq 0 ]; then - "$@" - elif command -v su >/dev/null 2>&1; then - su -c "$*" - else - echo 'su binary not found' >&2; return 127 - fi -} - -# Stop frida-server if it's running without Magisk -frida-stop() { - if [ -d '/sbin/.magisk/' ]; then - echo 'Use Magisk to stop Frida' >&2; return 1 - else - local pid=$(pgrep -f frida-server) - if [ ! -z "$pid" ]; then - sudo kill -9 $pid || { echo 'Failed to stop Frida' >&2; return 1; } - fi - fi -} - -# Check the status of the frida-server -frida-status() { - local pid=$(pgrep -f frida-server) - [ -z "$pid" ] && echo 'Frida not running' || echo "Frida PID: $pid" -} - -# Start frida-server if it's not already running and Magisk is not installed -frida-start() { - local pid=$(pgrep -f frida-server) - if [ -z "$pid" ]; then - if [ -d '/sbin/.magisk/' ]; then - echo 'Use Magisk to start Frida' >&2; return 1 - else - command -v setenforce >/dev/null 2>&1 && sudo setenforce 0 >/dev/null 2>&1 - sudo frida-server -D "$@" || { echo 'Failed to start Frida' >&2; return 1; } - fi - else - echo 'Frida already running' - fi -} \ No newline at end of file