Last active
March 18, 2020 11:19
-
-
Save iwakura/ff478c8c4ba9add94fe5464f30f9a009 to your computer and use it in GitHub Desktop.
mount ext3fs from firmware image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
fail() { | |
echo $1 1>&2 | |
exit $2 | |
} | |
[ $# -eq 2 ] || fail "Usage: `basename $0` fw.img /mount/point" 1 | |
[ `which bgrep` ] || fail "Please install bgrep tool." 2 | |
[ -r $1 ] || fail "Unable to locate image file: $1" 3 | |
[ -d $2 ] || fail "Mount point does not exists: $2" 4 | |
FW_IMAGE=$1 | |
MOUNT_POINT=$2 | |
FS_TYPE=ext3 | |
EXTFS_MAGIC_NUM=53ef | |
MAGIC_OFFSET=1080 | |
OFFSETS=`bgrep $EXTFS_MAGIC_NUM $FW_IMAGE | awk '{print toupper($NF)}'` | |
for OFFSET in $OFFSETS; do | |
OFFSET=`echo "ibase=16; $OFFSET" | bc` | |
FS_OFFSET=`expr $OFFSET - $MAGIC_OFFSET` | |
sudo mount -t $FS_TYPE -o loop,offset=$FS_OFFSET,noatime $FW_IMAGE $MOUNT_POINT 2>/dev/null | |
#sudo chown -R $USER $MOUNT_POINT | |
if [ $? -eq 0 ]; then | |
echo "Success! Filesystem offset is: $FS_OFFSET." | |
break | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment