REM original script by trigate, additions, fixes and expansion by HcH
:bof
@echo off
@color 0a
echo A13 Firmware Dump Tool
echo.
echo Connect your device now, waiting for device...
echo.
echo Make sure a SD with at least 512MB free space is present in the device.
echo.
echo.
adb.exe wait-for-device
cls
echo A13 Firmware Dump Tool
echo.
echo Device is CONNECTED
echo.
echo Make sure a SD with at least 512MB free space is present in the device.
echo.
echo.

:del1stq
set yn=
echo Do you want to delete a previous firmware dump from the device's SD?
set /p yn=y=Yes / n=No / help=Help / q=Quit : 
IF /i "%yn%"=="" goto nochoice
IF /i "%yn%"=="y" goto del1st
IF /i "%yn%"=="help" goto help
IF /i "%yn%"=="n" goto fw_dump
IF /i "%yn%"=="q" exit

:help
cls
echo A13 Firmware Dump Tool
echo.
echo This tool dumps the firmware of your A13 onto your PC using ADB.
echo If you are not familiar with ADB seek the web for more info.
echo This dump requires to have an SD card mounted in the device with
echo at least 512MB free space available.
echo.
echo Do note that this dump is not a ROM that you can flash, however
echo with the ROM kitchen it's possible to rebuilt a flashable ROM
echo using the files from the dump.
echo.
echo for updates and more info visit www.techknowforum.net
echo.
echo HcH
pause>nul
goto bof

:nochoice
goto bof

:del1st
echo.
echo Deleting /sdcard/dump...
echo.
adb.exe shell rm -r /sdcard/dump

:fw_dump
echo Making dump directory on device's SD card
adb.exe shell mkdir /sdcard/dump
echo.

echo Dumping ROM on device's SD card
echo.

echo Dumping bootloader...
adb.exe shell su -c "cat /dev/block/nanda > /sdcard/dump/bootloader.img"
echo.

echo Dumping boot...
adb.exe shell su -c "cat /dev/block/nandc > /sdcard/dump/boot.img"
echo.

echo Dumping recovery...
adb.exe shell su -c "cat /dev/block/nandg > /sdcard/dump/recovery.img"
echo.

echo Dumping system...
adb.exe shell su -c "cd /system && busybox tar cvf - * | gzip -c > /sdcard/dump/system.tgz"
echo.

echo Dumping data...
adb.exe shell su -c "cd /data && busybox tar cvf - * | gzip -c > /sdcard/dump/data.tgz"
echo.

echo Pulling files to local system...
mkdir dump
adb.exe pull /sdcard/dump dump
echo.

echo Renaming dump directory
for /F "tokens=2-4 delims=/- " %%i in ('date /t') do set yyyymmdd=%%k%%i%%j
for /F "tokens=1-2 delims=: " %%l in ('time /t') do set hhmm=%%l%%m
ren dump A13_FW_BACKUP_%yyyymmdd%_%hhmm%
echo.

echo Checking if all extracted files are present
cd A13_FW_BACKUP_%yyyymmdd%_%hhmm%
if exist boot.img echo boot.img is OK
if not exist boot.img echo boot.img is NOT FOUND! && color 0c
if exist bootloader.img echo bootloader.img is OK
if not exist bootloader.img echo bootloader.img is NOT FOUND! && color 0c
if exist recovery.img echo recovery.img is OK
if not exist recovery.img echo recovery.img is NOT FOUND! && color 0c
if exist system.tgz echo system.tgz is OK
if not exist system.tgz echo system.tgz is NOT FOUND! && color 0c
if exist data.tgz echo data.tgz is OK
if not exist data.tgz echo data.tgz is NOT FOUND! && color 0c
cd ..
echo.
echo.
echo Dump finished
echo.
echo.
pause
