# -*- coding: utf-8 -*-
# Xem TOÀN BỘ request còn lại trong HAR FaceID: api.vsuite.biz + backend + response quan trọng
import json, io, sys, base64
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
HAR = r'E:\ios\vinfast\logbypasssword.har'
d = json.load(open(HAR, encoding='utf-8'))
entries = d['log']['entries']

def hmap(h):
    return {x['name'].lower(): x['value'] for x in h}

print('== TOÀN BỘ TRẢI NGHIỆM (mobile.connected-car + api.vsuite.biz, không phải auth) ==')
for e in entries:
    u = e['request']['url']
    if not any(k in u for k in ['mobile.connected-car', 'vsuite.biz']): continue
    rq, rs = e['request'], e['response']
    path = '/' + u.split('/', 3)[3] if u.count('/') >= 3 else u
    h = hmap(rq['headers'])
    auth = h.get('authorization', '')[:30]
    xh = 'X' if 'x-hash' in h else '-'
    print(f"[{rs['status']}] {rq['method']:4s} {path[:115]}  auth={auth} xhash={xh}")
    # Response body ngắn
    rtxt = rs.get('content', {}).get('text', '')
    if rtxt and rs['status'] == 200:
        try:
            j = json.loads(rtxt)
            s = json.dumps(j, ensure_ascii=False)
            print('        RSP:', s[:220])
        except Exception:
            pass
    elif rtxt:
        print('        RSP:', rtxt[:180])
