├── Backup-TA.bat ├── changelog.txt ├── compatible-devices.txt ├── scripts ├── adb.bat ├── backup.bat ├── busybox.bat ├── convert.bat ├── license.bat ├── menu.bat ├── restore.bat ├── root.bat └── string-util.bat └── tools ├── AdbWinApi.dll ├── AdbWinUsbApi.dll ├── adb.exe ├── busybox ├── choice32.exe ├── choice32_alt.exe ├── choice64.exe ├── find.exe ├── md5.exe └── zip.exe /Backup-TA.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | set VERSION=9.11 4 | 5 | REM ##################### 6 | REM ## CHOICE CHECK 7 | REM ##################### 8 | choice /T 0 /D Y /C Y /M test > nul 2>&1 9 | if "!errorlevel!" == "1" ( 10 | set CHOICE=choice 11 | set CHOICE_TEXT_PARAM=/M 12 | ) else ( 13 | choice /T 0 /D Y /C Y test > nul 2>&1 14 | if "!errorlevel!" == "1" ( 15 | set CHOICE=choice 16 | set CHOICE_TEXT_PARAM= 17 | ) else ( 18 | tools\choice32.exe /TY,1 /CY > nul 2>&1 19 | if "!errorlevel!" == "1" ( 20 | set CHOICE=tools\choice32.exe 21 | ) else ( 22 | tools\choice32_alt.exe /T 0 /D Y /C Y /M test > nul 2>&1 23 | if "!errorlevel!" == "1" ( 24 | set CHOICE=tools\choice32_alt.exe 25 | set CHOICE_TEXT_PARAM=/M 26 | ) else ( 27 | tools\choice64.exe /T 0 /D Y /C Y /M test > nul 2>&1 28 | if "!errorlevel!" == "1" ( 29 | set CHOICE=tools\choice64.exe 30 | set CHOICE_TEXT_PARAM=/M 31 | ) 32 | ) 33 | ) 34 | ) 35 | ) 36 | 37 | cd %~dp0 38 | if NOT exist tmpbak mkdir tmpbak > nul 2>&1 39 | call scripts\license.bat showLicense 40 | call:initialize 41 | call scripts\adb.bat wakeDevice 42 | call scripts\busybox.bat pushBusyBox 43 | call scripts\root.bat check hasRoot 44 | if NOT "!hasRoot!" == "1" goto quit 45 | call scripts\menu.bat showMenu 46 | goto quit 47 | 48 | REM ##################### 49 | REM ## INITIALIZE 50 | REM ##################### 51 | :initialize 52 | cls 53 | echo. 54 | echo [ ------------------------------------------------------------ ] 55 | echo [ Backup TA v%VERSION% for Sony Xperia ] 56 | echo [ ------------------------------------------------------------ ] 57 | echo [ Initialization ] 58 | echo [ ] 59 | echo [ Make sure that you have USB Debugging enabled, you do ] 60 | echo [ allow your computer ADB access by accepting its RSA key ] 61 | echo [ (only needed for Android 4.2.2 or higher) and grant this ] 62 | echo [ ADB process root permissions through superuser. ] 63 | echo [ ------------------------------------------------------------ ] 64 | echo. 65 | set PARTITION_BY_NAME=/dev/block/platform/msm_sdcc.1/by-name/TA 66 | goto:eof 67 | 68 | REM ##################### 69 | REM ## DISPOSE 70 | REM ##################### 71 | :dispose 72 | echo. 73 | echo ======================================= 74 | echo CLEAN UP 75 | echo ======================================= 76 | set partition= 77 | set choiceTextParam= 78 | set choice= 79 | 80 | call scripts\menu.bat dispose 81 | call scripts\backup.bat dispose 82 | call scripts\restore.bat dispose 83 | call scripts\convert.bat dispose 84 | 85 | if exist tmpbak ( 86 | del /q /s tmpbak\*.* 87 | rmdir tmpbak 88 | ) 89 | 90 | call scripts\busybox.bat dispose 91 | 92 | set /p "=Killing ADB Daemon..." < nul 93 | tools\adb kill-server > nul 2>&1 94 | echo OK 95 | goto:eof 96 | 97 | REM ##################### 98 | REM ## QUIT 99 | REM ##################### 100 | :quit 101 | call:dispose 102 | echo. 103 | pause 104 | goto:eof 105 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | Backup TA v9.11 (2014-06-15) 2 | ============================== 3 | New Features, Improvements 4 | -------------------------- 5 | - Renamed 'Convert v4' to 'Convert TA.img' 6 | - Renamed 'Checking for root...' to 'Checking for SU binary' 7 | - When backup was made from an unknown device block, the tool will first check for the existence of '/dev/block/platform/msm_sdcc.1/by-name/TA' as the destination for the restore before using '/dev/block/mmcblk0p1' as the destination. 3 8 | 9 | Fixed Bugs 10 | -------------------------- 11 | - Execute all Windows executables with extension to prevent command not found issues on some systems. 12 | - SU binary check failure does not prevent the request for root permissions anymore, in case the SU binary is at an unknown location but indeed callable. 13 | - Changed the order in which the different CHOICE programs are tried in order to hopefully workaround issues on some systems. 14 | 15 | Backup TA v9.10 (2013-12-28) 16 | ============================== 17 | New Features, Improvements 18 | -------------------------- 19 | - Fixed search/replace mistake alternative choice program. 20 | 21 | Backup TA v9.9 (2013-12-07) 22 | ============================== 23 | New Features, Improvements 24 | -------------------------- 25 | - Changed the way to determine which choice program to use and added alternative 32bits choice program. Should fix an OS compatibility issue some users were having. 26 | 27 | Backup TA v9.8 (2013-09-28) 28 | ============================== 29 | New Features, Improvements 30 | -------------------------- 31 | - Added extra safeguard which checks whether the backup and TA partition have the same size before doing the actual restore. 32 | - Added superuser root access check. To make sure ADB is granted root access. 33 | - Initialization description which tells the user what is required for it to be successful. 34 | - More verbose output. 35 | 36 | Backup TA v9.7 (2013-08-18) 37 | ============================== 38 | New Features, Improvements 39 | -------------------------- 40 | - Added better partition inspection which should be more generic and compatible with Sony Xperia devices. 41 | - Added better serial check by not relying on a serial in the TA partition but store it inside the backup package. 42 | - Added timestamp and version number inside the backup package for later usage. 43 | - Added restart option after a successful backup. 44 | 45 | Backup TA v9.6 (2013-07-27) 46 | ============================== 47 | New Features, Improvements 48 | -------------------------- 49 | - Replaced the convert v4 backup step-by-step guide with an automated process. 50 | - Enhanced the Windows 64-bits check. Thanks to the feedback of zoomsk@XDA 51 | 52 | Backup TA v9.5 (2013-07-07) 53 | ============================== 54 | New Features, Improvements 55 | -------------------------- 56 | - Replaced all grep with awk commands for searching through lists. 57 | 58 | Backup TA v9.4 (2013-07-06) 59 | ============================== 60 | Fixed Bugs 61 | -------------------------- 62 | - Fixed the hang issue some users were having. 63 | - Changed the sort order of backup list in restore from ascending to descending. 64 | 65 | Backup TA v9.3 (2013-07-03) 66 | ============================== 67 | Fixed Bugs 68 | -------------------------- 69 | - Fixed menu bug 70 | 71 | Backup TA v9.2 (2013-07-02) 72 | ============================== 73 | Fixed Bugs 74 | -------------------------- 75 | - Fix typo 76 | 77 | Backup TA v9.1 (2013-07-02) 78 | ============================== 79 | New Features, Improvements 80 | -------------------------- 81 | - Changed the restore backup file confirmation dialog in that it now includes the filename chosen. 82 | 83 | Fixed Bugs 84 | -------------------------- 85 | - Fix bug which caused the tool not to find the TA by name the second time you run the backup process within the same session. 86 | 87 | Backup TA v9.0 (2013-06-30) 88 | ============================== 89 | New Features, Improvements 90 | -------------------------- 91 | - Merged device compatibility check into backup. Removed 'device compatibility check' from menu. 92 | - Backup does an extensive search for the TA when it can not be found by name, which makes Backup TA compatible with almost if not all Sony Xperia devices. 93 | - A brief description is displayed of what is going to happen when you choose for a backup or restore as menu option. A dialog will ask you to proceed to not. 94 | - After a restore a restart message is displayed which tells the user to restart the device for it to take effect. 95 | 96 | Fixed Bugs 97 | ---------- 98 | - Fixed bug in datetime stamp creation for backup filename. 99 | - Fixed sorting bug when choosing a backup to restore. 100 | 101 | Backup TA v8.9 (2013-06-18) 102 | ============================== 103 | New Features, Improvements 104 | -------------------------- 105 | - Enhanced device compatibility check. 106 | - Restore confirmation dialog now after backup choice menu. 107 | 108 | 109 | Backup TA v8.8 (2013-06-16) 110 | ============================== 111 | New Features, Improvements 112 | -------------------------- 113 | - Added a device compatibility check. 114 | 115 | 116 | Backup TA v8.7 (2013-06-16) 117 | ============================== 118 | Fixed Bugs 119 | ---------- 120 | - Bundled Windows find command. 121 | - Replaced 32bits choice.exe from Windows 7 to a prior Windows XP version. 122 | 123 | 124 | Backup TA v8.6 (2013-05-26) 125 | ============================== 126 | Fixed Bugs 127 | ---------- 128 | - Fixed bug in IMEI/Serial check. Was always executing the code as if the device was invalid. 129 | 130 | Backup TA v8.5 (2013-05-25) 131 | ============================== 132 | New Features, Improvements 133 | -------------------------- 134 | - Added device serial check when performing a restore. 135 | - Added ADB device 'wake-up' before a backup or restore. 136 | 137 | Fixed Bugs 138 | ---------- 139 | - Fixed compatibility bug with 64bits Windows version. Thanks to wawyed@xda for advice in the solution. 140 | - Added choice32.exe and choice64.exe as part of the tool instead of relying on Windows. 141 | 142 | 143 | Backup TA v8.4 (2013-05-23) 144 | ============================== 145 | Fixed Bugs 146 | ---------- 147 | - Fixed bug in IMEI input. 148 | - Added choice.com as part of the tool instead of relying on Windows. 149 | 150 | 151 | Backup TA v8.3 (2013-05-21) 152 | ============================== 153 | New Features, Improvements 154 | -------------------------- 155 | - Added backup selector when restoring. 156 | - Backups are now saved with datetime suffix. 157 | 158 | Fixed Bugs 159 | ---------- 160 | - Fixed bug in IMEI check. 161 | 162 | 163 | Backup TA v8.2 (2013-05-21) 164 | ============================== 165 | Fixed Bugs 166 | ---------- 167 | - Added backwards compatibility for backups made with versions before v8.0. 168 | - Fixed bug which caused the tool to not use busybox. 169 | 170 | 171 | Backup TA v8.1 (2013-05-20) 172 | ============================== 173 | New Features, Improvements 174 | -------------------------- 175 | - Added menu option to 'dry run' the restore, so a restore can be tested without writing. 176 | - Added IMEI length check when restoring. 177 | - Added extra safeguard to make sure a restore is fully written from memory to disk when restore ends. 178 | 179 | Fixed Bugs 180 | ---------- 181 | - Fixed bug which caused the tool to think a restore was unsuccesful while it was not. 182 | 183 | 184 | Backup TA v8.0 (2013-05-18) 185 | ============================== 186 | New Features, Improvements 187 | -------------------------- 188 | - Complete rewrite of the code to make it easier to maintain. 189 | - Added extra safeguards to decrease the risk of a hard-brick. 190 | - Added backup confirmation when backup package already present. 191 | - No need for pre-installed busybox. The tool will temporarily add and 192 | remove it without the need of adbd-insecure app. 193 | - Release the code under MIT license at GitHub: https://github.com/DevShaft/Backup TA. 194 | - Better output to console. 195 | - Better disposal of used data. 196 | 197 | 198 | Backup TA v7.3 - v7.7 (2013-05-16) 199 | ============================== 200 | New Features, Improvements 201 | -------------------------- 202 | - Kill ADB Daemon on quit. 203 | 204 | Fixed Bugs 205 | ---------- 206 | - Fixed minor issues. 207 | 208 | 209 | Backup TA v7.2 (2013-05-13) 210 | ============================== 211 | Fixed Bugs 212 | ---------- 213 | - The 'tmpbak' folder wasnt always created. 214 | 215 | 216 | Backup TA v7.1 (2013-05-12) 217 | ============================== 218 | Fixed Bugs 219 | ---------- 220 | - Fixed bug which caused the tool to hang after checking busybox. 221 | 222 | 223 | Backup TA v7.0 (2013-05-11) 224 | ============================== 225 | New Features, Improvements 226 | -------------------------- 227 | - Compatible busybox check. 228 | - More output for better support when needed. 229 | - Overall better checks. 230 | - Instructions how to convert v4 backup to v6+. 231 | 232 | Fixed Bugs 233 | ---------- 234 | - Check Compatibility bug fix. 235 | 236 | 237 | Backup TA v6.1 (2013-04-17) 238 | ============================== 239 | New Features, Improvements 240 | -------------------------- 241 | - (Backup) Extra MD5 checksum check before pulling the backup image from sdcard. 242 | - (Restore) Extra MD5 checksum check after pushing the backup package to sdcard. 243 | - Compatibility check to see if the device (other Xperia models) are compatibile with this tool (no guarantees!). 244 | 245 | 246 | Backup TA v6.0 (2013-04-16) 247 | ============================== 248 | New Features, Improvements 249 | -------------------------- 250 | - Removed unneeded ADB Insecure App 251 | - Removed unneeded fastboot 252 | - Removed unneeded busybox 253 | - Now you can extract this tool to any directory of your choosing. 254 | - Added clear progression status while backing up and restoring 255 | - Added restore confirmation 256 | - Backup and restore will be always be unsuccessful when the MD5 checksums do not match. 257 | - It now creates a backup package in ZIP format. In this you'll find the backup image and MD5 file. This package will also be used for restoring. 258 | -------------------------------------------------------------------------------- /compatible-devices.txt: -------------------------------------------------------------------------------- 1 | COMPATIBLE DEVICES (2014-02-09) 2 | =============================== 3 | Most likely all Sony Xperia models up till now are compatible. Sony Ericsson Xperia models however are NOT compatible 4 | and will never be. The following devices are confirmed being compatible with Backup TA by device owners. When your 5 | device is not in the list but is compatible, please let me know by sending a mail to devshaft@gmail.com. Thank you. 6 | 7 | Confirmed: 8 | ---------- 9 | Sony Xperia Z1 Compact 10 | Sony Xperia Z1 11 | Sony Xperia Z Ultra 12 | Sony Xperia Z 13 | Sony Xperia ZL 14 | Sony Xperia ZQ 15 | Sony Xperia ZR 16 | Sony Xperia ION 17 | Sony Xperia S 18 | Sony Xperia SL 19 | Sony Xperia SP 20 | Sony Xperia Acro S 21 | Sony Xperia T 22 | Sony Xperia TL 23 | Sony Xperia TX 24 | Sony Xperia M 25 | Sony Xperia V 26 | Sony Xperia P 27 | Sony Xperia L 28 | Sony Xperia U 29 | Sony Xperia Go 30 | Sony Xperia Sola 31 | Sony Xperia Miro 32 | Sony Xperia Tipo 33 | Sony Xperia J 34 | Sony Xperia E 35 | Sony Xperia Tablet Z 36 | 37 | Most likely: 38 | ----------------------- 39 | All Sony Xperia models 40 | 41 | Not compatible: 42 | -------------- 43 | All Sony Ericsson Xperia models 44 | -------------------------------------------------------------------------------- /scripts/adb.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | :wakeDevice 5 | set /p "=Waiting for USB Debugging..." < nul 6 | tools\adb.exe wait-for-device > nul 7 | echo OK 8 | goto:eof -------------------------------------------------------------------------------- /scripts/backup.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | REM ##################### 5 | REM ## BACKUP 6 | REM ##################### 7 | :inspectPartition 8 | if "!backup_taPartitionName!" == "-1" goto:eof 9 | echo --- %1 --- 10 | set /p "=Searching for Operator Identifier..." < nul 11 | tools\adb.exe shell su -c "%BB% cat /dev/block/%1 | %BB% grep -s -m 1 -c 'OP_ID='">tmpbak\backup_matchOP_ID 12 | set /p backup_matchOP_ID=tmpbak\backup_matchS1_Boot 36 | set /p backup_matchS1_Boot=tmpbak\backup_matchS1_Loader 44 | set /p backup_matchS1_Loader=tmpbak\backup_matchS1_HWConf 52 | set /p backup_matchS1_HWConf= nul 2>&1 83 | call scripts\adb.bat wakeDevice 84 | echo. 85 | echo ======================================= 86 | echo FIND TA PARTITION 87 | echo ======================================= 88 | tools\adb.exe shell su -c "%BB% ls -l %PARTITION_BY_NAME% | %BB% awk '{print \$11}'">tmpbak\backup_defaultTA 89 | set /p backup_defaultTA=tmpbak\backup_defaultTAvalid 91 | set /p backup_defaultTAvalid=tmpbak\backup_potentialPartitions 107 | for /F "tokens=*" %%A in (tmpbak\backup_potentialPartitions) do call:inspectPartition %%A 108 | 109 | if NOT "!backup_taPartitionName!" == "" ( 110 | if NOT "!backup_taPartitionName!" == "-1" ( 111 | echo Partition found^^! 112 | set partition=/dev/block/!backup_taPartitionName! 113 | ) else ( 114 | echo *** More than one partition match the TA partition search criteria. *** 115 | echo *** Therefore it is not possible to determine which one or ones to use. *** 116 | echo *** Contact DevShaft @XDA-forums for support. *** 117 | goto onBackupCancelled 118 | ) 119 | ) else ( 120 | echo *** No compatible TA partition found on your device. *** 121 | goto onBackupCancelled 122 | ) 123 | 124 | ) 125 | 126 | echo. 127 | echo ======================================= 128 | echo BACKUP TA PARTITION 129 | echo ======================================= 130 | tools\adb.exe shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\backup_currentPartitionMD5 131 | tools\adb.exe shell su -c "%BB% dd if=!partition! of=/sdcard/backupTA.img" 132 | 133 | echo. 134 | echo ======================================= 135 | echo INTEGRITY CHECK 136 | echo ======================================= 137 | tools\adb.exe shell su -c "%BB% md5sum /sdcard/backupTA.img | %BB% awk {'print \$1'}">tmpbak\backup_backupMD5 138 | set /p backup_currentPartitionMD5= nul 141 | if NOT "!backup_currentPartitionMD5!" == "!backup_backupMD5!" ( 142 | echo FAILED - Backup does not match TA Partition. Please try again. 143 | goto onBackupFailed 144 | ) else ( 145 | echo OK 146 | ) 147 | 148 | echo. 149 | echo ======================================= 150 | echo PULL BACKUP FROM SDCARD 151 | echo ======================================= 152 | tools\adb.exe pull /sdcard/backupTA.img tmpbak\TA.img 153 | if NOT "!errorlevel!" == "0" goto onBackupFailed 154 | 155 | echo. 156 | echo ======================================= 157 | echo INTEGRITY CHECK 158 | echo ======================================= 159 | tools\md5.exe -l -n tmpbak\TA.img>tmpbak\backup_backupPulledMD5 160 | if NOT "!errorlevel!" == "0" goto onBackupFailed 161 | set /p backup_backupPulledMD5= nul 163 | if NOT "!backup_currentPartitionMD5!" == "!backup_backupPulledMD5!" ( 164 | echo FAILED - Backup has gone corrupted while pulling. Please try again. 165 | goto onBackupFailed 166 | ) else ( 167 | echo OK 168 | ) 169 | 170 | echo. 171 | echo ======================================= 172 | echo PACKAGE BACKUP 173 | echo ======================================= 174 | tools\adb.exe get-serialno>tmpbak\TA.serial 175 | echo !partition!>tmpbak\TA.blk 176 | echo !backup_backupPulledMD5!>tmpbak\TA.md5 177 | echo %VERSION%>tmpbak\TA.version 178 | tools\adb.exe shell su -c "%BB% date +%%Y%%m%%d.%%H%%M%%S">tmpbak\TA.timestamp 179 | set /p backup_timestamp= nul 2>&1 235 | if "%~1" == "1" del /q /s tmpbak\TA.* > nul 2>&1 236 | tools\adb.exe shell rm /sdcard/backupTA.img > nul 2>&1 237 | goto:eof -------------------------------------------------------------------------------- /scripts/busybox.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | REM ##################### 5 | REM ## PUSH BUSYBOX 6 | REM ##################### 7 | :pushBusyBox 8 | set /p "=Pushing Backup TA Tools..." < nul 9 | tools\adb.exe push tools\busybox /data/local/tmp/busybox-backup-ta > nul 2>&1 10 | tools\adb.exe shell chmod 755 /data/local/tmp/busybox-backup-ta > nul 2>&1 11 | set BB=/data/local/tmp/busybox-backup-ta 12 | echo OK 13 | goto:eof 14 | 15 | REM ##################### 16 | REM ## REMOVE BUSYBOX 17 | REM ##################### 18 | :removeBusyBox 19 | set /p "=Removing Backup TA Tools..." < nul 20 | tools\adb.exe shell rm /data/local/tmp/busybox-backup-ta > nul 2>&1 21 | set bb= 22 | echo OK 23 | goto:eof 24 | 25 | :dispose 26 | call:removeBusyBox 27 | goto:eof -------------------------------------------------------------------------------- /scripts/convert.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | REM ##################### 5 | REM ## CONVERT 6 | REM ##################### 7 | :convertRawTA 8 | echo. 9 | echo ======================================= 10 | echo PROVIDE BACKUP 11 | echo ======================================= 12 | if NOT exist convert-this mkdir convert-this > nul 2>&1 13 | :copyTAFile 14 | echo Copy your 'TA.img' file to the %CD%\convert-this\ folder. 15 | echo. 16 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Are you ready to continue?" 17 | if "!errorlevel!" == "2" goto onConvertCancelled 18 | if NOT exist convert-this\TA.img ( 19 | echo. 20 | echo There is no 'TA.img' file found inside the 'convert-this' folder. 21 | goto copyTAFile 22 | ) 23 | tools\md5.exe -l -n convert-this\TA.img>convert-this\TA.md5 24 | echo. 25 | echo ======================================= 26 | echo PACKAGE BACKUP 27 | echo ======================================= 28 | tools\adb.exe shell su -c "%BB% date +%%Y%%m%%d.%%H%%M%%S">tmpbak\convert_timestamp 29 | set /p convert_timestamp= nul 2>&1 77 | 78 | if exist convert-this ( 79 | del /q /s convert-this\*.* 80 | ) 81 | ) 82 | goto:eof -------------------------------------------------------------------------------- /scripts/license.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | REM ##################### 5 | REM ## LICENSE 6 | REM ##################### 7 | :showLicense 8 | cls 9 | echo. 10 | echo [ ------------------------------------------------------------ ] 11 | echo [ Backup TA v%VERSION% for Sony Xperia MIT License ] 12 | echo [ ------------------------------------------------------------ ] 13 | echo [ Copyright (C) 2013 DevShaft ] 14 | echo [ ] 15 | echo [ Permission is hereby granted, free of charge, ] 16 | echo [ to any person obtaining a copy of this software ] 17 | echo [ and associated documentation files (the "Software"), ] 18 | echo [ to deal in the Software without restriction, ] 19 | echo [ including without limitation the rights to use, ] 20 | echo [ copy, modify, merge, publish, distribute, sublicense, ] 21 | echo [ and/or sell copies of the Software, and to permit ] 22 | echo [ persons to whom the Software is furnished to do so, ] 23 | echo [ subject to the following conditions: ] 24 | echo [ ] 25 | echo [ The above copyright notice and this permission notice ] 26 | echo [ shall be included in all copies or substantial portions ] 27 | echo [ of the Software. ] 28 | echo [ ] 29 | echo [ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY ] 30 | echo [ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ] 31 | echo [ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR ] 32 | echo [ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ] 33 | echo [ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR ] 34 | echo [ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ] 35 | echo [ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ] 36 | echo [ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ] 37 | echo [ ------------------------------------------------------------ ] 38 | echo. 39 | pause 40 | goto:eof 41 | -------------------------------------------------------------------------------- /scripts/menu.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | REM ##################### 5 | REM ## MENU 6 | REM ##################### 7 | :showMenu 8 | set menu_currentIndex=1 9 | set menu_choices=1 10 | cls 11 | echo. 12 | echo [ ------------------------------------------------------------ ] 13 | echo [ Backup TA v%VERSION% for Sony Xperia ] 14 | echo [ ------------------------------------------------------------ ] 15 | echo [ !menu_currentIndex!. Backup ] 16 | 17 | set /a menu_currentIndex+=1 >nul 18 | set menu_choices=!menu_choices!!menu_currentIndex! 19 | 20 | echo [ !menu_currentIndex!. Restore ] 21 | 22 | set /a menu_currentIndex+=1 >nul 23 | set menu_choices=!menu_choices!!menu_currentIndex! 24 | 25 | echo [ !menu_currentIndex!. Restore dry-run ] 26 | 27 | set /a menu_currentIndex+=1 >nul 28 | set menu_choices=!menu_choices!!menu_currentIndex! 29 | 30 | echo [ !menu_currentIndex!. Convert TA.img ] 31 | 32 | set /a menu_currentIndex+=1 >nul 33 | set menu_choices=!menu_choices!!menu_currentIndex! 34 | 35 | echo [ !menu_currentIndex!. Quit ] 36 | echo [ ------------------------------------------------------------ ] 37 | 38 | %CHOICE% /c:!menu_choices! %CHOICE_TEXT_PARAM% "Please make your decision:" 39 | 40 | set menu_decision=!errorlevel! 41 | set menu_currentIndex= 42 | set menu_choices= 43 | 44 | if "!menu_decision!" == "1" ( 45 | echo. 46 | echo ======================================= 47 | echo BACKUP 48 | echo ======================================= 49 | echo When you continue Backup TA will perform a backup of the TA partition. 50 | echo First it will look for the TA partition by its name. When it can not 51 | echo be found this way it will ask you to perform an extensive search. 52 | echo The extensive search will inspect many of the partitions on your device, 53 | echo in the hope to find it and continue with the backup process. 54 | echo. 55 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Are you sure you want to continue?" 56 | if "!errorlevel!" == "2" goto showMenu 57 | call scripts\backup.bat backupTA 58 | set menu_decision=0 59 | ) 60 | if "!menu_decision!" == "2" ( 61 | echo. 62 | echo ======================================= 63 | echo RESTORE 64 | echo ======================================= 65 | echo When you continue Backup TA will perform a restore of a TA partition 66 | echo backup. There will be many integrity checks along the way to make sure 67 | echo a restore will either complete successfully, revert when something goes 68 | echo wrong while restoring or fail before the restore begins because of an 69 | echo invalid backup. There is always a risk when writing to an important 70 | echo partition like TA, but with these safeguards that risk is kept to an 71 | echo absolute minimum. 72 | echo. 73 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Are you sure you want to continue?" 74 | if "!errorlevel!" == "2" goto showMenu 75 | call scripts\restore.bat restoreTA 76 | set menu_decision=0 77 | ) 78 | if "!menu_decision!" == "3" ( 79 | echo. 80 | echo ======================================= 81 | echo RESTORE DRY-RUN 82 | echo ======================================= 83 | echo When you continue Backup TA will perform the restore of a TA partition 84 | echo in 'dry-run' mode. This mode performs the restore just like the regular 85 | echo restore with the exception that it will not do an actual restore of the 86 | echo backup to the device. It will however perform every integrity check, so 87 | echo you can test beforehand if your backup is invalid or corrupted. 88 | echo. 89 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Are you sure you want to continue?" 90 | if "!errorlevel!" == "2" goto showMenu 91 | call scripts\restore.bat restoreTAdry 92 | set menu_decision=0 93 | ) 94 | if "!menu_decision!" == "4" ( 95 | echo. 96 | echo ======================================= 97 | echo CONVERT TA.IMG 98 | echo ======================================= 99 | echo When you continue Backup TA will ask you to copy your TA.img file to a location 100 | echo and then convert this backup to make it compatible with the latest version 101 | echo of Backup TA. 102 | echo. 103 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Are you sure you want to continue?" 104 | if "!errorlevel!" == "2" goto showMenu 105 | call scripts\convert.bat convertRawTA 106 | set menu_decision=0 107 | ) 108 | if "!menu_decision!" == "5" ( 109 | set menu_decision=-1 110 | ) 111 | 112 | if "!menu_decision!" == "0" goto showMenu 113 | goto:eof 114 | 115 | :dispose 116 | set menu_decision= 117 | set menu_currentIndex= 118 | set menu_choices= 119 | goto:eof 120 | -------------------------------------------------------------------------------- /scripts/restore.bat: -------------------------------------------------------------------------------- 1 | set restore_dryRun= 2 | call:%* 3 | goto:eof 4 | 5 | :hardbrickConfirmation 6 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "This restore may hard-brick your device. Are you sure you want to restore the TA Partition?" 7 | goto:eof 8 | 9 | REM ##################### 10 | REM ## RESTORE DRY 11 | REM ##################### 12 | :restoreTAdry 13 | set restore_dryRun=1 14 | call:restoreTA 15 | goto:eof 16 | 17 | REM ##################### 18 | REM ## RESTORE 19 | REM ##################### 20 | :restoreTA 21 | echo. 22 | call scripts\adb.bat wakeDevice 23 | echo. 24 | if "!restore_dryRun!" == "1" ( 25 | echo --- Restore dry run --- 26 | ) 27 | tools\adb.exe get-serialno>tmpbak\restore_serialno 28 | set /p restore_serialno= nul 30 | 31 | echo. 32 | echo ======================================= 33 | echo CHOOSE BACKUP TO RESTORE 34 | echo ======================================= 35 | echo off > tmpbak\restore_list 36 | set restore_restoreIndex=0 37 | for /f "tokens=*" %%D in ('dir/b/o backup\TA-Backup*.zip') do ( 38 | set /a restore_restoreIndex+=1 39 | echo [!restore_restoreIndex!] %%D >> tmpbak\restore_list 40 | ) 41 | echo [Q] Quit >> tmpbak\restore_list 42 | type tmpbak\restore_list 43 | 44 | :restoreChoose 45 | set /p restore_restoreChosen=Please make your decision: 46 | 47 | if "!restore_restoreChosen!" == "q" goto onRestoreCancelled 48 | if "!restore_restoreChosen!" == "Q" goto onRestoreCancelled 49 | 50 | tools\find "[!restore_restoreChosen!]" < tmpbak\restore_list > tmpbak\restore_item 51 | for /f "tokens=2" %%T in (tmpbak\restore_item) do ( 52 | set restore_restoreFile=%%T 53 | ) 54 | if "!restore_restoreFile!" == "" goto restoreChoose 55 | 56 | echo. 57 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Are you sure you want to restore '!restore_restoreFile!'?" 58 | if "!errorlevel!" == "2" goto onRestoreCancelled 59 | 60 | echo. 61 | echo ======================================= 62 | echo EXTRACT BACKUP 63 | echo ======================================= 64 | tools\zip.exe x -y backup\!restore_restoreFile! -otmpbak 65 | if NOT "!errorlevel!" == "0" goto onRestoreFailed 66 | if exist tmpbak\TA.blk ( 67 | set /p partition=tmpbak\restore_defaultTA 70 | set /p restore_defaultTA=tmpbak\restore_defaultTAvalid 72 | set /p restore_defaultTAvalid= nul 86 | call scripts\string-util.bat strlen restore_savedBackupMD5Len restore_savedBackupMD5 87 | set /a restore_savedBackupMD5TrailingSpaces=!restore_savedBackupMD5Len!-32 88 | for /f "tokens=* delims= " %%a in ("!restore_savedBackupMD5!") do set restore_savedBackupMD5=%%a 89 | for /l %%a in (1,1,100) do if "!restore_savedBackupMD5:~-1!"==" " set restore_savedBackupMD5=!restore_savedBackupMD5:~0,-!restore_savedBackupMD5TrailingSpaces! 90 | tools\md5.exe -l -n tmpbak\TA.img>tmpbak\restore_backupMD5 91 | if NOT "!errorlevel!" == "0" goto onRestoreFailed 92 | set /p restore_backupMD5= nul 94 | if NOT "!restore_savedBackupMD5!" == "!restore_backupMD5!" ( 95 | echo FAILED - Backup is corrupted. 96 | goto onRestoreFailed 97 | ) else ( 98 | echo OK 99 | ) 100 | 101 | echo. 102 | echo ======================================= 103 | echo COMPARE TA PARTITION WITH BACKUP 104 | echo ======================================= 105 | tools\adb.exe shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\restore_currentPartitionMD5 106 | set /p restore_currentPartitionMD5= nul 108 | if "!restore_currentPartitionMD5!" == "!restore_savedBackupMD5!" ( 109 | echo TA partition already matches backup, no need to restore. 110 | goto onRestoreCancelled 111 | ) else ( 112 | echo OK 113 | ) 114 | 115 | echo. 116 | echo ======================================= 117 | echo BACKUP CURRENT TA PARTITION 118 | echo ======================================= 119 | tools\adb.exe shell su -c "%BB% dd if=!partition! of=/sdcard/revertTA.img && %BB% sync && %BB% sync && %BB% sync && %BB% sync" 120 | if NOT "!errorlevel!" == "0" goto onRestoreFailed 121 | tools\adb.exe shell su -c "%BB% ls -l /sdcard/revertTA.img | %BB% awk {'print \$5'}">tmpbak\restore_revertTASize 122 | set /p restore_revertTASize= nul 124 | 125 | echo. 126 | echo ======================================= 127 | echo PUSH BACKUP TO SDCARD 128 | echo ======================================= 129 | tools\adb.exe push tmpbak\TA.img sdcard/restoreTA.img 130 | if NOT "!errorlevel!" == "0" goto onRestoreFailed 131 | 132 | echo. 133 | echo ======================================= 134 | echo INTEGRITY CHECK 135 | echo ======================================= 136 | tools\adb.exe shell su -c "%BB% ls -l /sdcard/restoreTA.img | %BB% awk {'print \$5'}">tmpbak\restore_pushedBackupSize 137 | tools\adb.exe shell su -c "%BB% md5sum /sdcard/restoreTA.img | %BB% awk {'print \$1'}">tmpbak\restore_pushedBackupMD5 138 | if NOT "!errorlevel!" == "0" goto onRestoreFailed 139 | set /p restore_pushedBackupSize= nul 142 | if NOT "!restore_savedBackupMD5!" == "!restore_pushedBackupMD5!" ( 143 | echo FAILED - Backup has gone corrupted while pushing. Please try again. 144 | goto onRestoreFailed 145 | ) else ( 146 | if NOT "!restore_revertTASize!" == "!restore_pushedBackupSize!" ( 147 | echo FAILED - Backup and TA partition sizes do not match. 148 | goto onRestoreFailed 149 | ) else ( 150 | echo OK 151 | ) 152 | ) 153 | 154 | echo. 155 | echo ======================================= 156 | echo SERIAL CHECK 157 | echo ======================================= 158 | if NOT exist tmpbak\TA.serial ( 159 | tools\adb.exe shell su -c "%BB% cat /sdcard/restoreTA.img | %BB% grep -m 1 -o !restore_serialno!">tmpbak\restore_backupSerial 160 | if NOT "!errorlevel!" == "0" goto unknownDevice 161 | copy tmpbak\restore_backupSerial tmpbak\TA.serial > nul 2>&1 162 | ) 163 | set /p restore_backupSerial= nul 165 | if NOT "!restore_serialno!" == "!restore_backupSerial!" ( 166 | goto otherDevice 167 | ) 168 | echo OK 169 | goto validDevice 170 | 171 | :otherDevice 172 | echo The backup appears to be from another device. 173 | goto invalidConfirmation 174 | 175 | :unknownDevice 176 | echo It is impossible to determine the origin for this backup. The backup could be from another device. 177 | goto invalidConfirmation 178 | 179 | :invalidConfirmation 180 | call:hardbrickConfirmation 181 | if "!errorlevel!" == "2" goto onRestoreCancelled 182 | goto validDevice 183 | 184 | :validDevice 185 | echo. 186 | echo ======================================= 187 | echo RESTORE BACKUP 188 | echo ======================================= 189 | if NOT "%restore_dryRun%" == "1" ( 190 | tools\adb.exe shell su -c "%BB% dd if=/sdcard/restoreTA.img of=!partition! && %BB% sync && %BB% sync && %BB% sync && %BB% sync" 191 | if NOT "!errorlevel!" == "0" goto onRestoreFailed 192 | ) else ( 193 | echo --- dry run --- 194 | ) 195 | tools\adb.exe shell su -c "rm /sdcard/restoreTA.img" 196 | 197 | echo. 198 | echo ======================================= 199 | echo COMPARE NEW TA PARTITION WITH BACKUP 200 | echo ======================================= 201 | tools\adb.exe shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\restore_restoredMD5 202 | if NOT "%restore_dryRun%" == "1" ( 203 | set /p restore_restoredMD5= nul 205 | ) else ( 206 | set restore_restoredMD5=%restore_pushedBackupMD5% 207 | ) 208 | if "!restore_currentPartitionMD5!" == "!restore_restoredMD5!" ( 209 | echo TA partition appears unchanged, try again. 210 | goto onRestoreFailed 211 | ) else if NOT "!restore_restoredMD5!" == "!restore_savedBackupMD5!" ( 212 | echo TA partition seems corrupted. Trying to revert restore now... 213 | goto onRestoreCorrupt 214 | ) else ( 215 | echo OK 216 | ) 217 | goto onRestoreSuccess 218 | goto:eof 219 | 220 | REM ##################### 221 | REM ## RESTORE SUCCESS 222 | REM ##################### 223 | :onRestoreSuccess 224 | call:exit 1 225 | goto:eof 226 | 227 | REM ##################### 228 | REM ## RESTORE CANCELLED 229 | REM ##################### 230 | :onRestoreCancelled 231 | call:exit 2 232 | goto:eof 233 | 234 | REM ##################### 235 | REM ## RESTORE FAILED 236 | REM ##################### 237 | :onRestoreFailed 238 | call:exit 3 239 | goto:eof 240 | 241 | REM ##################### 242 | REM ## RESTORE CORRUPT 243 | REM ##################### 244 | :onRestoreCorrupt 245 | echo. 246 | echo ======================================= 247 | echo REVERT RESTORE 248 | echo ======================================= 249 | if NOT "%restore_dryRun%" == "1" ( 250 | tools\adb.exe shell su -c "%BB% dd if=/sdcard/revertTA.img of=%partition% && %BB% sync && %BB% sync && %BB% sync && %BB% sync" 251 | ) 252 | 253 | echo. 254 | echo ======================================= 255 | echo REVERT VERIFICATION 256 | echo ======================================= 257 | tools\adb.exe shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\restore_revertedMD5 258 | if NOT "%restore_dryRun%" == "1" ( 259 | set /p restore_revertedMD5= nul 264 | if NOT "!restore_currentPartitionMD5!" == "!restore_revertedMD5!" ( 265 | echo FAILED 266 | goto onRestoreRevertFailed 267 | ) else ( 268 | echo OK 269 | goto onRestoreRevertSuccess 270 | ) 271 | goto:eof 272 | 273 | REM ##################### 274 | REM ## RESTORE REVERT FAILED 275 | REM ##################### 276 | :onRestoreRevertFailed 277 | tools\adb.exe pull /sdcard/revertTA.img tmpbak\revertTA.img 278 | call:exit 4 279 | goto:eof 280 | 281 | REM ##################### 282 | REM ## RESTORE REVERT SUCCESS 283 | REM ##################### 284 | :onRestoreRevertSuccess 285 | call:exit 5 286 | goto:eof 287 | 288 | REM ##################### 289 | REM ## EXIT RESTORE 290 | REM ##################### 291 | :exit 292 | call:dispose %~1 293 | echo. 294 | if "%~1" == "1" ( 295 | echo *** Restore successful. *** 296 | echo *** You must restart the device for the restore to take effect. *** 297 | echo. 298 | %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Do you want to restart the device?" 299 | if "!errorlevel!" == "2" goto:eof 300 | tools\adb.exe reboot 301 | ) 302 | if "%~1" == "2" echo *** Restore cancelled. *** 303 | if "%~1" == "3" echo *** Restore unsuccessful. *** 304 | if "%~1" == "4" ( 305 | echo *** DO NOT SHUTDOWN OR RESTART THE DEVICE!!! *** 306 | echo *** Reverting restore has failed! Contact DevShaft @XDA-forums for guidance. *** 307 | ) 308 | if "%~1" == "5" echo *** Revert successful. Try to restore again. *** 309 | echo. 310 | pause 311 | goto:eof 312 | 313 | REM ##################### 314 | REM ## DISPOSE RESTORE 315 | REM ##################### 316 | :dispose 317 | set restore_dryRun= 318 | set restore_backupMD5= 319 | set restore_savedBackupMD5= 320 | set restore_currentPartitionMD5= 321 | set restore_pushedBackupMD5= 322 | set restore_restoredMD5= 323 | set restore_revertedMD5= 324 | set restore_backupSerial= 325 | set restore_serialno= 326 | set partition= 327 | 328 | if "%~1" == "1" del /q /s tmpbak\restore_*.* > nul 2>&1 329 | if "%~1" == "1" del /q /s tmpbak\TA.* > nul 2>&1 330 | tools\adb.exe shell rm /sdcard/restoreTA.img > nul 2>&1 331 | tools\adb.exe shell rm /sdcard/revertTA.img > nul 2>&1 332 | goto:eof -------------------------------------------------------------------------------- /scripts/root.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | REM ##################### 5 | REM ## ROOT CHECK 6 | REM ##################### 7 | :check 8 | set /p "=Checking for SU binary..." < nul 9 | tools\adb shell %BB% ls /system/bin/su>tmpbak\su 10 | set /p su=tmpbak\su 13 | set /p su=tmpbak\rootPermission 22 | set /p rootPermission= nul 2>&1 31 | del /q /s tmpbak\rootPermission > nul 2>&1 32 | goto:eof -------------------------------------------------------------------------------- /scripts/string-util.bat: -------------------------------------------------------------------------------- 1 | call:%* 2 | goto:eof 3 | 4 | :strlen 5 | ( 6 | set s=!%~2!# 7 | set len=0 8 | for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( 9 | if NOT "!s:~%%P,1!" == "" ( 10 | set /a len+=%%P 11 | set s=!s:~%%P! 12 | ) 13 | ) 14 | 15 | set %~1=!len! 16 | goto:eof 17 | ) -------------------------------------------------------------------------------- /tools/AdbWinApi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/AdbWinApi.dll -------------------------------------------------------------------------------- /tools/AdbWinUsbApi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/AdbWinUsbApi.dll -------------------------------------------------------------------------------- /tools/adb.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/adb.exe -------------------------------------------------------------------------------- /tools/busybox: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/busybox -------------------------------------------------------------------------------- /tools/choice32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/choice32.exe -------------------------------------------------------------------------------- /tools/choice32_alt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/choice32_alt.exe -------------------------------------------------------------------------------- /tools/choice64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/choice64.exe -------------------------------------------------------------------------------- /tools/find.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/find.exe -------------------------------------------------------------------------------- /tools/md5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/md5.exe -------------------------------------------------------------------------------- /tools/zip.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevShaft/Backup-TA/538b38cfadac229b5973928451c7bf53c24d1a1b/tools/zip.exe --------------------------------------------------------------------------------