Created
May 13, 2014 07:51
-
-
Save gpduck/a1210201f95ae9b6ac2b to your computer and use it in GitHub Desktop.
Unpack an Android adb backup using groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.zip.* | |
String backupFile = "c:\\backup.ab"; | |
String outFile = "c:\\backup.tar"; | |
int skip = 0; | |
System.setProperty("line.separator", (String)(char)10); | |
File f = new File(backupFile); | |
FileInputStream fis = new FileInputStream(f); | |
InputStreamReader sr = new InputStreamReader(fis); | |
BufferedReader br = new BufferedReader(sr); | |
String type = br.readLine(); | |
if(type != "ANDROID BACKUP") { | |
thorw new Exception("File not an android backup"); | |
} | |
skip += type.length() + 1; | |
String version = br.readLine(); | |
skip += version.length() + 1; | |
String compressed = br.readLine(); | |
skip += compressed.length() + 1; | |
String encryption = br.readLine(); | |
if(encryption != "none") { | |
throw new Exception("Can't handle encryption " + encryption); | |
} | |
skip += encryption.length() + 1; | |
br.close() | |
fis = new FileInputStream(f); | |
fis.skip(skip); | |
InflaterInputStream i = new InflaterInputStream(fis); | |
FileOutputStream fos = new FileOutputStream(outFile); | |
try { | |
i.eachByte(1024) { buffer, bytesRead -> | |
if(bytesRead > 0) { | |
fos.write(buffer, 0, bytesRead); | |
} | |
} | |
} finally { | |
fos.close(); | |
i.close(); | |
fis.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment