|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from argparse import ArgumentParser |
| 4 | +from struct import unpack |
| 5 | +import sys |
| 6 | +import os.path |
| 7 | +from decrypt import decrypt |
| 8 | + |
| 9 | +argparser = ArgumentParser('Unpack ADB file') |
| 10 | +argparser.add_argument('file') |
| 11 | +args = argparser.parse_args() |
| 12 | + |
| 13 | +with open(args.file, "rb") as f: |
| 14 | + data = bytearray(f.read()) |
| 15 | + |
| 16 | +size = len(data) |
| 17 | +magic, h1, h2, h3, h4 = unpack('<IIIII', data[:0x14]) |
| 18 | +if magic != 666: |
| 19 | + raise Exception('invalid db magic', magic) |
| 20 | + |
| 21 | +db_name, _ = os.path.splitext(os.path.basename(args.file)) |
| 22 | +try: |
| 23 | + os.makedirs(db_name) |
| 24 | +except: |
| 25 | + pass |
| 26 | + |
| 27 | +print('header', h1, h2, h3, h4) |
| 28 | + |
| 29 | +data_offset = h2 * 0x28 + 0x14 |
| 30 | +print('data offset: 0x%08x' %(data_offset)) |
| 31 | +for i in range(h3): |
| 32 | + offset = 0x14 + i * 0x28 |
| 33 | + entry = data[offset: offset + 0x28] |
| 34 | + name_end = entry.index(bytes([0]), 4) |
| 35 | + name = str(entry[4: name_end], 'utf-8') |
| 36 | + index, = unpack('<I', entry[0:4]) |
| 37 | + size, = unpack('<I', entry[0x24:]) |
| 38 | + print(repr(name), hex(index), hex(data_offset + index), size) |
| 39 | + |
| 40 | + entry_data = data[data_offset + index: data_offset + index + size] |
| 41 | + with open(os.path.join(db_name, name + '.dec'), 'wb') as fo: |
| 42 | + fo.write(decrypt(entry_data)) |
| 43 | + |
| 44 | + with open(os.path.join(db_name, name), 'wb') as fo: |
| 45 | + fo.write(entry_data) |
| 46 | + |
0 commit comments