#!/usr/bin/env python3
import asyncio, sys
sys.stdout.reconfigure(encoding='utf-8')
from pymobiledevice3.lockdown import create_using_usbmux
from pymobiledevice3.services.house_arrest import HouseArrestService

BID = 'vn.gsm.md'
UDID = '00008130-001E084434DB803A'


async def main():
    ld = await create_using_usbmux(serial=UDID)
    async with await HouseArrestService.create(ld, BID, documents_only=False) as afc:
        for root in ('/', '/Library', '/Library/Preferences', '/Library/Caches',
                     '/Documents', '/tmp', '/SystemData'):
            try:
                names = await afc.listdir(root)
            except Exception as e:
                print('==', root, 'ERR', type(e).__name__, e)
                continue
            print('==', root, names)
            for n in names:
                p = (root.rstrip('/') + '/' + n)
                try:
                    st = await afc.stat(p)
                    print('   %-40s %10s %s %s' % (n, st.get('st_size'), st.get('st_ifmt'), st.get('st_mtime')))
                except Exception as e:
                    print('   %-40s stat ERR %s' % (n, e))


asyncio.run(main())
