Advertisement
wyatt8740

android unzipdir.sh

Feb 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #! /system/bin/sh
  2. #unzipdir
  3. #Version 2
  4. #safely extracts the zip equivalent of tarbombs
  5. #v2 works on zipfiles with extensions other than .zip (like .xpi and some .cbr files)
  6. #By Wyatt Ward, but with some things snatched from stack exchange answers
  7. #Requires info-zip
  8. export INFILENAME=`echo "$@" | busybox awk -F/ '$0=$NF'` #Looking back, i forget exactly what this does, but I think it cuts out a path.
  9. export INFILEBASENAME=$(busybox basename "$INFILENAME")
  10. export INFILEEXTENSION="${INFILEBASENAME##*.}" #not sure how it works. thanks stack exchange
  11.  
  12. #original v1 line:
  13. #export OUTPUTDIR=`echo "$INFILENAME" | sed 's/.zip//g'`
  14. #new v2 line:
  15. export OUTPUTDIR=`echo "$INFILENAME" | sed "s/.$INFILEEXTENSION//g"`
  16.  
  17. echo "OUTPUTDIR is"
  18. echo "$OUTPUTDIR"
  19. export STARTINGDIR="$PWD"
  20. if [ -f "$1" ]
  21. then
  22.         echo "Found file."
  23.         mkdir "$OUTPUTDIR"
  24.         cd "$OUTPUTDIR"
  25.         if [ `echo "$1" | grep [/]` ]
  26.         then
  27. #leading slash present, no need to find actual paths
  28.                 unzip "$1"
  29.         else
  30. #no slash present, be paranoid and do it the harder way
  31.                 unzip "$STARTINGDIR/$1"
  32.         fi
  33. else
  34.         echo "$1 not found. Sorry."
  35. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement