#!/usr/bin/env python3
"""Extract the PARTIAL IPA to a clean working tree (patch base)."""
import zipfile, os, shutil, sys

IPA = r'E:\ios\vn.gsm.md_3.19.0-PARTIAL.ipa'
OUT = r'E:\ios\work319\patch_src'

if os.path.isdir(OUT):
    shutil.rmtree(OUT)
os.makedirs(OUT)

with zipfile.ZipFile(IPA) as z:
    z.extractall(OUT)

app = os.path.join(OUT, 'Payload', 'Driver.app')
print('extracted to', app)
print('exists:', os.path.isdir(app))
for root, dirs, files in os.walk(app):
    if root.count(os.sep) - app.count(os.sep) <= 1:
        print('  ', os.path.relpath(root, OUT), 'files=%d' % len(files))
