Skip to content

Commit

Permalink
More mount options
Browse files Browse the repository at this point in the history
Some users already have a functional fuse-ext2 setup so don't force them to
upgrade to ext4fuse by still supporting the legacy fuse-ext2. Also add the option
to directly mount via loopback when script is running as root.

Signed-off-by: Anestis Bechtsoudis <[email protected]>
  • Loading branch information
anestisb committed Aug 11, 2018
1 parent 64b6aa1 commit 3bca6d3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 24 deletions.
58 changes: 37 additions & 21 deletions execute-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ cat <<_EOF
-s|--skip : [OPTIONAL] Skip /system bytecode repairing (default: false)
-y|--yes : [OPTIONAL] Auto accept Google ToS when downloading Nexus factory images (default: false)
--debugfs : [OPTIONAL] Use debugfs (Linux only) instead of the default ext4fuse (default: false)
--fuse-ext2 : [OPTIONAL] Use fuse-ext2 (Linux only) instead of the default ext4fuse (default: false)
--force-opt : [OPTIONAL] Override LOCAL_DEX_PREOPT to always pre-optimize /system bytecode (default: false)
--oatdump : [OPTIONAL] Force use of oatdump method to revert pre-optimized bytecode
--smali : [OPTIONAL] Force use of smali/baksmali to revert pre-optimized bytecode
Expand All @@ -75,7 +76,7 @@ cat <<_EOF
* Default bytecode de-optimization repair choise is based on most stable/heavily-tested method.
If you need to change the defaults, you can select manually.
* Darwin systems can use the ext4fuse to extract data from ext4 images without root
* Linux system can use the ext4fuse or debugfs to extract data from ext4 images without root
* Linux system can use the ext4fuse, fuse-ext2 or debugfs to extract data from ext4 images without root
_EOF
abort 1
}
Expand Down Expand Up @@ -208,6 +209,11 @@ check_input_args() {
fi
fi

if [[ "$USE_DEBUGFS" = true && "$USE_FUSEEXT2" = true ]]; then
echo "[-] --debugfs & --fuse-ext2 cannot be used at the same time"
abort 1
fi

# Some business logic related checks
if [[ "$DEODEX_ALL" = true && $KEEP_DATA = false ]]; then
echo "[!] It's pointless to deodex all if not keeping runtime generated data"
Expand Down Expand Up @@ -309,33 +315,14 @@ BYTECODE_REPAIR_METHOD=""
DEODEX_ALL=false
AOSP_ROOT=""
USE_DEBUGFS=false
USE_FUSEEXT2=false
FORCE_VIMG=false
JAVA_FOUND=false

# Compatibility
check_bash_version
check_compatible_system

# Platform specific commands
if isDarwin; then
SYS_TOOLS+=("umount")
_UMOUNT=umount
else
# For Linux use debugfs
SYS_TOOLS+=("fusermount")
_UMOUNT="fusermount -u"
fi


# Check that system tools exist
for i in "${SYS_TOOLS[@]}"
do
if ! command_exists "$i"; then
echo "[-] '$i' command not found"
abort 1
fi
done

# Parse calling arguments
while [[ $# -gt 0 ]]
do
Expand Down Expand Up @@ -380,6 +367,9 @@ do
--debugfs)
USE_DEBUGFS=true
;;
--fuse-ext2)
USE_FUSEEXT2=true
;;
--force-opt)
FORCE_PREOPT=true
;;
Expand Down Expand Up @@ -409,6 +399,30 @@ done
# Check user input args
check_input_args

# Platform specific commands
if isDarwin; then
SYS_TOOLS+=("umount")
_UMOUNT=umount
else
# Check if script is running as root to directly use loopback instead of fuses
if [ "$EUID" -eq 0 ]; then
SYS_TOOLS+=("umount")
_UMOUNT="umount"
elif [ "$USE_DEBUGFS" = false ]; then
SYS_TOOLS+=("fusermount")
_UMOUNT="fusermount -uz"
fi
fi

# Check that system tools exist
for i in "${SYS_TOOLS[@]}"
do
if ! command_exists "$i"; then
echo "[-] '$i' command not found"
abort 1
fi
done

# Check if output directory is AOSP root
if is_aosp_root "$OUTPUT_DIR"; then
if [ "$KEEP_DATA" = true ]; then
Expand Down Expand Up @@ -490,6 +504,8 @@ EXTRACT_SCRIPT_ARGS=(--input "$factoryImgArchive" --output "$FACTORY_IMGS_DATA")

if [ "$USE_DEBUGFS" = true ]; then
EXTRACT_SCRIPT_ARGS+=( --debugfs)
elif [ "$USE_FUSEEXT2" = true ]; then
EXTRACT_SCRIPT_ARGS+=( --fuse-ext2)
fi

$EXTRACT_SCRIPT "${EXTRACT_SCRIPT_ARGS[@]}" --conf-file "$CONFIG_FILE" || {
Expand Down
30 changes: 27 additions & 3 deletions scripts/extract-factory-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ cat <<_EOF
-o|--output : Path to save contents extracted from images
--conf-file : Device configuration file
--debugfs : Use debugfs instead of default ext4fuse
--fuse-ext2 : Use fuse-ext2 instead of default ext4fuse
INFO:
* ext4fuse available at 'https://github.com/gerard/ext4fuse'
* Caller is responsible to unmount mount points when done
* debugfs support is experimental
_EOF
abort 1
}
Expand Down Expand Up @@ -116,7 +116,17 @@ mount_linux() {
local imgFile="$1"
local mountPoint="$2"
local mount_log="$TMP_WORK_DIR/mount.log"
ext4fuse -o logfile=/dev/stdout,uid=$EUID,ro "$imgFile" "$mountPoint" &>"$mount_log" || {
local mount_cmd

if [ "$RUNS_WITH_ROOT" = true ]; then
mount_cmd="mount -t ext4 -o loop,ro"
elif [ "$USE_FUSEEXT2" = true ]; then
mount_cmd="fuse-ext2 -o uid=$EUID,ro"
else
mount_cmd="ext4fuse -o logfile=/dev/stdout,uid=$EUID,ro"
fi

$mount_cmd "$imgFile" "$mountPoint" &>"$mount_log" || {
echo "[-] '$imgFile' mount failed"
cat "$mount_log"
abort 1
Expand Down Expand Up @@ -183,6 +193,8 @@ INPUT_ARCHIVE=""
OUTPUT_DIR=""
CONFIG_FILE=""
USE_DEBUGFS=false
USE_FUSEEXT2=false
RUNS_WITH_ROOT=false

# Compatibility
HOST_OS=$(uname)
Expand Down Expand Up @@ -210,6 +222,9 @@ do
--debugfs)
USE_DEBUGFS=true
;;
--fuse-ext2)
USE_FUSEEXT2=true
;;
*)
echo "[-] Invalid argument '$1'"
usage
Expand All @@ -218,9 +233,18 @@ do
shift
done

# Check if script is running as root to directly use loopback instead of fuses
if [ "$EUID" -eq 0 ]; then
RUNS_WITH_ROOT=true
fi

# Additional tools based on chosen image files data extraction method
if [ "$USE_DEBUGFS" = true ]; then
if [ "$RUNS_WITH_ROOT" = true ]; then
SYS_TOOLS+=("mount")
elif [ "$USE_DEBUGFS" = true ]; then
SYS_TOOLS+=("debugfs")
elif [ "$USE_FUSEEXT2" ]; then
SYS_TOOLS+=("fuse-ext2")
else
SYS_TOOLS+=("ext4fuse")
# Platform specific commands
Expand Down

0 comments on commit 3bca6d3

Please sign in to comment.