Skip to content

Instantly share code, notes, and snippets.

@iwakura
Last active March 18, 2020 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwakura/ff478c8c4ba9add94fe5464f30f9a009 to your computer and use it in GitHub Desktop.
Save iwakura/ff478c8c4ba9add94fe5464f30f9a009 to your computer and use it in GitHub Desktop.
mount ext3fs from firmware image
#!/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