Advertisement
rajkosto

hekate2rawnand.sh

Apr 30th, 2018
5,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.83 KB | None | 0 0
  1. #!/bin/sh
  2. #This script requires some binary files, get them by extracting https://files.sshnuke.net/hekate2rawnand.zip
  3. #If on Windows, easiest way to get a compatible shell for running this script would be to install https://gitforwindows.org/ and then "Git Bash here" in the context menu of this folder
  4. #To get hekate_ipl to dump USER (and maybe BOOT0/1) you can download my fork from https://github.com/rajkosto/hekate/releases
  5.  
  6. if [ ! -f "gpt_prefix.bin" ]; then
  7.     echo "Missing required binary files. Get the zip from https://files.sshnuke.net/hekate2rawnand.zip and extract it to this folder."
  8.     exit 1
  9. fi
  10.  
  11. statusParam="status=progress"
  12. ddSupportsLine=`dd --help 2>&1 | grep "shows periodic transfer statistics"`
  13. if [ -z "$ddSupportsLine" ]; then
  14.     statusParam=""
  15. fi
  16.  
  17. dd of=hekate-RawNand.bin if=gpt_prefix.bin skip=0 seek=0 count=34 bs=512
  18. dd of=hekate-RawNand.bin if=PRODINFO skip=0 seek=34 count=8158 bs=512
  19. dd of=hekate-RawNand.bin if=PRODINFOF skip=0 seek=256 count=256 bs=16384
  20. dd of=hekate-RawNand.bin if=BCPKG2-1-Normal-Main skip=0 seek=512 count=512 bs=16384
  21. dd of=hekate-RawNand.bin if=BCPKG2-2-Normal-Sub skip=0 seek=1024 count=512 bs=16384
  22. dd of=hekate-RawNand.bin if=BCPKG2-3-SafeMode-Main skip=0 seek=1536 count=512 bs=16384
  23. dd of=hekate-RawNand.bin if=BCPKG2-4-SafeMode-Sub skip=0 seek=2048 count=512 bs=16384
  24. dd of=hekate-RawNand.bin if=BCPKG2-5-Repair-Main skip=0 seek=2560 count=512 bs=16384
  25. dd of=hekate-RawNand.bin if=BCPKG2-6-Repair-Sub skip=0 seek=3072 count=512 bs=16384
  26. dd of=hekate-RawNand.bin if=SAFE skip=0 seek=3584 count=4096 bs=16384 $statusParam
  27. dd of=hekate-RawNand.bin if=SYSTEM skip=0 seek=7680 count=163840 bs=16384 $statusParam
  28.  
  29. userStartSeek=171520
  30. userCurrSeek=$userStartSeek
  31.  
  32. if [ -f "USER" ]; then
  33.     fileSizeInBlocks=1703936
  34.     dd of=hekate-RawNand.bin if=USER skip=0 seek=$userCurrSeek count=$fileSizeInBlocks bs=16384 $statusParam
  35.     userCurrSeek=`expr "$userCurrSeek" + "$fileSizeInBlocks"`
  36. else
  37.     for file in USER.*; do
  38.         [ -f "$file" ] || break
  39.        
  40.         fileSize=`(
  41.             du --apparent-size --block-size=1 "$file" 2>/dev/null ||
  42.             gdu --apparent-size --block-size=1 "$file" 2>/dev/null ||
  43.             find "$file" -printf "%s" 2>/dev/null ||
  44.             gfind "$file" -printf "%s" 2>/dev/null ||
  45.             stat --printf="%s" "$file" 2>/dev/null ||
  46.             stat -f%z "$file" 2>/dev/null ||
  47.             wc -c <"$file" 2>/dev/null
  48.         ) | awk '{print $1}'`
  49.         fileSizeInBlocks=`expr "$fileSize" / 16384`
  50.         dd of=hekate-RawNand.bin "if=$file" skip=0 seek=$userCurrSeek count=$fileSizeInBlocks bs=16384 $statusParam
  51.         userCurrSeek=`expr "$userCurrSeek" + "$fileSizeInBlocks"`
  52.     done    
  53. fi
  54.  
  55. if [ "$userCurrSeek" -ne "$userStartSeek" ]; then
  56.     dd of=hekate-RawNand.bin if=gpt_suffix.bin skip=0 seek=61071327 count=33 bs=512
  57. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement