diff --git a/README.md b/README.md index 0a628fe..28c1596 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # sharun Run dynamically linked ELF binaries everywhere (musl and glibc are supported). -Tree +![sharun](img/sharun.gif) * Its works with [userland-execve](https://github.com/io12/userland-execve-rust) by mapping the interpreter (such as ld-linux-x86-64.so.2) into memory, creating a stack for it (containing the auxiliary vector, arguments, and environment variables), and then jumping to the entry point with the new stack. * [lib4bin](https://github.com/VHSgunzo/sharun/blob/main/lib4bin) pulls out the binary file and all the libraries on which it depends, strip it and forms the `bin`, `shared/{bin,lib,lib32}` directories (see [screenshots](https://github.com/VHSgunzo/sharun?tab=readme-ov-file#screenshots)) and generate a file `shared/{lib,lib32}/lib.path` with a list of all directories that contain libraries for pass it to interpreter `--library-path`. The paths in this file are specified on a new line with a `+` at the beginning and relative to the directory in which it is located. @@ -28,38 +28,38 @@ cargo build --release ## Usage sharun: ``` [ Usage ]: sharun [OPTIONS] [EXEC ARGS]... -| Use lib4bin for create 'bin' and 'shared' dirs -| + Use lib4bin for create 'bin' and 'shared' dirs + [ Arguments ]: -| [EXEC ARGS]... Command line arguments for execution -| + [EXEC ARGS]... Command line arguments for execution + [ Options ]: -| l, lib4bin [ARGS] Launch the built-in lib4bin -| -g, --gen-lib-path Generate library path file -| -v, --version Print version -| -h, --help Print help -| + l, lib4bin [ARGS] Launch the built-in lib4bin + -g, --gen-lib-path Generate library path file + -v, --version Print version + -h, --help Print help + [ Environments ]: -| SHARUN_LDNAME=ld.so Specifies the name of the interpreter + SHARUN_LDNAME=ld.so Specifies the name of the interpreter ``` ## Usage lib4bin: ``` [ Usage ]: lib4bin [options] /path/executable -Options: - -s, --strip Strip binaries and libraries (env: STRIP=1) - -v, --verbose Verbose mode (env: VERBOSE=1) - -d, --dst-dir '/path' Destination directory (env: DST_DIR=/path) +[ Options ]: + -s, --strip Strip binaries and libraries (env: STRIP) + -v, --verbose Verbose mode (env: VERBOSE) + -d, --dst-dir '/path' Destination directory (env: DST_DIR) -n, --not-one-dir Separate directories for each executable (env: ONE_DIR=0) - -l, --libs-only Pack only libraries (env: LIBS_ONLY=1) - -w, --with-sharun Pack sharun from PATH or env or download (env: WITH_SHARUN=1, SHARUN=/sharun) - -p, --hard-links Create hard links to sharun (env: HARD_LINKS=1) - -r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH=1) - -g, --gen-lib-path Generate a lib.path file (env: GEN_LIB_PATH=1) - -a, --any-executable Pack any executable (env: ANY_EXECUTABLE=1) - -i, --patch-interpreter Patch INTERPRETER to a relative path (env: PATCH_INTERPRETER=1) - -q, --quiet-mode Show only errors (env: QUIET_MODE=1) + -l, --libs-only Pack only libraries (env: LIBS_ONLY) + -w, --with-sharun Pack sharun from PATH or env or download (env: WITH_SHARUN, SHARUN, SHARUN_URL) + -p, --hard-links Create hard links to sharun (env: HARD_LINKS) + -r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH) + -g, --gen-lib-path Generate a lib.path file (env: GEN_LIB_PATH) + -a, --any-executable Pack any executable (env: ANY_EXECUTABLE) + -i, --patch-interpreter Patch INTERPRETER to a relative path (env: PATCH_INTERPRETER) + -q, --quiet-mode Show only errors (env: QUIET_MODE) -h, --help Show this message ``` diff --git a/lib4bin b/lib4bin index d2dcc8f..0875c63 100755 --- a/lib4bin +++ b/lib4bin @@ -30,21 +30,22 @@ PATCH_INTERPRETER=${PATCH_INTERPRETER:=0} GIT_SHARUN_RELEASES='https://github.com/VHSgunzo/sharun/releases' usage() { - echo -e "$YELLOW[ Usage ]: ${GREEN}$(basename "$0") ${RED}[options] ${BLUE}/path/executable$RESETCOLOR\n" - echo "Options:" - echo " -s, --strip Strip binaries and libraries (env: STRIP=1)" - echo " -v, --verbose Verbose mode (env: VERBOSE=1) " - echo " -d, --dst-dir '/path' Destination directory (env: DST_DIR=/path)" - echo " -n, --not-one-dir Separate directories for each executable (env: ONE_DIR=0)" - echo " -l, --libs-only Pack only libraries (env: LIBS_ONLY=1)" - echo " -w, --with-sharun Pack sharun from PATH or env or download (env: WITH_SHARUN=1, SHARUN=/sharun)" - echo " -p, --hard-links Create hard links to sharun (env: HARD_LINKS=1)" - echo " -r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH=1)" - echo " -g, --gen-lib-path Generate a lib.path file (env: GEN_LIB_PATH=1)" - echo " -a, --any-executable Pack any executable (env: ANY_EXECUTABLE=1)" - echo " -i, --patch-interpreter Patch INTERPRETER to a relative path (env: PATCH_INTERPRETER=1)" - echo " -q, --quiet-mode Show only errors (env: QUIET_MODE=1)" - echo " -h, --help Show this message" + echo -e "[ Usage ]: lib4bin [options] /path/executable + +[ Options ]: + -s, --strip Strip binaries and libraries (env: STRIP) + -v, --verbose Verbose mode (env: VERBOSE) + -d, --dst-dir '/path' Destination directory (env: DST_DIR) + -n, --not-one-dir Separate directories for each executable (env: ONE_DIR=0) + -l, --libs-only Pack only libraries (env: LIBS_ONLY) + -w, --with-sharun Pack sharun from PATH or env or download (env: WITH_SHARUN, SHARUN, SHARUN_URL) + -p, --hard-links Create hard links to sharun (env: HARD_LINKS) + -r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH) + -g, --gen-lib-path Generate a lib.path file (env: GEN_LIB_PATH) + -a, --any-executable Pack any executable (env: ANY_EXECUTABLE) + -i, --patch-interpreter Patch INTERPRETER to a relative path (env: PATCH_INTERPRETER) + -q, --quiet-mode Show only errors (env: QUIET_MODE) + -h, --help Show this message" exit 1 } @@ -76,7 +77,7 @@ check_deps() { for bin in "${binaries[@]}" do if ! is_exe_exist $bin - then + then error_msg "$BLUE[$bin]$YELLOW not found!" ret=1 fi @@ -337,13 +338,20 @@ for binary in "${BINARY_LIST[@]}" fi if [[ "$WITH_SHARUN" == 1 && ! -e "${DST_DIR}/sharun" ]] then + TMP_SHARUN="/tmp/$(uname -m)/sharun" SHARUN="${SHARUN:="$(readlink -f "$(which_exe sharun)")"}" - SHARUN="${SHARUN:="/tmp/$(uname -m)/sharun"}" + SHARUN="${SHARUN:="$TMP_SHARUN"}" if [ ! -x "$SHARUN" ] then + if grep -q '^http'<<<"$SHARUN" + then + SHARUN_URL="$SHARUN" + SHARUN="$TMP_SHARUN" + fi + SHARUN_URL="${SHARUN_URL:="$(get_sharun_git_url)"}" info_msg "Downloading sharun -> '$SHARUN'..." - info_msg "$(get_sharun_git_url)" - if try_dl "$(get_sharun_git_url)" "$SHARUN" + info_msg "$SHARUN_URL" + if try_dl "$SHARUN_URL" "$SHARUN" then chmod $varg +x "$SHARUN" else error_msg "Failed to download sharun!" diff --git a/src/main.rs b/src/main.rs index ee425ec..66ad2fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,31 +103,24 @@ fn gen_library_path(library_path: &mut String) -> i32 { } } -fn strip_str(str: &str) -> String { - str.lines() - .map(|line| line.trim_start()) - .collect::>() - .join("\n") -} - fn print_usage() { - println!("{}", strip_str(&format!("[ {} ] - | - [ Usage ]: {SHARUN_NAME} [OPTIONS] [EXEC ARGS]... - | Use lib4bin for create 'bin' and 'shared' dirs - | - [ Arguments ]: - | [EXEC ARGS]... Command line arguments for execution - | - [ Options ]: - | l, lib4bin [ARGS] Launch the built-in lib4bin - | -g, --gen-lib-path Generate library path file - | -v, --version Print version - | -h, --help Print help - | - [ Environments ]: - | SHARUN_LDNAME=ld.so Specifies the name of the interpreter", - env!("CARGO_PKG_DESCRIPTION")))); + println!("[ {} ] + +[ Usage ]: {SHARUN_NAME} [OPTIONS] [EXEC ARGS]... + Use lib4bin for create 'bin' and 'shared' dirs + +[ Arguments ]: + [EXEC ARGS]... Command line arguments for execution + +[ Options ]: + l, lib4bin [ARGS] Launch the built-in lib4bin + -g, --gen-lib-path Generate library path file + -v, --version Print version + -h, --help Print help + +[ Environments ]: + SHARUN_LDNAME=ld.so Specifies the name of the interpreter", + env!("CARGO_PKG_DESCRIPTION")); } fn main() {