#!/usr/bin/env python3
import re, sys
sys.stdout.reconfigure(encoding='utf-8')
raw = open(r'E:\ios\work319\apps.json', 'rb').read()
s = raw.decode('utf-16') if raw[:2] in (b'\xff\xfe', b'\xfe\xff') else raw.decode('utf-8-sig', errors='replace')
lines = s.splitlines()
for i, l in enumerate(lines):
    if '"CFBundleIdentifier": "vn.gsm.md"' in l or '"CFBundleIdentifier": "app.pegasus1331.silver3523"' in l:
        key = None
        for j in range(i, -1, -1):
            m = re.match(r'^    "(.+?)": \{$', lines[j])
            if m:
                key = m.group(1)
                break
        print('KEY', key)
        for j in range(i, min(i + 400, len(lines))):
            t = lines[j]
            if any(k in t for k in ('CFBundleShortVersionString', 'CFBundleVersion', '"Path"', 'ApplicationType', '"Container"')):
                print('  ', t.strip())
            if re.match(r'^    \},?$', lines[j]):
                break
