Skip to content

Instantly share code, notes, and snippets.

@AlD
Created March 27, 2018 21:55
Show Gist options
  • Save AlD/cb443fe4ba152e1de8a42fa72721552b to your computer and use it in GitHub Desktop.
Save AlD/cb443fe4ba152e1de8a42fa72721552b to your computer and use it in GitHub Desktop.
inf = open('backup.ab', 'rb')
out = open('backup.tar', 'wb')
buf = inf.read(512)
while buf != '':
if buf[:8] == 'TWRP\x00\x00\x00\x00':
print "Skipping %r" % buf[:16]
buf = inf.read(512)
continue
out.write(buf)
buf = inf.read(512)
@DyKey13
Copy link

DyKey13 commented Sep 8, 2021

Hi I have run this on a Backup made with ADB through TWRP Backup, but I´m not sure if is running, my lap sounds like it is working a lot ... I can see a new .tar file with almost the same size of my document, but the script keeps running, after a while I close de cmd windows and explore the .tar but there is just 1 file named backup.... the same size of the original.

@AlD
Copy link
Author

AlD commented Sep 14, 2021

@DyKey13 The file is expected to be almost the same size. It should be pretty much exactly 16/(512+16)*100 = 3.03 % smaller.
It may help to look at both the input and the output file with a hex editor to understand what's supposed to happen and check whether that's working.

@zai1208
Copy link

zai1208 commented Sep 21, 2023

backup.tar is completely empty yet 17.6 gb?

@Abrolkirat
Copy link

Abrolkirat commented Feb 17, 2025

For people having problem with python3

use this:


with open('backup.ab', 'rb') as inf:
    # Open the output .tar file for writing in binary mode
    with open('backup.tar', 'wb') as out:
        # Read the first 512 bytes (header)
        buf = inf.read(512)

        # Continue reading the .ab file and write to .tar
        while buf:
            # If we detect the TWRP header, skip this chunk
            if buf[:8] == b'TWRP\x00\x00\x00\x00':
                print("Skipping header: %r" % buf[:16])
                buf = inf.read(512)
                continue

            # Write the remaining data to the output file
            out.write(buf)

            # Read the next 512-byte chunk
            buf = inf.read(512)

print("Conversion from .ab to .tar is complete.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment